/// <summary> /// 数据绑定到Gameobject /// </summary> /// <param name="go"></param> /// <returns></returns> public ReferenceObject BindInstance(GameObject go) { ReferenceObject component = ReferenceRoot.AddReference(AssemblyTool.FindTypesInCurrentDomainByName(RefType), go, null); this.state = SceneObjectState.binding; component.Data = this; return(component); }
public static void CreateRefObject <T>() where T : ReferenceObject { var go = new GameObject("ReferenceObject"); ReferenceRoot.AddReference <T>(go, null); if (Selection.activeGameObject) { go.transform.SetParent(Selection.activeGameObject.transform); } Selection.activeGameObject = go; }
private void OnEnable() { if (!_Instance) { _Instance = this; CollectRefrence(); } #if UNITY_EDITOR if (!Application.isPlaying) { EditorApplication.hierarchyChanged += hierarchyChanged; } #endif }
Rect ObjectField(SerializedProperty property, SceneReference instance, Rect postion, bool showDetail, string label = null) { OnGUIUtility.Layout.IndentDisable(); postion = postion.Delta(new Vector2(2, 0)); Rect r4 = Rect.zero; if (showDetail) { r4 = OnGUIUtility.Layout.Divide.Divide2Horizontal(postion, out postion, postion.width - 16); } EditorGUI.BeginChangeCheck(); if (!ReferenceRoot.Instance) { if (label.IsNOTNullOrEmpty()) { instance.RefObj = EditorGUI.ObjectField(postion, label, instance.RefObj, typeof(ReferenceObject), true) as ReferenceObject; } else { instance.RefObj = EditorGUI.ObjectField(postion, instance.RefObj, typeof(ReferenceObject), true) as ReferenceObject; } } else { EditorGUI.BeginChangeCheck(); UnityEngine.Object obj = null; if (label.IsNOTNullOrEmpty()) { obj = EditorGUI.ObjectField(postion, label, instance.RefObj, typeof(UnityEngine.Object), true); } else { obj = EditorGUI.ObjectField(postion, instance.RefObj, typeof(UnityEngine.Object), true); } if (EditorGUI.EndChangeCheck()) { if (obj) { if (obj is ReferenceObject) { instance.RefObj = obj as ReferenceObject; } else if (obj is GameObject) { instance.RefObj = ReferenceRoot.AddReference(obj as GameObject, instance); } } else { instance.RefObj = null; } } } if (EditorGUI.EndChangeCheck()) { if (instance.RefObj) { instance.RefObj.TryInit(); instance.Identity = instance.RefObj.Data.GUID; EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } else { if (!string.IsNullOrEmpty(instance.Identity)) { instance.Identity = string.Empty; instance.Type = string.Empty; instance.RefObj = null; } } } if (GUI.Button(r4, "", new GUIStyle("WinBtnRestore"))) { ObjectPopupWindow.Show(instance, new Vector2(300, 300), "ScenReference", () => { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); PrefabUtility.RecordPrefabInstancePropertyModifications(property.serializedObject.targetObject); }); } OnGUIUtility.Layout.IndentEnable(); return(postion); }