Last active
March 4, 2025 17:13
-
-
Save LotteMakesStuff/cb63e4e25e5dfdda19a95380e9c03436 to your computer and use it in GitHub Desktop.
Revisions
-
GenericEvilBusiness revised this gist
Jan 22, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
LotteMakesStuff revised this gist
Jan 22, 2017 . 1 changed file with 11 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,14 +18,17 @@ static void CreateInsptorEditorClass() [MenuItem("Assets/Create/Custom Inspector", priority = 81, validate = true)] static bool ValidateCreateInsptorEditorClass() { foreach (var script in Selection.objects) { string path = AssetDatabase.GetAssetPath(script); if (script.GetType() != typeof(MonoScript)) return false; if (!path.EndsWith(".cs")) return false; if (path.Contains("Editor")) return false; } return true; } -
LotteMakesStuff revised this gist
Jan 22, 2017 . 1 changed file with 81 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,17 @@ using UnityEngine; using UnityEditor; using System.IO; public static class CustomInspectorCreator { [MenuItem("Assets/Create/Custom Inspector", priority = 81)] static void CreateInsptorEditorClass() { foreach (var script in Selection.objects) { BuildEditorFile(script); } AssetDatabase.Refresh(); } @@ -39,7 +30,50 @@ static bool ValidateCreateInsptorEditorClass() return true; } static void BuildEditorFile(Object obj) { MonoScript monoScript = obj as MonoScript; if (monoScript == null) { Debug.Log("ERROR: Cannot generate a custom inspector, Selected script was not a MonoBehavior"); return; } string assetPath = AssetDatabase.GetAssetPath(obj); var filename = Path.GetFileNameWithoutExtension(assetPath); string script = ""; string scriptNamespace = monoScript.GetClass().Namespace; if (scriptNamespace == null) { // No namespace, use the default template script = string.Format(template, filename); } else { script = string.Format(namespaceTemplate, filename, scriptNamespace); } // make sure a editor folder exists for us to put this script into... var editorFolder = Path.GetDirectoryName(assetPath) + "/Editor"; if (!Directory.Exists(editorFolder)) { Directory.CreateDirectory(editorFolder); } if (File.Exists(editorFolder + "/" + filename + "Inspector.cs")) { Debug.Log("ERROR: " +filename + "Inspector.cs already exists."); return; } // finally write out the new editor~ File.WriteAllText(editorFolder + "/" + filename + "Inspector.cs", script); } #region Templates static readonly string template = @"using UnityEngine; using UnityEditor; using System.Collections; using System.Collections.Generic; @@ -68,4 +102,38 @@ public override void OnInspectorGUI() }} }} "; static readonly string namespaceTemplate = @"using UnityEngine; using UnityEditor; using System.Collections; using System.Collections.Generic; namespace {1} {{ [CustomEditor(typeof({0}))] //[CanEditMultipleObjects] public class {0}Inspector : Editor {{ void OnEnable() {{ // TODO: find properties we want to work with //serializedObject.FindProperty(); }} public override void OnInspectorGUI() {{ // Update the serializedProperty - always do this in the beginning of OnInspectorGUI. serializedObject.Update(); // TODO: Draw UI here //EditorGUILayout.PropertyField(); DrawDefaultInspector(); // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI. serializedObject.ApplyModifiedProperties(); }} }} }} "; #endregion } -
LotteMakesStuff revised this gist
Jan 15, 2017 . No changes.There are no files selected for viewing
-
LotteMakesStuff created this gist
Jan 15, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ using UnityEngine; using UnityEditor; using System.IO; using System.Collections; public static class CustomInspectorCreator { [MenuItem("Assets/Create/Custom Inspector", priority = 81)] static void CreateInsptorEditorClass() { Object obj = Selection.objects[0]; string assetPath = AssetDatabase.GetAssetPath(obj); var filename = Path.GetFileNameWithoutExtension(assetPath); var script = string.Format(template, filename); var editorFolder = Path.GetDirectoryName(assetPath) + "/Editor"; if (!Directory.Exists(editorFolder)) { Directory.CreateDirectory(editorFolder); } File.WriteAllText(editorFolder + "/" + filename + "Inspector.cs", script); AssetDatabase.Refresh(); } [MenuItem("Assets/Create/Custom Inspector", priority = 81, validate = true)] static bool ValidateCreateInsptorEditorClass() { Object obj = Selection.objects[0]; string path = AssetDatabase.GetAssetPath(obj); if (!path.EndsWith(".cs")) return false; if (path.Contains("Editor")) return false; return true; } static string template = @"using UnityEngine; using UnityEditor; using System.Collections; using System.Collections.Generic; [CustomEditor(typeof({0}))] //[CanEditMultipleObjects] public class {0}Inspector : Editor {{ void OnEnable() {{ // TODO: find properties we want to work with //serializedObject.FindProperty(); }} public override void OnInspectorGUI() {{ // Update the serializedProperty - always do this in the beginning of OnInspectorGUI. serializedObject.Update(); // TODO: Draw UI here //EditorGUILayout.PropertyField(); DrawDefaultInspector(); // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI. serializedObject.ApplyModifiedProperties(); }} }} "; }