void OnDestroy() { _window = null; }
public static void Open(GameObject parent, GameObject target, Action <GameObject> changeAction) { _window = GetWindow <PrefabTreeViewWindow>(true); _window.Build(parent, target, changeAction); }
public static void DrawPrefab(TemplateSettingStatus status) { EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle()); { var prefabProperty = status.GetProperty(TemplateSettingStatus.Property.DuplicatePrefab); var targetProperty = status.GetProperty(TemplateSettingStatus.Property.AttachTarget); var oldObj = prefabProperty.objectReferenceValue as GameObject; EditorGUILayout.PropertyField(prefabProperty, new GUIContent("Attach Prefab"), true); var obj = prefabProperty.objectReferenceValue as GameObject; if (obj == null || PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab) { targetProperty.objectReferenceValue = null; EditorGUILayout.EndVertical(); return; } if (oldObj != obj) { targetProperty.objectReferenceValue = prefabProperty.objectReferenceValue = PrefabUtility.FindRootGameObjectWithSameParentPrefab(obj); } EditorGUILayout.BeginHorizontal(EditorGUIHelper.GetScopeStyle()); { if (GUILayout.Button("Change Attach Target")) { PrefabTreeViewWindow.Open(obj, targetProperty.objectReferenceValue as GameObject, (targetObj) => { status.TargetSerializedObject.Update(); status.GetProperty(TemplateSettingStatus.Property.AttachTarget).objectReferenceValue = targetObj; status.TargetSerializedObject.ApplyModifiedProperties(); }); } EditorGUILayout.LabelField(targetProperty.objectReferenceValue == null ? string.Empty : targetProperty.objectReferenceValue.name); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle()); { var pathProperty = status.GetProperty(TemplateSettingStatus.Property.PrefabPath); EditorGUILayout.PropertyField(pathProperty, new GUIContent("Create Prefab Path"), true); var paths = EditorGUIHelper.DrawDragAndDropArea(); if (paths != null && paths.Length > 0) { pathProperty.stringValue = paths[0]; } if (string.IsNullOrEmpty(pathProperty.stringValue)) { EditorGUILayout.HelpBox("If empty, the script will be created in active folder", MessageType.Info); } EditorGUILayout.HelpBox("Example: Assets/Folder", MessageType.Info); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle()); { var nameProperty = status.GetProperty(TemplateSettingStatus.Property.PrefabName); EditorGUILayout.PropertyField(nameProperty, new GUIContent("Prefab Name"), true); if (string.IsNullOrEmpty(nameProperty.stringValue)) { EditorGUILayout.HelpBox("Example: ExamplePrefab", MessageType.Info); } } EditorGUILayout.EndVertical(); } EditorGUILayout.EndVertical(); }