12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using UnityEditor;
- using UnityEngine;
- using XGame.Framework.Map;
- namespace XGame.Editor.Map
- {
- [CustomEditor(typeof(MapBehaviour))]
- public class MapBehaviourInspector : UnityEditor.Editor
- {
- //private SerializedProperty m_Script;
- private MapBehaviour _behaviour;
- private string _componentName;
- private void OnEnable()
- {
- //m_Script = serializedObject.FindProperty("m_Script");
- _behaviour = serializedObject.targetObject as MapBehaviour;
- }
- private void OnDisable()
- {
- _behaviour = null;
- //m_Script = null;
- }
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- serializedObject.Update();
- //展示区域,禁止操作
- //EditorGUI.BeginDisabledGroup(true);
- //EditorGUILayout.PropertyField(m_Script);
- //EditorGUI.EndDisabledGroup();
- // 运行时不显示代码生成相关
- if (Application.isPlaying) return;
- GUILayout.Space(20);
- EditorGUILayout.BeginVertical("Box");
- DrawCodeTitle();
- DrawGenerateBtn();
- EditorGUILayout.EndVertical();
- }
- private void DrawCodeTitle()
- {
- var titleStyle = new GUIStyle("Label")
- {
- fontSize = 25,
- alignment = TextAnchor.MiddleCenter,
- fontStyle = FontStyle.BoldAndItalic
- };
- GUILayout.Box("以下为代码生成区域", titleStyle);
- GUILayout.Space(10);
- _componentName = EditorGUILayout.TextField("请输入Component名字:", _componentName);
- GUILayout.Space(10);
- }
- private void DrawGenerateBtn()
- {
- GUILayout.FlexibleSpace();
- GUILayout.BeginVertical();
- GUIStyle style = new GUIStyle("Button")
- {
- alignment = TextAnchor.MiddleCenter,
- fontStyle = FontStyle.BoldAndItalic,
- fontSize = 15,
- };
- GUI.color = Color.green;
- if (GUILayout.Button("Generator", style, GUILayout.Height(40)))
- {
- (new MapViewCodeGen()).Gen(_behaviour, _componentName);
- }
- GUI.color = Color.white;
- GUILayout.EndVertical();
- }
- }
- }
|