public override void OnInspectorGUI() { serializedObject.Update(); _propertySettingsPrefabsPath.stringValue = UViewEditorUtils.LayoutPathSelector(_propertySettingsPrefabsPath.stringValue, "Default Prefabs Path"); if (!UViewEditorUtils.ValidateResourcePath(_propertySettingsPrefabsPath.stringValue)) { EditorGUILayout.HelpBox(string.Format("Prefabs should be stored in a '{0}' folder", UViewEditorUtils.kResources), MessageType.Error); } _propertySettingsScriptsPath.stringValue = UViewEditorUtils.LayoutPathSelector(_propertySettingsScriptsPath.stringValue, "Default Scripts Path"); EditorGUILayout.PropertyField(_propertySettingsScriptTemplate); EditorGUILayout.PropertyField(_propertySettingsPrefabTemplate); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Reset to Defaults", GUILayout.Width(120))) { _settings.RestoreDefaults(); } EditorGUILayout.EndHorizontal(); serializedObject.ApplyModifiedProperties(); }
public static void HandleUpdate() { if (!EditorApplication.isCompiling && EditorPrefs.HasKey(UViewEditorUtils.KEY_SCRIPT_PATH)) { MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript>(EditorPrefs.GetString(UViewEditorUtils.KEY_SCRIPT_PATH)); GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(EditorPrefs.GetString(UViewEditorUtils.KEY_PREFAB_PATH)); if (script != null && prefab != null) { prefab.AddComponent(script.GetClass()); ViewController viewController = GameObject.FindObjectOfType <ViewController>(); if (viewController != null) { SerializedObject serializedObject = new SerializedObject(viewController); SerializedProperty propertyViewAssets = serializedObject.FindProperty("_viewAssets"); serializedObject.Update(); int index = propertyViewAssets.arraySize; propertyViewAssets.InsertArrayElementAtIndex(index); SerializedProperty propertyViewAsset = propertyViewAssets.GetArrayElementAtIndex(index); UViewEditorUtils.CreateViewAsset(propertyViewAsset, prefab.GetComponent <AbstractView>()); serializedObject.ApplyModifiedProperties(); } AssetDatabase.Refresh(); } EditorPrefs.DeleteKey(UViewEditorUtils.KEY_SCRIPT_PATH); EditorPrefs.DeleteKey(UViewEditorUtils.KEY_PREFAB_PATH); } }
private void DrawStatsGUI() { ViewController viewController = target as ViewController; if (viewController == null || viewController.currentLocation == null) { return; } UViewEditorUtils.LayoutLabelWithPrefix("Loaded Resources", viewController.loadedResourceCount); EditorGUILayout.Space(); EditorGUILayout.LabelField("Locations", EditorStyles.boldLabel); UViewEditorUtils.LayoutLabelWithPrefix("Current Location", string.Format("{0} ({1})", viewController.currentLocation.GetType(), viewController.currentLocation.state)); UViewEditorUtils.LayoutLabelWithPrefix("Last Location", viewController.lastLocation); UViewEditorUtils.LayoutLabelWithPrefix("Target Location", viewController.targetLocation); EditorGUILayout.Space(); EditorGUILayout.LabelField("Overlays", EditorStyles.boldLabel); int l = viewController.showingOverlays.Length; UViewEditorUtils.LayoutLabelWithPrefix("Overlays Showing", l.ToString()); UViewEditorUtils.LayoutLabelWithPrefix("Target Overlay", viewController.targetOverlay); }
protected void OnEnable() { _tabIndex = 0; _settings = UViewEditorUtils.GetSettings(); EditorApplication.playModeStateChanged += HandlePlayStateChanged; }
public void OnGUI() { bool error = false; EditorGUILayout.Space(); _createViewName = EditorGUILayout.TextField("View Name", _createViewName); EditorGUILayout.Space(); EditorGUILayout.Space(); _prefabPath = UViewEditorUtils.LayoutPathSelector(_prefabPath, "Prefab Path"); if (!UViewEditorUtils.ValidateResourcePath(_prefabPath)) { error = true; EditorGUILayout.HelpBox(string.Format("Prefabs should be stored in a '{0}' folder", UViewEditorUtils.kResources), MessageType.Error); } _scriptPath = UViewEditorUtils.LayoutPathSelector(_scriptPath, "Script Path"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Reset Paths", EditorStyles.miniButton)) { _scriptPath = _settings.scriptsPath; _prefabPath = _settings.prefabsPath; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical(EditorStyles.helpBox); string pathViewName = string.IsNullOrEmpty(_createViewName) ? "{VIEW_NAME}" : _createViewName; EditorGUILayout.LabelField(CreatePath(pathViewName, _prefabPath, "prefab")); EditorGUILayout.LabelField(CreatePath(pathViewName, _scriptPath, "cs")); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical(); GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(_createViewName) || error); if (GUILayout.Button("Create")) { CreateView(_createViewName, _prefabPath, _scriptPath); Close(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); }
private void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused) { SerializedProperty propertyViewAsset = serializedProperty.GetArrayElementAtIndex(index); SerializedProperty propertyViewTypeID = propertyViewAsset.FindPropertyRelative("viewTypeID"); SerializedProperty propertyAssetID = propertyViewAsset.FindPropertyRelative("assetID"); string viewName = UViewEditorUtils.GetViewName(propertyViewTypeID); string assetPath = AssetDatabase.GUIDToAssetPath(propertyAssetID.stringValue); if (UViewEditorUtils.ValidateViewAsset(propertyViewAsset)) { System.Type viewType = System.Type.GetType(propertyViewTypeID.stringValue); AbstractView sceneInstance = _loadedViews.ContainsKey(viewType) ? _loadedViews[viewType] : null; bool existsInScene = sceneInstance != null; EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, rect.height), existsInScene ? string.Format("{0} (Loaded)", viewName) : viewName, existsInScene ? EditorStyles.boldLabel : EditorStyles.label); if (existsInScene) { if (GUI.Button(new Rect(rect.x + rect.width - 145, rect.y, 90, rect.height - 4), "Apply & Unload", EditorStyles.miniButton)) { UnityEngine.Object prefabParent = PrefabUtility.GetCorrespondingObjectFromSource(sceneInstance.gameObject); GameObject gameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(sceneInstance.gameObject); PrefabUtility.ReplacePrefab(gameObject, prefabParent, ReplacePrefabOptions.ConnectToPrefab); GameObject.DestroyImmediate(sceneInstance.gameObject); } else if (GUI.Button(new Rect(rect.x + rect.width - 55, rect.y, 55, rect.height - 4), "Unload", EditorStyles.miniButton)) { GameObject.DestroyImmediate(sceneInstance.gameObject); } } else if (!existsInScene && GUI.Button(new Rect(rect.x + rect.width - 55, rect.y, 55, rect.height - 4), "Load", EditorStyles.miniButton)) { AbstractView viewAsset = AssetDatabase.LoadAssetAtPath <AbstractView>(assetPath); if (viewAsset != null) { AbstractView instance = PrefabUtility.InstantiatePrefab(viewAsset) as AbstractView; instance.SetParent(_propertyViewParent.objectReferenceValue as Transform, ViewDisplayMode.Overlay); Selection.activeGameObject = instance.gameObject; } else { Debug.LogErrorFormat("Unable to load {0} ({1}), missing an AbstractView component", viewName, assetPath); } } } else { EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, rect.height), string.Format("{0} (Asset Missing)", viewName), EditorStyles.boldLabel); requiresRebuild = true; } }
public static void CreateViewAsset(SerializedProperty property, AbstractView view) { string assetPath = AssetDatabase.GetAssetPath(view); SerializedProperty propertyViewTypeID = property.FindPropertyRelative("viewTypeID"); SerializedProperty propertyResourcePath = property.FindPropertyRelative("resourcePath"); SerializedProperty propertyAssetID = property.FindPropertyRelative("assetID"); propertyViewTypeID.stringValue = view.GetType().AssemblyQualifiedName; propertyResourcePath.stringValue = UViewEditorUtils.GetResourcePath(assetPath); propertyAssetID.stringValue = AssetDatabase.AssetPathToGUID(assetPath); }
private void OnRemoveCallback(ReorderableList list) { int response = EditorUtility.DisplayDialogComplex("Remove View", "Do you also want to cleanup the assets associated with this view? (Script & Prefab)", "Remove View", "Cancel", "Remove View & Assets"); if (response != 1) { if (response == 2) { UViewEditorUtils.RemoveViewAssets(serializedProperty.GetArrayElementAtIndex(list.index)); } serializedProperty.DeleteArrayElementAtIndex(list.index); } }
protected void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical(); EditorGUILayout.Space(); EditorGUILayout.Space(); _tabIndex = GUILayout.Toolbar(_tabIndex, UViewEditorUtils.kTabs, GUILayout.ExpandWidth(true), GUILayout.Height(30)); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); _scroll = EditorGUILayout.BeginScrollView(_scroll); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical(); if (_tabIndex == 0) { ViewController[] controllers = GameObject.FindObjectsOfType <ViewController>(); if (controllers.Length > 0) { ViewController controller = null; if (controllers.Length == 1) { controller = controllers[0]; EditorGUILayout.ObjectField("View Controller", controller, typeof(ViewController), true); } else { string[] names = new string[controllers.Length]; int i = 0, l = names.Length; for (; i < l; ++i) { names[i] = controllers[i].gameObject.name; } int index = System.Array.IndexOf <ViewController>(controllers, _viewController); if (index < 0) { index = 0; } index = EditorGUILayout.Popup("View Controller", index, names); controller = index >= 0 && index < controllers.Length ? controllers[index] : null; } if (controller != _viewController) { if (_viewControllerEditor != null) { DestroyImmediate(_viewControllerEditor); } _viewControllerEditor = UnityEditor.Editor.CreateEditor(controller); _viewController = controller; } if (_viewControllerEditor != null) { _viewControllerEditor.OnInspectorGUI(); } } else { if (_viewControllerEditor != null) { DestroyImmediate(_viewControllerEditor); _viewController = null; _viewControllerEditor = null; } GUIStyle centeredTextStyle = new GUIStyle("label"); centeredTextStyle.alignment = TextAnchor.MiddleCenter; string sceneName = SceneManager.GetActiveScene().name; string message = string.Format("No ViewController found in scene '{0}'", sceneName); EditorGUILayout.BeginVertical(); GUILayout.FlexibleSpace(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.LabelField(message, centeredTextStyle, GUILayout.Width(400)); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Create ViewController", GUILayout.Width(180), GUILayout.Height(30))) { UViewEditorUtils.ContextCreateViewController(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.EndVertical(); } } else { if (_settingsEditor == null) { _settingsEditor = UnityEditor.Editor.CreateEditor(_settings); } _settingsEditor.OnInspectorGUI(); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); }
private void OnEnable() { _settings = UViewEditorUtils.GetSettings(); _scriptPath = _settings.scriptsPath; _prefabPath = _settings.prefabsPath; }
private void OnAddCallback(ReorderableList list) { UViewEditorUtils.ContextCreateView(); }
private void DrawViewGUI() { EditorGUILayout.LabelField("Configuration", EditorStyles.boldLabel); EditorGUILayout.PropertyField(_propertyAutoSetup); EditorGUILayout.PropertyField(_propertyDontDestroyOnLoad); EditorGUILayout.PropertyField(_propertyDebug); EditorGUILayout.PropertyField(_propertyViewParent); string[] viewNames = UViewEditorUtils.GetViewNames(_propertyViewAssets, false); string[] viewNamesShort = UViewEditorUtils.GetViewNames(_propertyViewAssets, true); int startLocationIndex = System.Array.IndexOf <string>(viewNames, _propertyStartingLocation.stringValue); startLocationIndex = EditorGUILayout.Popup("Start Location", startLocationIndex, viewNamesShort); _propertyStartingLocation.stringValue = startLocationIndex == -1 ? "" : viewNames[startLocationIndex]; EditorGUILayout.Space(); EditorGUILayout.Space(); bool locked = EditorApplication.isCompiling && EditorPrefs.HasKey(UViewEditorUtils.KEY_SCRIPT_PATH); EditorGUI.BeginDisabledGroup(locked); _viewList.requiresRebuild = false; _viewList.UpdateLoadedViews(); _viewList.DoLayoutList(); if (_viewList.requiresRebuild && !_attemptedRebuild) { Debug.LogWarning("Views missing or changed, rebuilding..."); UViewEditorUtils.Rebuild(_propertyViewAssets); _viewList.requiresRebuild = false; _attemptedRebuild = true; } EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(5); EditorGUILayout.LabelField("Add Existing", GUILayout.Width(80)); GameObject viewGameObject = EditorGUILayout.ObjectField(null, typeof(GameObject), false) as GameObject; if (viewGameObject != null) { AbstractView view = viewGameObject.GetComponent <AbstractView>(); if (view != null) { // TODO: check this view isn't already in the list _showInvalidWarning = false; int index = _propertyViewAssets.arraySize; _propertyViewAssets.InsertArrayElementAtIndex(index); UViewEditorUtils.CreateViewAsset(_propertyViewAssets.GetArrayElementAtIndex(index), view as AbstractView); } else { _showInvalidWarning = true; } } if (GUILayout.Button("Create New", GUILayout.Width(100))) { UViewEditorUtils.ContextCreateView(); } GUILayout.Space(5); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(5); if (GUILayout.Button("Rebuild List", GUILayout.Width(110))) { _attemptedRebuild = false; UViewEditorUtils.Rebuild(_propertyViewAssets); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUI.EndDisabledGroup(); if (_showInvalidWarning) { EditorGUILayout.HelpBox("Asset must have an AbstractView component attached", MessageType.Warning); } EditorGUILayout.Space(); if (locked) { EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.HelpBox("Creating View...", MessageType.Info); } }