problème : au moment de load une save, les tiles qui spawnaient des GameObjects au start les spawnaient malgré qu'ils l'avait déjà spawné dans la dernière session de jeu + problèmes de sérialisation divers solution : spawner le GameObject seulement si le lifetime de la tile est de zéro. correction des différents problèmes de sérialisation. note : les tiles ne semblent vraiment pas être faites pour avoir une update loop. mais bon, maintenant ça marche.
58 lines
1.9 KiB
C#
58 lines
1.9 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 (!prefab)
|
|
{
|
|
Debug.Log("");
|
|
}
|
|
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);
|
|
}
|
|
} |