public GameObject(string name, params Type[] components) { this.name = name; m_Transform = AddComponent <Transform>(); SceneManager.AddGameObject(this); foreach (Type component in components) { AddComponent(component); } }
// public int GetInstanceID() // { // return this.m_InstanceID; // } // public override bool Equals(object o) // { // return Object.CompareBaseObjects(this, o as Object); // } // private static bool CompareBaseObjects(Object lhs, Object rhs) // { // return lhs == rhs; // if (lhs == null && rhs == null) // return true; // if (lhs != null && rhs != null) // return lhs.m_InstanceID == rhs.m_InstanceID; // // return false; // } // public static T DeepClone<T>(T obj) // { // using (var ms = new MemoryStream()) // { // var formatter = new BinaryFormatter(); // formatter.Serialize(ms, obj); // ms.Position = 0; // // return (T) formatter.Deserialize(ms); // } // } public static Object Instantiate(Object original) { Object.CheckNullArgument((object)original, "The Object you want to instantiate is null."); var gameObject = original as GameObject; if (gameObject != null) { SceneManager.dontAddGameObject = true; } var serializer = UnikonEngine.serializationContext.GetSerializer(original.GetType()); MessagePackObject mpo = serializer.ToMessagePackObject(original); var clone = serializer.FromMessagePackObject(mpo); if (gameObject != null) { #if DEBUG_UNIKON Debug.Log("GameObject Instantiate"); Debug.Log(mpo.ToString()); foreach (var component in (clone as GameObject).components) { Debug.Log(component.GetType().Name); } #endif SceneManager.dontAddGameObject = false; SceneManager.AddGameObject(clone as GameObject); // gameObject.dontAwake = false; // foreach (var component in gameObject.components) // { // var awakeMethod = component.GetType().GetMethod("Awake", // BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); // if (awakeMethod != null) // { // Debug.Log("Invoke Awake " + component.GetType()); // awakeMethod.Invoke(component, BindingFlags.InvokeMethod, null, null, CultureInfo.CurrentCulture); // } // // } } return((Object)clone); }
public GameObject(string name) { this.name = name; m_Transform = AddComponent <Transform>(); SceneManager.AddGameObject(this); }
public GameObject() { m_Transform = AddComponent <Transform>(); SceneManager.AddGameObject(this); }