public void OpenEditorFor(Object2D obj) { if (current) { Destroy(current); } if(obj != null) { var editor = GameObjectUtil.GetResourceInstance(Object2DEditorBasePrefab); if (Object2DEditorMap.Instance.HasTypeFor(obj.GetType())) { editor.AddComponent(Object2DEditorMap.Instance.GetTypeFor(obj.GetType())); } foreach(var initObj in editor.GetInterfacesInChildren<IInitializable<Object2D>>()) { initObj.Initialize(obj); } Debug.Log(MainCanvas.main); Debug.Log(editor); MainCanvas.main.Add(editor.transform); current = editor; } }
GameObject ConstructObject2DInstance(Object2D obj) { var baseObject = GameObjectUtil.GetResourceInstance(Object2DBasePrefab); baseObject.GetOrAddComponent<Object2DComponent>().Initialize(obj); baseObject.transform.position = GetWorldPosition(GetGridPosition(obj.Position)); baseObject.name = string.Format("{0} ({1})", obj.Name, obj.GetType()); var graphicObject = GameObjectUtil.GetResourceInstance(Object2DPrefabsDirectory + obj.PrefabName); graphicObject.transform.SetParent(baseObject.transform); graphicObject.transform.localPosition = Vector3.zero; //if (obj is IHasTrigger) { // var c = baseObject.AddComponent<BoxCollider2D>(); // c.isTrigger = true; //} if (obj is IHasCollider) { graphicObject.AddComponent<BoxCollider2D>(); } if (Object2DBehaviourMap.Instance.HasTypeFor(obj.GetType())) { baseObject.AddComponent(Object2DBehaviourMap.Instance.GetTypeFor(obj.GetType())); } foreach (var i in baseObject.GetInterfacesInChildren<IInitializable<Object2D>>()) { i.Initialize(obj); } return baseObject; }