MapBehaviourInspector.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using UnityEditor;
  2. using UnityEngine;
  3. using XGame.Framework.Map;
  4. namespace XGame.Editor.Map
  5. {
  6. [CustomEditor(typeof(MapBehaviour))]
  7. public class MapBehaviourInspector : UnityEditor.Editor
  8. {
  9. //private SerializedProperty m_Script;
  10. private MapBehaviour _behaviour;
  11. private string _componentName;
  12. private void OnEnable()
  13. {
  14. //m_Script = serializedObject.FindProperty("m_Script");
  15. _behaviour = serializedObject.targetObject as MapBehaviour;
  16. }
  17. private void OnDisable()
  18. {
  19. _behaviour = null;
  20. //m_Script = null;
  21. }
  22. public override void OnInspectorGUI()
  23. {
  24. base.OnInspectorGUI();
  25. serializedObject.Update();
  26. //展示区域,禁止操作
  27. //EditorGUI.BeginDisabledGroup(true);
  28. //EditorGUILayout.PropertyField(m_Script);
  29. //EditorGUI.EndDisabledGroup();
  30. // 运行时不显示代码生成相关
  31. if (Application.isPlaying) return;
  32. GUILayout.Space(20);
  33. EditorGUILayout.BeginVertical("Box");
  34. DrawCodeTitle();
  35. DrawGenerateBtn();
  36. EditorGUILayout.EndVertical();
  37. }
  38. private void DrawCodeTitle()
  39. {
  40. var titleStyle = new GUIStyle("Label")
  41. {
  42. fontSize = 25,
  43. alignment = TextAnchor.MiddleCenter,
  44. fontStyle = FontStyle.BoldAndItalic
  45. };
  46. GUILayout.Box("以下为代码生成区域", titleStyle);
  47. GUILayout.Space(10);
  48. _componentName = EditorGUILayout.TextField("请输入Component名字:", _componentName);
  49. GUILayout.Space(10);
  50. }
  51. private void DrawGenerateBtn()
  52. {
  53. GUILayout.FlexibleSpace();
  54. GUILayout.BeginVertical();
  55. GUIStyle style = new GUIStyle("Button")
  56. {
  57. alignment = TextAnchor.MiddleCenter,
  58. fontStyle = FontStyle.BoldAndItalic,
  59. fontSize = 15,
  60. };
  61. GUI.color = Color.green;
  62. if (GUILayout.Button("Generator", style, GUILayout.Height(40)))
  63. {
  64. (new MapViewCodeGen()).Gen(_behaviour, _componentName);
  65. }
  66. GUI.color = Color.white;
  67. GUILayout.EndVertical();
  68. }
  69. }
  70. }