public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var n = property.FindPropertyRelative("presetName"); // Draw Name var lines = position.SplitByHeights((int)EditorGUIUtility.singleLineHeight); var nameBounds = lines[0].SplitByWidthsRatio(0.5f, 0.5f); var keysProp = property.FindPropertyRelative("keys"); List <string> presetKeys = new List <string>(); for (int i = 0; i < keysProp.arraySize; ++i) { presetKeys.Add(keysProp.GetArrayElementAtIndex(i).stringValue); } using (new ColorScope(Color.green, SwitcherInspector.IsPreset(presetKeys))) { using (new ColorScope(Color.red, n.stringValue.IsEmpty())) { if (GUI.Button(nameBounds[0], new GUIContent(n.stringValue))) { var script = property.serializedObject.targetObject as Switcher; script.SetPreset(n.stringValue); SwitcherInspector.SetActive(presetKeys.ToArray()); } EditorGUI.PropertyField(nameBounds[1], n, new GUIContent("")); } // indentation lines[1].x += 30; lines[1].width -= 30; var drawer = GetKeysDrawer(property); drawer.Draw(lines[1]); } }
protected override void OnGUI(SerializedProperty p, Rect bound) { var uiSwitch = p.serializedObject.targetObject as Switcher; // Draw Name var bounds = bound.SplitByHeights(lineHeight); var n = p.FindPropertyRelative("name"); var active = SwitcherInspector.IsActive(n.stringValue); var nameBounds = bounds[0].SplitByWidthsRatio(0.5f, 0.25f, 0.25f); var boundsLeft = bounds[1]; // indentation boundsLeft.x += 30; boundsLeft.width -= 30; Color c = GUI.color; if (active) { c = UpdatePos(p) ? ChangedSelectedColor : SelectedColor; } // Draw Title using (new EnableScope(!n.stringValue.IsEmpty())) { using (new ColorScope(c)) { if (GUI.Button(nameBounds[0], new GUIContent(n.stringValue))) { Undo.RecordObjects(uiSwitch.objs.ToArray(), "switch"); bool hasPreset = !uiSwitch.preset.IsEmpty(); if (!hasPreset) { SwitcherInspector.SetActive(n.stringValue, n.stringValue); } else { SwitcherInspector.Activate(n.stringValue, !SwitcherInspector.IsActive(n.stringValue)); } var script = p.serializedObject.targetObject as Switcher; script.SetKey(n.stringValue); } } } EditorGUI.PropertyField(nameBounds[1], n, new GUIContent("")); if (GUI.Button(nameBounds[2], "Collect")) { uiSwitch.Collect(n.stringValue); EditorUtil.SetDirty(uiSwitch); } // Draw Visibility var visibility = GetVisibilityDrawer(p); var objBounds = boundsLeft.SplitByHeights((int)visibility.GetHeight()); boundsLeft = objBounds[1]; visibility.Draw(objBounds[0]); // Draw Transform if (uiSwitch.showTrans) { var trans = GetTransDrawer(p); var tBound = boundsLeft.SplitByHeights(transHeight); boundsLeft = tBound[1]; using (new ColorScope(c)) { trans.Draw(tBound[0]); } } // Draw Actions if (uiSwitch.showAction) { var actionBounds = boundsLeft.SplitByHeights(actionHeight); boundsLeft = actionBounds[1]; var actionProperty = p.FindPropertyRelative("action"); EditorGUI.PropertyField(actionBounds[0], actionProperty); } // Draw ICompData var dataBounds = boundsLeft.SplitByHeights(dataHeight); boundsLeft = dataBounds[1]; #if UNITY_2019_1_OR_NEWER var dataProperty = p.FindPropertyRelative("data"); EditorGUI.PropertyField(dataBounds[0], dataProperty, true); #endif }