|
| 1 | +using Analysis.GraphicsTuner.Module; |
| 2 | +using UnityEditor; |
| 3 | +using UnityEngine; |
| 4 | +using UnityEngine.UI; |
| 5 | + |
| 6 | +namespace Analysis.GraphicsTuner { |
| 7 | + [CustomEditor(typeof(GraphicsTuner))] |
| 8 | + public class GraphicsTunerInspector : Editor { |
| 9 | + |
| 10 | + private const int PADDING = 30; |
| 11 | + private const int TOGGLE_WIDTH = 100; |
| 12 | + |
| 13 | + public override void OnInspectorGUI() { |
| 14 | + this.DrawSwitchAnchor(); |
| 15 | + this.DrawModuleSetting(); |
| 16 | + } |
| 17 | + |
| 18 | + private void DrawSwitchAnchor() { |
| 19 | + var switchBtn = (Button)serializedObject.FindProperty("switchBtn").objectReferenceValue; |
| 20 | + var rect = switchBtn.GetComponent<RectTransform>(); |
| 21 | + |
| 22 | + EditorGUILayout.BeginVertical(EditorStyles.helpBox); |
| 23 | + EditorGUILayout.LabelField("Anchor", EditorStyles.toolbarButton); |
| 24 | + EditorGUILayout.Space(); |
| 25 | + |
| 26 | + EditorGUILayout.BeginHorizontal(); |
| 27 | + GUILayout.FlexibleSpace(); |
| 28 | + // Top Left |
| 29 | + if (GUILayout.Toggle(rect.anchorMin == Vector2.up && rect.anchorMax == Vector2.up, "Top-Left", EditorStyles.toolbarButton, GUILayout.Width(TOGGLE_WIDTH))) { |
| 30 | + rect.anchorMin = Vector2.up; |
| 31 | + rect.anchorMax = Vector2.up; |
| 32 | + rect.anchoredPosition = new Vector3(PADDING, -PADDING); |
| 33 | + } |
| 34 | + // Top Right |
| 35 | + if (GUILayout.Toggle(rect.anchorMin == Vector2.one && rect.anchorMax == Vector2.one, "Top-Right", EditorStyles.toolbarButton, GUILayout.Width(TOGGLE_WIDTH))) { |
| 36 | + rect.anchorMin = Vector2.one; |
| 37 | + rect.anchorMax = Vector2.one; |
| 38 | + rect.anchoredPosition = new Vector3(-PADDING, -PADDING); |
| 39 | + } |
| 40 | + GUILayout.FlexibleSpace(); |
| 41 | + EditorGUILayout.EndHorizontal(); |
| 42 | + |
| 43 | + EditorGUILayout.BeginHorizontal(); |
| 44 | + GUILayout.FlexibleSpace(); |
| 45 | + // Bottom Left |
| 46 | + if (GUILayout.Toggle(rect.anchorMin == Vector2.zero && rect.anchorMax == Vector2.zero, "Bottom-Left", EditorStyles.toolbarButton, GUILayout.Width(TOGGLE_WIDTH))) { |
| 47 | + rect.anchorMin = Vector2.zero; |
| 48 | + rect.anchorMax = Vector2.zero; |
| 49 | + rect.anchoredPosition = new Vector3(PADDING, PADDING); |
| 50 | + } |
| 51 | + // Bottom Right |
| 52 | + if (GUILayout.Toggle(rect.anchorMin == Vector2.right && rect.anchorMax == Vector2.right, "Bottom-Right", EditorStyles.toolbarButton, GUILayout.Width(TOGGLE_WIDTH))) { |
| 53 | + rect.anchorMin = Vector2.right; |
| 54 | + rect.anchorMax = Vector2.right; |
| 55 | + rect.anchoredPosition = new Vector3(-PADDING, PADDING); |
| 56 | + } |
| 57 | + GUILayout.FlexibleSpace(); |
| 58 | + EditorGUILayout.EndHorizontal(); |
| 59 | + |
| 60 | + EditorGUILayout.Space(); |
| 61 | + EditorGUILayout.EndVertical(); |
| 62 | + } |
| 63 | + |
| 64 | + private void DrawModuleSetting() { |
| 65 | + var tuner = (GraphicsTuner)this.target; |
| 66 | + if (tuner.Modules != null) { |
| 67 | + for (int i = 0; i < tuner.Modules.Count; i++) { |
| 68 | + this.DrawModuleSetting(tuner.Modules[i]); |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + private void DrawModuleSetting(SettingModule module) { |
| 74 | + if (module == null) return; |
| 75 | + |
| 76 | + EditorGUILayout.BeginVertical(EditorStyles.helpBox); |
| 77 | + EditorGUILayout.LabelField(module.name, EditorStyles.toolbarButton); |
| 78 | + EditorGUILayout.Space(); |
| 79 | + |
| 80 | + var active = EditorGUILayout.Toggle("Enable", module.isActive); |
| 81 | + if (active != module.isActive) { |
| 82 | + module.SetActive(active); |
| 83 | + } |
| 84 | + |
| 85 | + var anchor = (ComponentAnchor)EditorGUILayout.EnumPopup("Anchor", module.anchor); |
| 86 | + if (anchor != module.anchor) { |
| 87 | + module.SetAnchor(anchor); |
| 88 | + } |
| 89 | + |
| 90 | + EditorGUILayout.Space(); |
| 91 | + EditorGUILayout.EndVertical(); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments