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 }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <TList> entry, GUIContent label) { var property = entry.Property; int minCount = int.MaxValue; int maxCount = 0; PropertyContext <bool> isVisible; if (entry.Context.Get(this, "is_visible", out isVisible)) { isVisible.Value = GeneralDrawerConfig.Instance.OpenListsByDefault; } for (int i = 0; i < entry.ValueCount; i++) { if (entry.Values[i].Count > maxCount) { maxCount = entry.Values[i].Count; } if (entry.Values[i].Count < minCount) { minCount = entry.Values[i].Count; } } AllEditorGUI.BeginHorizontalToolbar(); isVisible.Value = AllEditorGUI.Foldout(isVisible.Value, GUIHelper.TempContent("SyncList " + label.text + " [" + typeof(TList).Name + "]")); EditorGUILayout.LabelField(GUIHelper.TempContent(minCount == maxCount ? (minCount == 0 ? "Empty" : minCount + " items") : minCount + " (" + maxCount + ") items"), SirenixGUIStyles.RightAlignedGreyMiniLabel); AllEditorGUI.EndHorizontalToolbar(); if (AllEditorGUI.BeginFadeGroup(isVisible, isVisible.Value)) { GUIHelper.PushGUIEnabled(false); AllEditorGUI.BeginVerticalList(); { var elementLabel = new GUIContent(); for (int i = 0; i < maxCount; i++) { AllEditorGUI.BeginListItem(); elementLabel.text = "Item " + i; if (i < minCount) { InspectorUtilities.DrawProperty(property.Children[i], elementLabel); } else { EditorGUILayout.LabelField(elementLabel, "—"); } AllEditorGUI.EndListItem(); } } AllEditorGUI.EndVerticalList(); GUIHelper.PopGUIEnabled(); } AllEditorGUI.EndFadeGroup(); }
protected override void DrawTree() { if (customTree == null) { customTree = PropertyTree.Create(serializedObject); } InspectorUtilities.BeginDrawPropertyTree(customTree, true); InspectorUtilities.DrawPropertiesInTree(customTree); InspectorUtilities.EndDrawPropertyTree(customTree); }
private void CreateNewProfile() { ValidationProfileSOCreator.ShowDialog <ValidationProfileAsset>(SirenixAssetPaths.SirenixPluginPath + "Odin Validator/Editor/Config/", newProfile => { if (newProfile != null) { this.MainValidationProfiles.Add(newProfile); InspectorUtilities.RegisterUnityObjectDirty(this); } }); }
public override void OnInspectorGUI() { serializedObject.Update(); ColorVolume volume = target as ColorVolume; SerializedProperty modeProperty = serializedObject.FindProperty("Mode"); SerializedProperty gradientTypeProperty = serializedObject.FindProperty("GradientType"); SerializedProperty colorProperty = serializedObject.FindProperty("Color"); SerializedProperty gradientProperty = serializedObject.FindProperty("Gradient"); SerializedProperty offsetProperty = serializedObject.FindProperty("GradientOffset"); SerializedProperty invertProperty = serializedObject.FindProperty("InvertGradient"); EditorGUILayout.Space(20.0f); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Apply", GUILayout.Width(200))) { volume.Apply(); } if (GUILayout.Button("Apply & Remove", GUILayout.Width(200))) { volume.ApplyAndRemove(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); InspectorUtilities.Header("Settings"); InspectorUtilities.EnumToolbar <VolumeMode>(modeProperty, "Mode"); VolumeMode mode = (VolumeMode)modeProperty.enumValueIndex; if (mode == VolumeMode.Color) { EditorGUILayout.PropertyField(colorProperty, true); } else { InspectorUtilities.EnumToolbar <GradientType>(gradientTypeProperty, "Gradient Type"); EditorGUILayout.PropertyField(gradientProperty, true); EditorGUILayout.PropertyField(offsetProperty, true); EditorGUILayout.PropertyField(invertProperty, true); } EditorGUILayout.Space(20.0f); if (target != null) { serializedObject.ApplyModifiedProperties(); } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label) { if (entry.ValueState == PropertyValueState.Reference) { var isToggled = entry.Context.GetPersistent(this, "is_Toggled", false); var targetProp = entry.Property.Tree.GetPropertyAtPath(entry.TargetReferencePath); SirenixEditorGUI.BeginBox(); SirenixEditorGUI.BeginBoxHeader(); EditorGUILayout.BeginHorizontal(); isToggled.Value = label != null?SirenixEditorGUI.Foldout(isToggled.Value, label) : SirenixEditorGUI.Foldout(isToggled.Value, GUIHelper.TempContent("")); if (targetProp.Parent == null) { EditorGUILayout.LabelField("Reference to " + targetProp.Path, SirenixGUIStyles.RightAlignedGreyMiniLabel); } else { EditorGUILayout.LabelField("Reference to " + targetProp.Path, SirenixGUIStyles.RightAlignedGreyMiniLabel); } EditorGUILayout.EndHorizontal(); SirenixEditorGUI.EndBoxHeader(); if (SirenixEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry.Property, this), isToggled.Value)) { //EditorGUI.indentLevel++; //GUIHelper.PushGUIEnabled(true); var isInReference = targetProp.Context.GetGlobal("is_in_reference", false); bool previous = isInReference.Value; isInReference.Value = true; InspectorUtilities.DrawProperty(targetProp); isInReference.Value = previous; //GUIHelper.PopGUIEnabled(); //EditorGUI.indentLevel--; } SirenixEditorGUI.EndFadeGroup(); SirenixEditorGUI.EndBox(); } else { this.CallNextDrawer(entry.Property, label); } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, ButtonGroupAttribute attribute, GUIContent label) { SirenixEditorGUI.BeginIndentedHorizontal(); PropertyContext <int> height; if (property.Context.Get(this, "ButtonHeight", out height)) { //height = new PropertyContext<int>(); height.Value = 0; for (int i = 0; i < property.Children.Count; i++) { var button = property.Children[i].Info.GetAttribute <ButtonAttribute>(); if (button != null && button.ButtonHeight > 0) { height.Value = button.ButtonHeight; } } } for (int i = 0; i < property.Children.Count; i++) { var style = (GUIStyle)null; if (property.Children.Count != 1) { if (i == 0) { style = SirenixGUIStyles.ButtonLeft; } else if (i == property.Children.Count - 1) { style = SirenixGUIStyles.ButtonRight; } else { style = SirenixGUIStyles.ButtonMid; } } property.Children[i].Context.GetGlobal("ButtonHeight", height.Value).Value = height.Value; property.Children[i].Context.GetGlobal("ButtonStyle", style).Value = style; InspectorUtilities.DrawProperty(property.Children[i]); } SirenixEditorGUI.EndIndentedHorizontal(); }
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(); } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, BoxGroupAttribute attribute, GUIContent label) { var labelGetter = property.Context.Get <StringMemberHelper>(this, "LabelContext", (StringMemberHelper)null); if (labelGetter.Value == null) { labelGetter.Value = new StringMemberHelper(property.ParentType, attribute.GroupName); } SirenixEditorGUI.BeginBox(attribute.ShowLabel ? labelGetter.Value.GetString(property) : null, attribute.CenterLabel); for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } SirenixEditorGUI.EndBox(); }
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); } }
public static void DrawPropertyGroupLayout <T>(OdinGroupDrawer <T> ogd, InspectorProperty property, T attribute, GUIContent label, bool result) where T : CrossSceneSideAttribute { if (SirenixEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(property, ogd), result)) { var labelGetter = property.Context.Get <StringMemberHelper>(ogd, "LabelContext", (StringMemberHelper)null); if (labelGetter.Value == null) { labelGetter.Value = new StringMemberHelper(property.ParentType, attribute.GroupName); } SirenixEditorGUI.BeginBox(attribute.ShowLabel ? labelGetter.Value.GetString(property) : null, attribute.CenterLabel); for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i], property.Children[i].Label); } SirenixEditorGUI.EndBox(); } SirenixEditorGUI.EndFadeGroup(); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, FoldoutGroupAttribute attribute, GUIContent label) { var context = property.Context.Get <FoldoutGroupContext>(this, "FoldoutGroupContext", (FoldoutGroupContext)null); if (context.Value == null) { context.Value = new FoldoutGroupContext() { IsVisible = property.Context.GetPersistent <bool>(this, "IsVisible", attribute.HasDefinedExpanded ? attribute.Expanded : AllEditorGUI.ExpandFoldoutByDefault), TitleHelper = new StringMemberHelper(property.ParentType, attribute.GroupName) }; } if (context.Value.TitleHelper.ErrorMessage != null) { AllEditorGUI.ErrorMessageBox(context.Value.TitleHelper.ErrorMessage); } AllEditorGUI.BeginBox(); { AllEditorGUI.BeginBoxHeader(); var content = GUIHelper.TempContent(context.Value.TitleHelper.GetString(property)); var rect = GUILayoutUtility.GetRect(content, SirenixGUIStyles.Label); context.Value.IsVisible.Value = AllEditorGUI.Foldout(rect, context.Value.IsVisible.Value, content); AllEditorGUI.EndBoxHeader(); if (AllEditorGUI.BeginFadeGroup(context, context.Value.IsVisible.Value)) { for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } } AllEditorGUI.EndFadeGroup(); } AllEditorGUI.EndBox(); }
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); }
/// <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 }
private void DrawElements(IPropertyValueEntry <TDictionary> entry, GUIContent label, Context context) { for (int i = context.Paging.StartIndex; i < context.Paging.EndIndex; i++) { var keyValuePairProperty = entry.Property.Children[i]; var keyValuePairEntry = (PropertyDictionaryElementValueEntry <TDictionary, TKey, TValue>)keyValuePairProperty.BaseValueEntry; Rect rect = SirenixEditorGUI.BeginListItem(false, context.ListItemStyle); { if (context.AttrSettings.DisplayMode != DictionaryDisplayOptions.OneLine) { bool defaultExpanded; switch (context.AttrSettings.DisplayMode) { case DictionaryDisplayOptions.CollapsedFoldout: defaultExpanded = false; break; case DictionaryDisplayOptions.ExpandedFoldout: defaultExpanded = true; break; default: defaultExpanded = SirenixEditorGUI.ExpandFoldoutByDefault; break; } var isExpanded = keyValuePairProperty.Context.Get(this, "Expanded", defaultExpanded); SirenixEditorGUI.BeginBox(); SirenixEditorGUI.BeginBoxHeader(); { if (keyValuePairEntry.HasTempInvalidKey) { GUIHelper.PushColor(Color.red); } var btnRect = GUIHelper.GetCurrentLayoutRect().AlignLeft(HeaderMargin.margin.left); btnRect.y += 1; GUILayout.BeginVertical(HeaderMargin); GUIHelper.PushIsDrawingDictionaryKey(true); GUIHelper.PushLabelWidth(10); InspectorUtilities.DrawProperty(keyValuePairProperty.Children[0], null); GUIHelper.PopLabelWidth(); GUIHelper.PopIsDrawingDictionaryKey(); GUILayout.EndVertical(); if (keyValuePairEntry.HasTempInvalidKey) { GUIHelper.PopColor(); } isExpanded.Value = SirenixEditorGUI.Foldout(btnRect, isExpanded.Value, GUIHelper.TempContent("Key")); } SirenixEditorGUI.EndBoxHeader(); if (SirenixEditorGUI.BeginFadeGroup(isExpanded, isExpanded.Value)) { InspectorUtilities.DrawProperty(keyValuePairProperty.Children[1], null); } SirenixEditorGUI.EndFadeGroup(); SirenixEditorGUI.EndBox(); } else { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayoutOptions.Width(context.KeyWidthOffset)); { var keyProperty = keyValuePairProperty.Children[0]; if (keyValuePairEntry.HasTempInvalidKey) { GUIHelper.PushColor(Color.red); } if (context.AttrSettings.IsReadOnly) { GUIHelper.PushGUIEnabled(false); } GUIHelper.PushIsDrawingDictionaryKey(true); GUIHelper.PushLabelWidth(10); InspectorUtilities.DrawProperty(keyProperty, null); GUIHelper.PopLabelWidth(); GUIHelper.PopIsDrawingDictionaryKey(); if (context.AttrSettings.IsReadOnly) { GUIHelper.PopGUIEnabled(); } if (keyValuePairEntry.HasTempInvalidKey) { GUIHelper.PopColor(); } } GUILayout.EndVertical(); GUILayout.BeginVertical(OneLineMargin); { var valueEntry = keyValuePairProperty.Children[1]; var tmp = GUIHelper.ActualLabelWidth; EditorGUIUtility.labelWidth = 150; InspectorUtilities.DrawProperty(valueEntry, null); EditorGUIUtility.labelWidth = tmp; } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } if (entry.IsEditable && !context.AttrSettings.IsReadOnly && SirenixEditorGUI.IconButton(new Rect(rect.xMax - 24 + 5, rect.y + 2 + ((int)rect.height - 23) / 2, 14, 14), EditorIcons.X)) { context.DictionaryHandler.Remove(context.DictionaryHandler.GetKey(0, i)); EditorApplication.delayCall += () => context.NewKewIsValid = null; GUIHelper.RequestRepaint(); } } SirenixEditorGUI.EndListItem(); } if (context.Paging.IsOnLastPage && entry.ValueState == PropertyValueState.CollectionLengthConflict) { SirenixEditorGUI.BeginListItem(false); GUILayout.Label(GUIHelper.TempContent("------"), EditorStyles.centeredGreyMiniLabel); SirenixEditorGUI.EndListItem(); } }
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); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, HorizontalGroupAttribute attribute, GUIContent label) { var context = property.Context.Get(this, "Context", (Context)null); if (context.Value == null) { context.Value = new Context(); if (attribute.Title != null) { context.Value.TitleHelper = new StringMemberHelper(property.ParentType, attribute.Title); } context.Value.Widths = new float[property.Children.Count]; context.Value.MinWidths = new float[property.Children.Count]; context.Value.MaxWidths = new float[property.Children.Count]; context.Value.LabelWidths = new float[property.Children.Count]; context.Value.Margins = new Vector2[property.Children.Count]; context.Value.Paddings = new Vector2[property.Children.Count]; float percentageAllocated = 0; for (int i = 0; i < property.Children.Count; i++) { var child = property.Children[i]; var attr = child.Children.Recurse() .Append(child) .SelectMany(a => a.Info.GetAttributes <HorizontalGroupAttribute>()) .FirstOrDefault(x => x.GroupID == attribute.GroupID); if (attr == null) { context.Value.Widths[i] = -1; } else { context.Value.Widths[i] = attr.Width; context.Value.MinWidths[i] = attr.MinWidth; context.Value.MaxWidths[i] = attr.MaxWidth; context.Value.LabelWidths[i] = attr.LabelWidth; if (attr.Width > 0 && attr.Width < 1) { context.Value.ContainsPercentageWidth++; percentageAllocated += attr.Width; // If we allocate 100% there is no way to resize the window down. // In those cases, we convert the attribute to adjust itself automatically and Unity will ensure that // that it reaches the 100% for us. if (percentageAllocated >= 0.97) { percentageAllocated -= attr.Width; context.Value.Widths[i] = 0; attr.Width = 0; } } if (attr.MinWidth > 0 && attr.MinWidth <= 1) { context.Value.ContainsPercentageWidth++; percentageAllocated += attr.MinWidth; // Same thing for MinWidth. if (percentageAllocated >= 0.97) { percentageAllocated -= attr.MinWidth; context.Value.MinWidths[i] = 0; attr.MinWidth = 0; } } context.Value.Margins[i] = new Vector2(attr.MarginLeft, attr.MarginRight); context.Value.Paddings[i] = new Vector2(attr.PaddingLeft, attr.PaddingRight); } } } if (context.Value.TitleHelper != null) { if (context.Value.TitleHelper.ErrorMessage != null) { AllEditorGUI.ErrorMessageBox(context.Value.TitleHelper.ErrorMessage); } else { AllEditorGUI.Title(context.Value.TitleHelper.GetString(property), null, TextAlignment.Left, false); } } AllEditorGUI.BeginIndentedHorizontal(GUILayoutOptions.ExpandWidth(false)); { if (Event.current.type == EventType.Repaint) { var newWidth = GUIHelper.GetCurrentLayoutRect().width; if (context.Value.TotalWidth != newWidth) { GUIHelper.RequestRepaint(); } context.Value.TotalWidth = newWidth; } for (int i = 0; i < property.Children.Count; i++) { float width, minWidth, maxWidth; Vector2 padding, margin; if (context.Value.ContainsPercentageWidth > 1 && context.Value.TotalWidth == 0) { width = 20; // Start small and expand next frame. Instead of starting to big and slowly getting smaller. minWidth = 0; maxWidth = 0; padding = new Vector2(); margin = new Vector2(); } else { width = context.Value.Widths[i]; minWidth = context.Value.MinWidths[i]; maxWidth = context.Value.MaxWidths[i]; margin = context.Value.Margins[i]; padding = context.Value.Paddings[i]; if (padding.x > 0 && padding.x <= 1) { padding.x = padding.x * context.Value.TotalWidth; } if (padding.y > 0 && padding.y <= 1) { padding.y = padding.y * context.Value.TotalWidth; } if (margin.x > 0 && margin.x <= 1) { margin.x = margin.x * context.Value.TotalWidth; } if (margin.y > 0 && margin.y <= 1) { margin.y = margin.y * context.Value.TotalWidth; } if (width <= 1) { width = width * context.Value.TotalWidth; } width -= padding.x + padding.y; if (minWidth > 0) { if (minWidth <= 1) { minWidth = minWidth * context.Value.TotalWidth; } minWidth -= padding.x + padding.y; } if (maxWidth > 0) { if (maxWidth <= 1) { maxWidth = maxWidth * context.Value.TotalWidth; } maxWidth -= padding.x + padding.y; } } GUILayoutOptions.GUILayoutOptionsInstance options = null; if (minWidth > 0) { options = GUILayoutOptions.MinWidth(minWidth); } if (maxWidth > 0) { options = options == null?GUILayoutOptions.MaxWidth(maxWidth) : options.MaxWidth(maxWidth); } if (options == null) { options = GUILayoutOptions.Width(width < 0 ? 0 : width); } var prevFieldWidth = EditorGUIUtility.fieldWidth; EditorGUIUtility.fieldWidth = 40; GUILayout.Space(margin.x + padding.x); GUILayout.BeginVertical(options); GUILayout.Space(0); if (attribute.LabelWidth > 0) { GUIHelper.PushLabelWidth(attribute.LabelWidth); } InspectorUtilities.DrawProperty(property.Children[i], property.Children[i].Label); if (attribute.LabelWidth > 0) { GUIHelper.PopLabelWidth(); } GUILayout.Space(0); GUILayout.EndVertical(); EditorGUIUtility.fieldWidth = prevFieldWidth; GUILayout.Space(margin.y + padding.y); } } AllEditorGUI.EndIndentedHorizontal(); }
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(); }
private Rect DrawItem(ListDrawerConfigInfo info, InspectorProperty itemProperty, DragHandle dragHandle, int index = -1) { var listItemInfo = itemProperty.Context.Get <ListItemInfo>(this, "listItemInfo"); Rect rect; rect = SirenixEditorGUI.BeginListItem(false, info.ListItemStyle, listItemOptions); { if (Event.current.type == EventType.Repaint && !info.IsReadOnly) { listItemInfo.Value.Width = rect.width; dragHandle.DragHandleRect = new Rect(rect.x + 4, rect.y, 20, rect.height); listItemInfo.Value.DragHandleRect = new Rect(rect.x + 4, rect.y + 2 + ((int)rect.height - 23) / 2, 20, 20); listItemInfo.Value.AddBtnRect = new Rect(listItemInfo.Value.DragHandleRect.x + rect.width - 22, listItemInfo.Value.DragHandleRect.y + 1, 14, 14); itemProperty.Context.GetGlobal <Rect?>("overrideRect").Value = rect; if (info.Draggable) { //GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; GUI.Label(listItemInfo.Value.DragHandleRect, EditorIcons.List.Inactive, GUIStyle.none); //GL.sRGBWrite = false; } } GUIHelper.PushHierarchyMode(false); GUIContent label = null; if (info.CustomListDrawerOptions.ShowIndexLabelsHasValue) { if (info.CustomListDrawerOptions.ShowIndexLabels) { label = new GUIContent(index.ToString()); } } else if (info.listConfig.ShowIndexLabels) { label = new GUIContent(index.ToString()); } if (info.GetListElementLabelText != null) { var value = itemProperty.ValueEntry.WeakSmartValue; if (object.ReferenceEquals(value, null)) { if (label == null) { label = new GUIContent("Null"); } else { label.text += " : Null"; } } else { label = label ?? new GUIContent(""); if (label.text != "") { label.text += " : "; } object text = info.GetListElementLabelText(value); label.text += (text == null ? "" : text.ToString()); } } if (info.OnBeginListElementGUI != null) { info.OnBeginListElementGUI(info.property.ParentValues[0], index); } InspectorUtilities.DrawProperty(itemProperty, label); if (info.OnEndListElementGUI != null) { info.OnEndListElementGUI(info.property.ParentValues[0], index); } GUIHelper.PopHierarchyMode(); if (info.IsReadOnly == false) { if (SirenixEditorGUI.IconButton(listItemInfo.Value.AddBtnRect, EditorIcons.X)) { if (index >= 0) { info.RemoveAt = index; } } } } SirenixEditorGUI.EndListItem(); return(rect); }
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(); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, TabGroupAttribute attribute, GUIContent label) { var tabGroup = AllEditorGUI.CreateAnimatedTabGroup(property); tabGroup.AnimationSpeed = 1 / AllEditorGUI.TabPageSlideAnimationDuration; tabGroup.FixedHeight = attribute.UseFixedHeight; LocalPersistentContext <int> persistentPageContext = property.Context.GetPersistent(this, "CurrentPage", 0); bool setPersistentPage = false; PropertyContext <List <Tab> > tabs; if (property.Context.Get(this, "Tabs", out tabs)) { setPersistentPage = true; tabs.Value = new List <Tab>(); var addLastTabs = new List <Tab>(); for (int j = 0; j < property.Children.Count; j++) { var child = property.Children[j]; bool added = false; if (child.Info.PropertyType == PropertyType.Group) { var attrType = child.Info.GetAttribute <PropertyGroupAttribute>().GetType(); if (attrType.IsNested && attrType.DeclaringType == typeof(TabGroupAttribute)) { // This is a tab subgroup; add all its children to a tab for that subgroup Tab tab = new Tab(); tab.TabName = child.NiceName; tab.Title = new StringMemberHelper(property.ParentType, child.Name.TrimStart('#')); for (int i = 0; i < child.Children.Count; i++) { tab.InspectorProperties.Add(child.Children[i]); } tabs.Value.Add(tab); added = true; } } if (!added) { // This is a group member of the tab group itself, so it gets its own tab Tab tab = new Tab(); tab.TabName = child.NiceName; tab.Title = new StringMemberHelper(property.ParentType, child.Name.TrimStart('#')); tab.InspectorProperties.Add(child); addLastTabs.Add(tab); } } foreach (var tab in addLastTabs) { tabs.Value.Add(tab); } } for (int i = 0; i < tabs.Value.Count; i++) { tabGroup.RegisterTab(tabs.Value[i].TabName); } if (setPersistentPage) { if (persistentPageContext.Value >= tabs.Value.Count || persistentPageContext.Value < 0) { persistentPageContext.Value = 0; } tabGroup.SetCurrentPage(tabGroup.RegisterTab(tabs.Value[persistentPageContext.Value].TabName)); } AllEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding); tabGroup.BeginGroup(); for (int i = 0; i < tabs.Value.Count; i++) { var page = tabGroup.RegisterTab(tabs.Value[i].TabName); page.Title = tabs.Value[i].Title.GetString(property); if (page.BeginPage()) { persistentPageContext.Value = i; int pageCount = tabs.Value[i].InspectorProperties.Count; for (int j = 0; j < pageCount; j++) { InspectorUtilities.DrawProperty(tabs.Value[i].InspectorProperties[j]); } } page.EndPage(); } tabGroup.EndGroup(); AllEditorGUI.EndIndentedVertical(); }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyImplementation(InspectorProperty property, GUIContent label) { if (label == null) { AllEditorGUI.BeginIndentedVertical(); for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } AllEditorGUI.EndIndentedVertical(); } else { Context context; if (property.Context.Get <Context>(this, "context", out context)) { context.IsVisisble = property.Context.GetPersistent(this, "IsVisible", AllEditorGUI.ExpandFoldoutByDefault); context.IsInlineProperty = property.ValueEntry.TypeOfValue.GetAttribute <InlinePropertyAttribute>() ?? property.Info.GetAttribute <InlinePropertyAttribute>(); } if (context.IsInlineProperty != null) { var outerRect = EditorGUILayout.BeginHorizontal(); { if (Event.current.type == EventType.Repaint) { outerRect.y += 1; EditorGUI.PrefixLabel(outerRect, label); } GUILayout.Space(EditorGUIUtility.labelWidth); GUILayout.BeginVertical(); { if (context.IsInlineProperty.LabelWidth > 0) { GUIHelper.PushLabelWidth(context.IsInlineProperty.LabelWidth); } GUIHelper.PushIndentLevel(0); for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } GUIHelper.PopIndentLevel(); if (context.IsInlineProperty.LabelWidth > 0) { GUIHelper.PopLabelWidth(); } } GUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); } else { context.IsVisisble.Value = AllEditorGUI.Foldout(context.IsVisisble.Value, label); if (AllEditorGUI.BeginFadeGroup(context, context.IsVisisble.Value)) { EditorGUI.indentLevel++; for (int i = 0; i < property.Children.Count; i++) { InspectorUtilities.DrawProperty(property.Children[i]); } EditorGUI.indentLevel--; } AllEditorGUI.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 the property. /// </summary> protected override void DrawPropertyGroupLayout(InspectorProperty property, ToggleGroupAttribute attribute, GUIContent label) { var toggleProperty = property.Children.Get(attribute.ToggleMemberName); var context = property.Context.Get <ToggleGroupConfig>(this, "ToggleGroupConfig", (ToggleGroupConfig)null); if (context.Value == null) { context.Value = new ToggleGroupConfig(); context.Value.IsVisible = property.Context.GetPersistent <bool>(this, "IsVisible", false); if (toggleProperty == null) { context.Value.ErrorMessage = "No property or field named " + attribute.ToggleMemberName + " found. Make sure the property is part of the inspector and the group."; } else { context.Value.TitleHelper = new StringMemberHelper(property.ParentType, attribute.ToggleGroupTitle, ref context.Value.ErrorMessage); } } if (context.Value.ErrorMessage != null) { AllEditorGUI.ErrorMessageBox(context.Value.ErrorMessage); } else { PropertyContext <string> openGroup = null; if (attribute.CollapseOthersOnExpand) { if (property.Parent == null) { //openGroup = GUIHelper.GetTemporaryContext<PropertyContext<string>>(property.Tree); openGroup = property.Context.Get <string>(this, "OpenGroup", (string)null); } else { var parent = (property.Parent.ValueEntry == null || property.Parent.ValueEntry.ValueCategory == PropertyValueCategory.Member) ? property.Parent : property.Parent.Parent; openGroup = parent.Context.GetGlobal <string>("OpenFoldoutToggleGroup", (string)null); } if (openGroup.Value != null && openGroup.Value != property.Path) { context.Value.IsVisible.Value = false; } } bool isEnabled = (bool)toggleProperty.ValueEntry.WeakSmartValue; string title = context.Value.TitleHelper.GetString(property) ?? attribute.GroupName; bool prev = context.Value.IsVisible.Value; bool visibleBuffer = context.Value.IsVisible.Value; if (AllEditorGUI.BeginToggleGroup(UniqueDrawerKey.Create(property, this), ref isEnabled, ref visibleBuffer, title)) { for (int i = 0; i < property.Children.Count; i++) { var child = property.Children[i]; if (child != toggleProperty) { InspectorUtilities.DrawProperty(child); } } } else { // OnValueChanged is not fired if property is not drawn. GUIHelper.BeginDrawToNothing(); InspectorUtilities.DrawProperty(toggleProperty); GUIHelper.EndDrawToNothing(); } AllEditorGUI.EndToggleGroup(); context.Value.IsVisible.Value = visibleBuffer; if (openGroup != null && prev != context.Value.IsVisible.Value && context.Value.IsVisible.Value) { openGroup.Value = property.Path; } toggleProperty.ValueEntry.WeakSmartValue = isEnabled; // Why is this here? Commenting this out for now //toggleProperty.ValueEntry.ApplyChanges(); } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(InspectorProperty property, ToggleAttribute attribute, GUIContent label) { var toggleProperty = property.Children.Get(attribute.ToggleMemberName); if (toggleProperty == null) { AllEditorGUI.ErrorMessageBox(attribute.ToggleMemberName + " is not a member of " + property.Info.MemberInfo.GetNiceName() + "."); } else if (toggleProperty.ValueEntry.TypeOfValue != typeof(bool)) { AllEditorGUI.ErrorMessageBox(attribute.ToggleMemberName + " on " + property.Info.MemberInfo.GetNiceName() + " must be a boolean."); } else { bool isEnabled = (bool)toggleProperty.ValueEntry.WeakSmartValue; var isVisible = property.Context.GetPersistent(this, "isVisible", false); PropertyContext <string> openGroup = null; if (attribute.CollapseOthersOnExpand) { if (property.Parent == null) { //openGroup = GUIHelper.GetTemporaryContext<PropertyContext<string>>(property.Tree); openGroup = property.Context.Get <string>(this, "OpenGroup", (string)null); } else { var parent = (property.Parent.ValueEntry == null || property.Parent.ValueEntry.ValueCategory == PropertyValueCategory.Member) ? property.Parent : property.Parent.Parent; openGroup = parent.Context.GetGlobal <string>("OpenFoldoutToggleGroup", (string)null); } if (openGroup.Value != null && openGroup.Value != property.Path) { isVisible.Value = false; } } bool prev = isVisible.Value; bool visibleBuffer = isVisible.Value; if (AllEditorGUI.BeginToggleGroup(UniqueDrawerKey.Create(property, this), ref isEnabled, ref visibleBuffer, label != null ? label.text : property.Info.MemberInfo.GetNiceName())) { for (int i = 0; i < property.Children.Count; i++) { var child = property.Children[i]; if (child != toggleProperty) { InspectorUtilities.DrawProperty(child); } } } AllEditorGUI.EndToggleGroup(); isVisible.Value = visibleBuffer; if (openGroup != null && prev != isVisible.Value && isVisible.Value) { openGroup.Value = property.Path; } toggleProperty.ValueEntry.WeakSmartValue = isEnabled; } }
private void InvokeButton() { GUIHelper.RemoveFocusControl(); GUIHelper.RequestRepaint(); foreach (var target in this.Property.SerializationRoot.ValueEntry.WeakValues.OfType <UnityEngine.Object>()) { InspectorUtilities.RegisterUnityObjectDirty(target); Undo.RecordObject(target, "Button click " + this.Property.NiceName + " on " + target.name); } var serializationRoot = this.Property.SerializationRoot; for (int j = 0; j < serializationRoot.ValueEntry.ValueCount; j++) { UnityEngine.Object unityObj = serializationRoot.ValueEntry.WeakValues[j] as UnityEngine.Object; if (unityObj != null) { } } var methodInfo = (MethodInfo)this.Property.Info.GetMemberInfo(); if (methodInfo != null) { var parentValueProperty = this.Property.ParentValueProperty; var targets = this.Property.ParentValues; for (int i = 0; i < targets.Count; i++) { object value = targets[i]; if (object.ReferenceEquals(value, null) == false || methodInfo.IsStatic) { try { var arguments = new object[this.Property.Children.Count]; for (int j = 0; j < arguments.Length; j++) { arguments[j] = this.Property.Children[j].ValueEntry.WeakSmartValue; } if (methodInfo.IsStatic) { methodInfo.Invoke(null, arguments); } else { methodInfo.Invoke(value, arguments); } for (int j = 0; j < arguments.Length; j++) { this.Property.Children[j].ValueEntry.WeakSmartValue = arguments[j]; } } catch (ExitGUIException ex) { throw ex; } catch (Exception ex) { Debug.LogException(ex); } if (parentValueProperty != null && value.GetType().IsValueType) { // If it's a struct, it will have been boxed and the invoke call might // have changed the struct and this won't be reflected in the original, // unboxed source struct. // Therefore, set the source value to the boxed struct that we just invoked on. parentValueProperty.ValueEntry.WeakValues[i] = value; } } } } else { try { var arguments = new object[this.Property.Children.Count]; for (int j = 0; j < arguments.Length; j++) { arguments[j] = this.Property.Children[j].ValueEntry.WeakSmartValue; } this.Property.Info.GetMethodDelegate().DynamicInvoke(arguments); } catch (ExitGUIException ex) { throw ex; } catch (Exception ex) { Debug.LogException(ex); } } }