problèmes : - mon code et l'arrangement des fichiers avait besoin d'un peu de tidy up - les tiles qui n'étaient pas des LevelTile ne loadaient pas solution : - rangé un peu + respecté structure une classe - un fichier - tenté un build pour voir si tout roulait comme il faut, ce qui m'a porté à ajouter des directives de preprocessing et à bouger les custom inspectors dans le dossier Editor. - ajouté une représentation simple des tuiles non-LevelTile dans la sauvegarde.
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BindingFlags = System.Reflection.BindingFlags;
|
|
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public static class Extensions
|
|
{
|
|
public static int ToInt(this object jobj)
|
|
{
|
|
return int.Parse(jobj.ToString());
|
|
}
|
|
public static float ToFloat(this object jobj)
|
|
{
|
|
return float.Parse(jobj.ToString());
|
|
}
|
|
public static Vector3 ToVector3(this object jobj)
|
|
{
|
|
var p_enum = (jobj as IEnumerable).GetEnumerator();
|
|
float[] p_array = new float[3];
|
|
|
|
p_enum.MoveNext();
|
|
p_array[0] = float.Parse(p_enum.Current.ToString());
|
|
p_enum.MoveNext();
|
|
p_array[1] = float.Parse(p_enum.Current.ToString());
|
|
p_enum.MoveNext();
|
|
p_array[2] = float.Parse(p_enum.Current.ToString());
|
|
|
|
return new Vector3(p_array[0], p_array[1], p_array[2]);
|
|
}
|
|
public static bool ToBool(this object jobj) => bool.Parse(jobj.ToString());
|
|
public static GameObject Create(this GameObject prefab, Vector3 position, Quaternion rotation = default, Transform parent = null)
|
|
{
|
|
if (rotation == default) rotation = Quaternion.identity;
|
|
var instance = GameObject.Instantiate(prefab, position, rotation);
|
|
instance.transform.SetParent(parent);
|
|
instance.name = prefab.name;
|
|
return instance;
|
|
|
|
}
|
|
public static T GetComponentInChildren<T>(this Component obj, string name) where T : Component
|
|
{
|
|
foreach (var comp in obj.GetComponentsInChildren<T>())
|
|
{
|
|
if (comp.name == name) return comp;
|
|
}
|
|
return null;
|
|
}
|
|
public enum LevelObjectType { GameObject, Tile }
|
|
public static bool Approximately(this Vector3 vect, Vector3 other)
|
|
{
|
|
return Mathf.Approximately(Vector3.Distance(vect, other), 0);
|
|
}
|
|
} |