private void DrawPageSlider(GUIContent label) { try { if (this.slider == null) { this.slider = new SlidePageNavigationHelper<InspectorProperty>(); this.slider.PushPage(this.Property, Guid.NewGuid().ToString()); this.page = this.slider.EnumeratePages.Last(); this.page.Name = this.GetLabelText(label); } currentSlider = this.slider; SirenixEditorGUI.BeginBox(); SirenixEditorGUI.BeginToolbarBoxHeader(); { var rect = GUILayoutUtility.GetRect(0, 20); rect.x -= 5; this.slider.DrawPageNavigation(rect); } SirenixEditorGUI.EndToolbarBoxHeader(); { this.slider.BeginGroup(); foreach (var p in this.slider.EnumeratePages) { if (p.BeginPage()) { if (p.Value == this.Property) { this.CallNextDrawer(null); } else { currentDrawingPageProperty = p.Value; if (p.Value.Tree != this.Property.Tree) { InspectorUtilities.BeginDrawPropertyTree(p.Value.Tree, true); } p.Value.Draw(null); if (p.Value.Tree != this.Property.Tree) { InspectorUtilities.EndDrawPropertyTree(p.Value.Tree); } currentDrawingPageProperty = null; } } p.EndPage(); } this.slider.EndGroup(); } SirenixEditorGUI.EndBox(); } finally { currentSlider = null; } }
/// <summary> Draws standard field editors for all public fields </summary> public virtual void OnBodyGUI() { #if ODIN_INSPECTOR inNodeEditor = true; #endif // Unity specifically requires this to save/update any serial object. // serializedObject.Update(); must go at the start of an inspector gui, and // serializedObject.ApplyModifiedProperties(); goes at the end. serializedObject.Update(); string[] excludes = { "m_Script", "graph", "position", "ports" }; #if ODIN_INSPECTOR InspectorUtilities.BeginDrawPropertyTree(objectTree, true); GUIHelper.PushLabelWidth(84); objectTree.Draw(true); InspectorUtilities.EndDrawPropertyTree(objectTree); GUIHelper.PopLabelWidth(); #else // Iterate through serialized properties and draw them like the Inspector (But with ports) SerializedProperty iterator = serializedObject.GetIterator(); bool enterChildren = true; while (iterator.NextVisible(enterChildren)) { enterChildren = false; if (excludes.Contains(iterator.name)) { continue; } NodeEditorGUILayout.PropertyField(iterator, true); } #endif // Iterate through dynamic ports and draw them in the order in which they are serialized foreach (XNode.NodePort dynamicPort in target.DynamicPorts) { if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) { continue; } NodeEditorGUILayout.PortField(dynamicPort); } serializedObject.ApplyModifiedProperties(); #if ODIN_INSPECTOR // Call repaint so that the graph window elements respond properly to layout changes coming from Odin if (GUIHelper.RepaintRequested) { GUIHelper.ClearRepaintRequest(); window.Repaint(); } #else window.Repaint(); #endif #if ODIN_INSPECTOR inNodeEditor = false; #endif }
protected override void DrawTree() { if (customTree == null) { customTree = PropertyTree.Create(serializedObject); } InspectorUtilities.BeginDrawPropertyTree(customTree, true); InspectorUtilities.DrawPropertiesInTree(customTree); InspectorUtilities.EndDrawPropertyTree(customTree); }
protected override void DrawPropertyLayout(GUIContent label) { var target = Property.ValueEntry.WeakSmartValue as Object; if (target != null) { foldout.Value = EditorGUILayout.Foldout(foldout.Value, new GUIContent(typeof(T).GetNiceName().Replace("Effect", string.Empty))); if (SirenixEditorGUI.BeginFadeGroup(this, foldout.Value)) { InspectorUtilities.BeginDrawPropertyTree(tree, true); InspectorUtilities.DrawPropertiesInTree(tree); InspectorUtilities.EndDrawPropertyTree(tree); } SirenixEditorGUI.EndFadeGroup(); } }
protected override void DrawTree() { EditorGUILayout.BeginHorizontal(); var size = EditorGUIUtility.singleLineHeight; if (GUILayout.Button(type == null ? " None" : $" {GetEffectName(type)}", EditorStyles.popup)) { var rect = GUIHelper.GetCurrentLayoutRect(); var position = new Vector2(rect.x, rect.yMax); var window = dropdown.ShowInPopup(position, rect.width - size - 3f); window.OnClose += dropdown.SelectionTree.Selection.ConfirmSelection; } if (GUILayout.Button(EditorIcons.Plus.ActiveGUIContent, SirenixGUIStyles.IconButton, GUILayout.Width(size), GUILayout.Height(size))) { if (type == null) { return; } var component = target as Component; var addedComponent = component.gameObject.AddComponent(type); addedComponent.hideFlags = HideFlags.HideInInspector; var feedbacksProperty = serializedObject.FindProperty("feedbacks"); var index = feedbacksProperty.arraySize; feedbacksProperty.InsertArrayElementAtIndex(index); var element = feedbacksProperty.GetArrayElementAtIndex(index); element.objectReferenceValue = addedComponent; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(size / 3f); Tree.DrawMonoScriptObjectField = false; InspectorUtilities.BeginDrawPropertyTree(Tree, true); InspectorUtilities.DrawPropertiesInTree(Tree); InspectorUtilities.EndDrawPropertyTree(Tree); }
public override void OnInspectorGUI() { // If there are no custom editors for a parent type just draw the inspector as usual if (parentEditorType == null) { base.OnInspectorGUI(); } else // If a parent type with a custom editor was found draw it { if (parentType != null) { SirenixEditorGUI.Title(ObjectNames.NicifyVariableName(parentType.GetNiceName()), null, TextAlignment.Left, true); } // Draw the parent custom editor if (parentEditorType != null) { CreateCachedEditor(target, parentEditorType, ref cachedParentEditor); cachedParentEditor.OnInspectorGUI(); } SirenixEditorGUI.Title(ObjectNames.NicifyVariableName(targetType.GetNiceName()), null, TextAlignment.Left, true); // Then draw the properties that the child class defined separately afterwards propertyTree ??= PropertyTree.Create(serializedObject); InspectorUtilities.BeginDrawPropertyTree(propertyTree, true); foreach (var inspectorProperty in propertyTree.EnumerateTree(false)) { // Don't draw properties that are covered by the parent editor type or any of its parents if (inspectorProperty.Info.TypeOfOwner == parentType || parentBaseClasses.Contains(inspectorProperty.Info.TypeOfOwner)) { continue; } inspectorProperty.Draw(inspectorProperty.Label); } InspectorUtilities.EndDrawPropertyTree(propertyTree); } }
protected static SettingsProvider CreateCustomSettingsProvider(string name) { _tree = PropertyTree.Create(GetInstance()); // First parameter is the path in the Settings window. // Second parameter is the scope of this setting: it only appears in the Project Settings window. SettingsProvider provider = new SettingsProvider($"Project/RedOwl/{name}", SettingsScope.Project) { // Create the SettingsProvider and initialize its drawing (IMGUI) function in place: guiHandler = searchContext => { InspectorUtilities.BeginDrawPropertyTree(_tree, false); foreach (InspectorProperty property in _tree.EnumerateTree(false)) { property.Draw(property.Label); } InspectorUtilities.EndDrawPropertyTree(_tree); }, // Populate the search keywords to enable smart search filtering and label highlighting: keywords = SettingsProvider.GetSearchKeywordsFromSerializedObject(new SerializedObject(GetInstance())) }; return(provider); }
private void DrawAddKey(IPropertyValueEntry <TDictionary> entry) { if (entry.IsEditable == false || this.attrSettings.IsReadOnly) { return; } if (SirenixEditorGUI.BeginFadeGroup(this, this.showAddKeyGUI)) { GUILayout.BeginVertical(AddKeyPaddingStyle); { if (typeof(TKey) == typeof(string) && this.newKey == null) { this.newKey = (TKey)(object)""; this.newKeyIsValid = null; } if (this.newKeyIsValid == null) { this.newKeyIsValid = CheckKeyIsValid(entry, this.newKey, out this.newKeyErrorMessage); } InspectorUtilities.BeginDrawPropertyTree(this.tempKeyEntry.Property.Tree, false); // Key { //this.TempKeyValue.key = this.NewKey; this.tempKeyEntry.Property.Update(); EditorGUI.BeginChangeCheck(); this.tempKeyEntry.Property.Draw(this.keyLabel); bool changed1 = EditorGUI.EndChangeCheck(); bool changed2 = this.tempKeyEntry.ApplyChanges(); if (changed1 || changed2) { this.newKey = this.tempKeyValue.Key; EditorApplication.delayCall += () => this.newKeyIsValid = null; GUIHelper.RequestRepaint(); } } // Value { //this.TempKeyValue.value = this.NewValue; this.tempValueEntry.Property.Update(); this.tempValueEntry.Property.Draw(this.valueLabel); this.tempValueEntry.ApplyChanges(); this.newValue = this.tempKeyValue.Value; } this.tempKeyEntry.Property.Tree.InvokeDelayedActions(); var changed = this.tempKeyEntry.Property.Tree.ApplyChanges(); if (changed) { this.newKey = this.tempKeyValue.Key; EditorApplication.delayCall += () => this.newKeyIsValid = null; GUIHelper.RequestRepaint(); } InspectorUtilities.EndDrawPropertyTree(this.tempKeyEntry.Property.Tree); GUIHelper.PushGUIEnabled(GUI.enabled && this.newKeyIsValid.Value); if (GUILayout.Button(this.newKeyIsValid.Value ? "Add" : this.newKeyErrorMessage)) { var keys = new object[entry.ValueCount]; var values = new object[entry.ValueCount]; for (int i = 0; i < keys.Length; i++) { keys[i] = SerializationUtility.CreateCopy(this.newKey); } for (int i = 0; i < values.Length; i++) { values[i] = SerializationUtility.CreateCopy(this.newValue); } this.dictionaryResolver.QueueSet(keys, values); EditorApplication.delayCall += () => this.newKeyIsValid = null; GUIHelper.RequestRepaint(); entry.Property.Tree.DelayActionUntilRepaint(() => { this.newValue = default(TValue); this.tempKeyValue.Value = default(TValue); this.tempValueEntry.Update(); }); } GUIHelper.PopGUIEnabled(); } GUILayout.EndVertical(); } SirenixEditorGUI.EndFadeGroup(); }
private void DrawAddKey(IPropertyValueEntry <TDictionary> entry, Context context) { if (entry.IsEditable == false || context.AttrSettings.IsReadOnly) { return; } if (SirenixEditorGUI.BeginFadeGroup(context, context.ShowAddKeyGUI)) { GUILayout.BeginVertical(AddKeyPaddingStyle); { if (typeof(TKey) == typeof(string) && context.NewKey == null) { context.NewKey = (TKey)(object)""; context.NewKewIsValid = null; } if (context.NewKewIsValid == null) { context.NewKewIsValid = CheckKeyIsValid(entry, context.NewKey, out context.NewKeyErrorMessage); } InspectorUtilities.BeginDrawPropertyTree(context.TempKeyEntry.Property.Tree, false); // Key { //context.TempKeyValue.key = context.NewKey; context.TempKeyEntry.Property.Update(); EditorGUI.BeginChangeCheck(); context.TempKeyEntry.Property.Draw(); bool changed1 = EditorGUI.EndChangeCheck(); bool changed2 = context.TempKeyEntry.ApplyChanges(); if (changed1 || changed2) { context.NewKey = context.TempKeyValue.Key; EditorApplication.delayCall += () => context.NewKewIsValid = null; GUIHelper.RequestRepaint(); } } // Value { //context.TempKeyValue.value = context.NewValue; context.TempValueEntry.Property.Update(); context.TempValueEntry.Property.Draw(); context.TempValueEntry.ApplyChanges(); context.NewValue = context.TempKeyValue.Value; } context.TempKeyEntry.Property.Tree.InvokeDelayedActions(); var changed = context.TempKeyEntry.Property.Tree.ApplyChanges(); if (changed) { context.NewKey = context.TempKeyValue.Key; EditorApplication.delayCall += () => context.NewKewIsValid = null; GUIHelper.RequestRepaint(); } InspectorUtilities.EndDrawPropertyTree(context.TempKeyEntry.Property.Tree); GUIHelper.PushGUIEnabled(GUI.enabled && context.NewKewIsValid.Value); if (GUILayout.Button(context.NewKewIsValid.Value ? "Add" : context.NewKeyErrorMessage)) { context.DictionaryHandler.SetValue(context.NewKey, context.NewValue); EditorApplication.delayCall += () => context.NewKewIsValid = null; GUIHelper.RequestRepaint(); entry.Property.Tree.DelayActionUntilRepaint(() => { context.NewValue = default(TValue); context.TempKeyValue.Value = default(TValue); context.TempValueEntry.Update(); }); } GUIHelper.PopGUIEnabled(); } GUILayout.EndVertical(); } SirenixEditorGUI.EndFadeGroup(); }
/// <summary> Draws standard field editors for all public fields </summary> public virtual void OnBodyGUI() { #if ODIN_INSPECTOR inNodeEditor = true; #endif // Unity specifically requires this to save/update any serial object. // serializedObject.Update(); must go at the start of an inspector gui, and // serializedObject.ApplyModifiedProperties(); goes at the end. serializedObject.Update(); string[] excludes = { "m_Script", "graph", "position", "ports" }; #if ODIN_INSPECTOR InspectorUtilities.BeginDrawPropertyTree(objectTree, true); GUIHelper.PushLabelWidth(84); objectTree.Draw(true); InspectorUtilities.EndDrawPropertyTree(objectTree); GUIHelper.PopLabelWidth(); #else if (typeof(UnityEngine.Object).IsAssignableFrom(target.Type)) { if (target.GetType() == typeof(BlackboardNonSerializedVariable)) { target.Value = EditorGUILayout.ObjectField((UnityEngine.Object)target.Value, target.Type, true); } else { target.Value = EditorGUILayout.ObjectField((UnityEngine.Object)target.Value, target.Type, false); } } else { switch (target.Type.Name) { case ("Int32"): target.Value = EditorGUILayout.IntField((int)target.Value); break; case ("Single"): target.Value = EditorGUILayout.FloatField((float)target.Value); break; case ("Vector2"): target.Value = EditorGUILayout.Vector2Field("", (Vector2)target.Value); break; case ("Vector3"): target.Value = EditorGUILayout.Vector3Field("", (Vector3)target.Value); break; case ("Vector4"): target.Value = EditorGUILayout.Vector4Field("", (Vector4)target.Value); break; case ("String"): target.Value = EditorGUILayout.TextField("", (string)target.Value); break; case ("Boolean"): target.Value = EditorGUILayout.Toggle("", (bool)target.Value); break; default: EditorGUILayout.LabelField(target.Type.Name); break; } } // Iterate through serialized properties and draw them like the Inspector (But with ports) //SerializedProperty iterator = serializedObject.GetIterator(); //bool enterChildren = true; //while (iterator.NextVisible(enterChildren)) { // enterChildren = false; // if (excludes.Contains(iterator.name)) continue; // EditorGUILayout.PropertyField(iterator, true); //} #endif serializedObject.ApplyModifiedProperties(); #if ODIN_INSPECTOR // Call repaint so that the graph window elements respond properly to layout changes coming from Odin if (GUIHelper.RepaintRequested) { GUIHelper.ClearRepaintRequest(); window.Repaint(); } #endif #if ODIN_INSPECTOR inNodeEditor = false; #endif }
protected override void OnGUI() { _repaintSheduled = false; GUILayout.BeginHorizontal(); if (GUILayout.Button("Clear")) { _properties.Clear(); } Rect settingsRect = GUILayoutUtility.GetRect(24, 24, GUILayout.ExpandWidth(false)).AlignLeft(20).AlignCenterY(20); if (SirenixEditorGUI.IconButton(settingsRect, _showSettings ? EditorIcons.SettingsCog.Inactive : EditorIcons.SettingsCog.Active, "Settings")) { _showSettings = !_showSettings; } GUILayout.EndHorizontal(); if (_showSettings) { GUILayout.BeginHorizontal(); GUILayout.Space(40); GUI.changed = false; Rect rect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight, GUILayout.ExpandWidth(true)); _labelWidth = GUI.HorizontalSlider(rect, _labelWidth, rect.xMin, rect.xMax); if (GUI.changed) { EditorPrefs.SetFloat("OWW_labelWidth", _labelWidth); } EditorGUILayout.LabelField("Label Width", GUILayout.Width(70)); GUILayout.EndHorizontal(); } GUILayout.Space(5); bool first = true; if (_properties.Count == 0) { EditorGUILayout.LabelField("Right-click any property in an Inspector and select 'Watch' to make it show up here.", SirenixGUIStyles.MultiLineCenteredLabel); } GUIHelper.PushLabelWidth(_labelWidth - 30); for (int i = 0; i < _properties.Count; i++) { TreeValuesHolder holder = _properties[i]; holder.CheckRefresh(); if (!first) { GUILayout.Space(5); } first = false; Rect titleRect = SirenixEditorGUI.BeginBox(" " + holder.Tree.TargetType.Name); titleRect = titleRect.AlignTop(21); if (holder.ParentObject != null) { Rect alignRight = titleRect.AlignRight(200).AlignCenterY(16).AlignLeft(180); GUIHelper.PushGUIEnabled(false); SirenixEditorFields.UnityObjectField(alignRight, holder.ParentObject, typeof(GameObject), true); GUIHelper.PopGUIEnabled(); } if (SirenixEditorGUI.IconButton(titleRect.AlignRight(20).AlignCenterY(18), EditorIcons.X)) { _properties.RemoveAt(i--); } Rect titleDragDropRect = titleRect.AlignLeft(30).AlignCenter(20, 20); EditorIcons.List.Draw(titleDragDropRect); TreeValuesHolder treedragdrop = (TreeValuesHolder)DragAndDropUtilities.DragAndDropZone(titleDragDropRect, holder, typeof(TreeValuesHolder), false, false); if (treedragdrop != holder) { int treeDragDropIndex = _properties.IndexOf(treedragdrop); Swap(_properties, treeDragDropIndex, i); } if (holder.Tree.UnitySerializedObject?.targetObject == null) { EditorGUILayout.LabelField($"This component is no longer valid in the current context (loaded different scene?)", SirenixGUIStyles.MultiLineLabel); } else { InspectorUtilities.BeginDrawPropertyTree(holder.Tree, true); for (int index = 0; index < holder.ValuePaths.Count; index++) { string path = holder.ValuePaths[index]; GUILayout.BeginHorizontal(); Rect rect1 = GUILayoutUtility.GetRect(EditorGUIUtility.singleLineHeight + 5, EditorGUIUtility.singleLineHeight + 3, GUILayout.ExpandWidth(false)).AlignRight(EditorGUIUtility.singleLineHeight + 2); EditorIcons.List.Draw(rect1); ValueDragDropHolder dragdrop = (ValueDragDropHolder)DragAndDropUtilities.DragAndDropZone(rect1, new ValueDragDropHolder(holder, index), typeof(ValueDragDropHolder), false, false); if (dragdrop.TreeValuesHolder == holder && dragdrop.Index != index) { string ptemp = holder.ValuePaths[index]; holder.ValuePaths[index] = holder.ValuePaths[dragdrop.Index]; holder.ValuePaths[dragdrop.Index] = ptemp; } InspectorProperty propertyAtPath = holder.Tree.GetPropertyAtPath(path); if (propertyAtPath == null) { propertyAtPath = holder.Tree.GetPropertyAtUnityPath(path); } if (propertyAtPath != null) { propertyAtPath.Draw(); } else { EditorGUILayout.LabelField($"Could not find property ({path})"); } if (SirenixEditorGUI.IconButton(EditorIcons.X)) { holder.ValuePaths.RemoveAt(index--); if (holder.ValuePaths.Count == 0) { _properties.RemoveAt(i--); } } GUILayout.Space(3); GUILayout.EndHorizontal(); } InspectorUtilities.EndDrawPropertyTree(holder.Tree); } SirenixEditorGUI.EndBox(); } GUIHelper.PopLabelWidth(); }
public override void OnInspectorGUI() { var tree = Tree; InspectorUtilities.BeginDrawPropertyTree(tree, true); var size = (EditorGUIUtility.fieldWidth / 16) * 9 * 3.3f; EditorGUIUtility.labelWidth = size + 75; language = (Language)EditorGUILayout.EnumPopup(new GUIContent($"Language {languageIndex + 1}/{languagesCount}"), language); GUILayout.Space(10); DrawLanguageSpecificInfo(new GUIContent("<b>Title</b>"), 0, 20); DrawLanguageSpecificInfo(new GUIContent("<b>Action Verb</b>"), 2, 25); DrawLanguageSpecificInfo(new GUIContent("<b>Description</b>"), 1, 180, true); var rect = GUILayoutUtility.GetRect(1, size); var thumbnailRect = new Rect(rect.x, rect.y, size, rect.height); var thumbnailProperty = tree.GetPropertyAtPath("thumbnail"); thumbnailProperty.ValueEntry.WeakSmartValue = SirenixEditorFields.UnityPreviewObjectField(thumbnailRect, GUIContent.none, (Sprite)thumbnailProperty.ValueEntry.WeakSmartValue, typeof(Sprite), false, ObjectFieldAlignment.Left); EditorGUIUtility.labelWidth = 75; var sceneRect = new Rect(thumbnailRect.xMax + 3, thumbnailRect.y - 7, rect.width - thumbnailRect.width, EditorGUIUtility.singleLineHeight + 9); EditorGUI.PropertyField(sceneRect, serializedObject.FindProperty("scene"), new GUIContent("Scene")); var inputsRect = new Rect(sceneRect.x, sceneRect.yMax - 5, sceneRect.width - 2, EditorGUIUtility.singleLineHeight); EditorGUI.PropertyField(inputsRect, serializedObject.FindProperty("inputs"), new GUIContent("Inputs")); var rythmRect = new Rect(inputsRect.x, inputsRect.yMax + 11, inputsRect.width, inputsRect.height); EditorGUI.PropertyField(rythmRect, serializedObject.FindProperty("rythmConstraints"), new GUIContent("Constraints")); var rivalsRect = DrawRivals(rythmRect); var themeRect = new Rect(rythmRect.x, rivalsRect.yMax + 3, rythmRect.width, rythmRect.height); EditorGUI.PropertyField(themeRect, serializedObject.FindProperty("theme"), new GUIContent("Theme")); EditorGUIUtility.labelWidth = size; EditorGUILayout.Separator(); var designerRect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight); DrawAuthor(designerRect, designerProperty, new GUIContent("Designer")); GUILayout.Space(2); var developerRect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight); DrawAuthor(developerRect, developerProperty, new GUIContent("Developer")); InspectorUtilities.EndDrawPropertyTree(tree); }