Guest User

Untitled

a guest
Jan 17th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.IO;
  4. using System.Collections;
  5.  
  6. public static class CustomInspectorCreator
  7. {
  8. [MenuItem("Assets/Create/Custom Inspector", priority = 81)]
  9. static void CreateInsptorEditorClass()
  10. {
  11. Object obj = Selection.objects[0];
  12. string assetPath = AssetDatabase.GetAssetPath(obj);
  13.  
  14. var filename = Path.GetFileNameWithoutExtension(assetPath);
  15. var script = string.Format(template, filename);
  16. var editorFolder = Path.GetDirectoryName(assetPath) + "/Editor";
  17.  
  18. if (!Directory.Exists(editorFolder))
  19. {
  20. Directory.CreateDirectory(editorFolder);
  21. }
  22.  
  23. File.WriteAllText(editorFolder + "/" + filename + "Inspector.cs", script);
  24. AssetDatabase.Refresh();
  25. }
  26.  
  27. [MenuItem("Assets/Create/Custom Inspector", priority = 81, validate = true)]
  28. static bool ValidateCreateInsptorEditorClass()
  29. {
  30. Object obj = Selection.objects[0];
  31. string path = AssetDatabase.GetAssetPath(obj);
  32.  
  33. if (!path.EndsWith(".cs"))
  34. return false;
  35. if (path.Contains("Editor"))
  36. return false;
  37.  
  38.  
  39. return true;
  40. }
  41.  
  42. static string template = @"using UnityEngine;
  43. using UnityEditor;
  44. using System.Collections;
  45. using System.Collections.Generic;
  46.  
  47. [CustomEditor(typeof({0}))]
  48. //[CanEditMultipleObjects]
  49. public class {0}Inspector : Editor
  50. {{
  51. void OnEnable()
  52. {{
  53. // TODO: find properties we want to work with
  54. //serializedObject.FindProperty();
  55. }}
  56.  
  57. public override void OnInspectorGUI()
  58. {{
  59. // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
  60. serializedObject.Update();
  61.  
  62. // TODO: Draw UI here
  63. //EditorGUILayout.PropertyField();
  64. DrawDefaultInspector();
  65.  
  66. // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
  67. serializedObject.ApplyModifiedProperties();
  68. }}
  69. }}
  70. ";
  71. }
Add Comment
Please, Sign In to add comment