Example #1
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <GUIStyleState> entry, GUIContent label)
        {
            var property = entry.Property;

            var isVisible = property.Context.Get(this, "isVisible", AllEditorGUI.ExpandFoldoutByDefault);

            isVisible.Value = AllEditorGUI.Foldout(isVisible.Value, label ?? GUIContent.none);

            if (AllEditorGUI.BeginFadeGroup(isVisible, isVisible.Value))
            {
                EditorGUI.indentLevel++;
                entry.SmartValue.background = (Texture2D)SirenixEditorFields.UnityObjectField(label, entry.SmartValue.background, typeof(Texture2D), true);
                entry.SmartValue.textColor  = EditorGUILayout.ColorField(label ?? GUIContent.none, entry.SmartValue.textColor);
                EditorGUI.indentLevel--;
            }
            AllEditorGUI.EndFadeGroup();
        }
Example #2
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <byte> entry, PropertyRangeAttribute attribute, GUIContent label)
        {
            int value = label == null?
                        EditorGUILayout.IntSlider(entry.SmartValue, Math.Max(byte.MinValue, (int)attribute.Min), Math.Min(byte.MaxValue, (int)attribute.Max)) :
                            EditorGUILayout.IntSlider(label, entry.SmartValue, Math.Max(byte.MinValue, (int)attribute.Min), Math.Min(byte.MaxValue, (int)attribute.Max));

            if (value < byte.MinValue)
            {
                value = byte.MinValue;
            }
            else if (value > byte.MaxValue)
            {
                value = byte.MaxValue;
            }

            entry.SmartValue = (byte)value;
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <ushort> entry, RangeAttribute attribute, GUIContent label)
        {
            int value = label == null?
                        EditorGUILayout.IntSlider(entry.SmartValue, Math.Max(ushort.MinValue, (int)attribute.min), Math.Min(ushort.MaxValue, (int)attribute.max)) :
                            EditorGUILayout.IntSlider(label, entry.SmartValue, Math.Max(ushort.MinValue, (int)attribute.min), Math.Min(ushort.MaxValue, (int)attribute.max));

            if (value < ushort.MinValue)
            {
                value = ushort.MinValue;
            }
            else if (value > ushort.MaxValue)
            {
                value = ushort.MaxValue;
            }

            entry.SmartValue = (ushort)value;
        }
Example #4
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <double> entry, PropertyRangeAttribute attribute, GUIContent label)
        {
            double value = entry.SmartValue;

            if (value < float.MinValue)
            {
                value = float.MinValue;
            }
            else if (value > float.MaxValue)
            {
                value = float.MaxValue;
            }

            entry.SmartValue = label == null?
                               EditorGUILayout.Slider((float)value, (float)attribute.Min, (float)attribute.Max) :
                                   EditorGUILayout.Slider(label, (float)value, (float)attribute.Min, (float)attribute.Max);
        }
Example #5
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <byte> entry, DelayedPropertyAttribute attribute, GUIContent label)
        {
            int value = label == null?
                        EditorGUILayout.DelayedIntField(entry.SmartValue) :
                            EditorGUILayout.DelayedIntField(label, entry.SmartValue);

            if (value < byte.MinValue)
            {
                value = byte.MinValue;
            }
            else if (value > byte.MaxValue)
            {
                value = byte.MaxValue;
            }

            entry.SmartValue = (byte)value;
        }
Example #6
0
        protected override void DrawPropertyField(IPropertyValueEntry <Property> pEntry, GUIContent pContent)
        {
            if (pEntry.SmartValue == null || pEntry.SmartValue.info == null)
            {
                return;
            }
            var tInfo = pEntry.SmartValue.info;

            var tInfoDic = MemberHelper.GetDrawInfos(System.Reflection.MemberTypes.Property);

            if (tInfoDic == null)
            {
                return;
            }

            pEntry.SmartValue.entry   = pEntry;
            pEntry.SmartValue.content = pContent;

            var tIsDrawer = false;

            foreach (var tType in tInfo.PropertyType.GetParentTypes())
            {
                var tMemberTypeName = string.Empty;
                if (tType.IsGenericType && tType.GetGenericTypeDefinition() == typeof(IList <>))
                {
                    tMemberTypeName = typeof(IList <>).FullName;
                }
                else
                {
                    tMemberTypeName = tType.ToString();
                }

                if (tInfoDic.ContainsKey(tMemberTypeName) && tInfoDic[tMemberTypeName] != null)
                {
                    tIsDrawer = true;
                    tInfoDic[tMemberTypeName].LayoutDrawer(pEntry.SmartValue);
                    break;
                }
            }

            if (!tIsDrawer)
            {
                EditorGUILayout.LabelField(pEntry.SmartValue.NotImplementedDescription());
            }
        }
        private void DrawElement(Rect rect, IPropertyValueEntry <TArray> entry, Context context, int x, int y)
        {
            if (x < context.ColCount && y < context.RowCount)
            {
                bool showMixedValue = false;
                if (entry.Values.Count != 1)
                {
                    for (int i = 1; i < entry.Values.Count; i++)
                    {
                        var a = (entry.Values[i] as TElement[, ])[x, y];
                        var b = (entry.Values[i - 1] as TElement[, ])[x, y];

                        if (!CompareElement(a, b))
                        {
                            showMixedValue = true;
                            break;
                        }
                    }
                }

                EditorGUI.showMixedValue = showMixedValue;
                EditorGUI.BeginChangeCheck();
                var      prevValue = context.Value[x, y];
                TElement value;

                if (context.DrawElement != null)
                {
                    value = context.DrawElement(rect, prevValue);
                }
                else
                {
                    value = DrawElement(rect, prevValue);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    for (int i = 0; i < entry.Values.Count; i++)
                    {
                        (entry.Values[i] as TElement[, ])[x, y] = value;
                    }

                    entry.Values.ForceMarkDirty();
                }
            }
        }
Example #8
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <Vector4> entry, MinValueAttribute attribute, GUIContent label)
        {
            this.CallNextDrawer(entry, label);

            Vector4 v = entry.SmartValue;

            if (attribute.MinValue > v.x ||
                attribute.MinValue > v.y ||
                attribute.MinValue > v.z ||
                attribute.MinValue > v.w)
            {
                v.x = attribute.MinValue > v.x ? (float)attribute.MinValue : v.x;
                v.y = attribute.MinValue > v.y ? (float)attribute.MinValue : v.y;
                v.z = attribute.MinValue > v.z ? (float)attribute.MinValue : v.z;
                v.w = attribute.MinValue > v.w ? (float)attribute.MinValue : v.w;
                entry.SmartValue = v;
            }
        }
Example #9
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <LayerMask> entry, GUIContent label)
        {
            //EditorGUI.BeginChangeCheck();

            entry.SmartValue = SirenixEditorFields.LayerMaskField(label, entry.SmartValue);

            //return;
            //FieldInfo fieldInfo;
            //SerializedProperty unityProperty = entry.Property.Tree.GetUnityPropertyForPath(entry.Property.Path, out fieldInfo);

            //if (unityProperty == null)
            //{
            //    SirenixEditorGUI.ErrorMessageBox("Could not get a Unity SerializedProperty for the property '" + entry.Property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'.");
            //    return;
            //}

            //if (unityProperty.serializedObject.targetObject is EmittedScriptableObject<LayerMask>)
            //{
            //    var targetObjects = unityProperty.serializedObject.targetObjects;

            //    for (int i = 0; i < targetObjects.Length; i++)
            //    {
            //        EmittedScriptableObject<LayerMask> target = (EmittedScriptableObject<LayerMask>)targetObjects[i];
            //        target.SetValue(entry.Values[i]);
            //    }

            //    unityProperty.serializedObject.Update();
            //    unityProperty = unityProperty.serializedObject.FindProperty(unityProperty.propertyPath);
            //}

            //EditorGUILayout.PropertyField(unityProperty, true);

            //if (unityProperty.serializedObject.targetObject is EmittedScriptableObject<LayerMask>)
            //{
            //    unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo();
            //    var targetObjects = unityProperty.serializedObject.targetObjects;

            //    for (int i = 0; i < targetObjects.Length; i++)
            //    {
            //        EmittedScriptableObject<LayerMask> target = (EmittedScriptableObject<LayerMask>)targetObjects[i];
            //        entry.Values[i] = target.GetValue();
            //    }
            //}
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label)
        {
            FieldInfo          fieldInfo;
            SerializedProperty unityProperty = entry.Property.Tree.GetUnityPropertyForPath(entry.Property.Path, out fieldInfo);

            if (unityProperty == null)
            {
                SirenixEditorGUI.ErrorMessageBox("Could not get a Unity SerializedProperty for the property '" + entry.Property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'.");
                return;
            }

            if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <T> )
            {
                var targetObjects = unityProperty.serializedObject.targetObjects;

                for (int i = 0; i < targetObjects.Length; i++)
                {
                    EmittedScriptableObject <T> target = (EmittedScriptableObject <T>)targetObjects[i];
                    target.SetValue(entry.Values[i]);
                }

                unityProperty.serializedObject.Update();
                unityProperty = unityProperty.serializedObject.FindProperty(unityProperty.propertyPath);
            }

            if (label == null)
            {
                label = GUIHelper.TempContent("");
            }

            EditorGUILayout.PropertyField(unityProperty, label, true);

            if (unityProperty.serializedObject.targetObject is EmittedScriptableObject <T> )
            {
                unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo();
                var targetObjects = unityProperty.serializedObject.targetObjects;

                for (int i = 0; i < targetObjects.Length; i++)
                {
                    EmittedScriptableObject <T> target = (EmittedScriptableObject <T>)targetObjects[i];
                    entry.Values[i] = target.GetValue();
                }
            }
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <ColorPalette> entry, GUIContent label)
        {
            var isEditing = entry.Property.Context.Get(this, "isEditing", false);

            entry.SmartValue.Name = entry.SmartValue.Name ?? "Palette Name";

            SirenixEditorGUI.BeginBox();
            {
                SirenixEditorGUI.BeginBoxHeader();
                {
                    GUILayout.Label(entry.SmartValue.Name);
                    GUILayout.FlexibleSpace();
                    if (SirenixEditorGUI.IconButton(EditorIcons.Pen))
                    {
                        isEditing.Value = !isEditing.Value;
                    }
                }
                SirenixEditorGUI.EndBoxHeader();

                if (entry.SmartValue.Colors == null)
                {
                    entry.SmartValue.Colors = new List <Color>();
                }

                if (SirenixEditorGUI.BeginFadeGroup(entry.SmartValue, entry, isEditing.Value))
                {
                    this.CallNextDrawer(entry.Property, null);
                }
                SirenixEditorGUI.EndFadeGroup();

                if (SirenixEditorGUI.BeginFadeGroup(entry.SmartValue, entry.SmartValue, isEditing.Value == false))
                {
                    Color col = default(Color);

                    var stretch = ColorPaletteManager.Instance.StretchPalette;
                    var size    = ColorPaletteManager.Instance.SwatchSize;
                    var margin  = ColorPaletteManager.Instance.SwatchSpacing;
                    ColorPaletteAttributeDrawer.DrawColorPaletteColorPicker(entry, entry.SmartValue, ref col, entry.SmartValue.ShowAlpha, stretch, size, 20, margin);
                }
                SirenixEditorGUI.EndFadeGroup();
            }
            SirenixEditorGUI.EndBox();
        }
Example #12
0
        /// <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))
                {
                    var  isInReference = targetProp.Context.GetGlobal("is_in_reference", false);
                    bool previous      = isInReference.Value;
                    isInReference.Value = true;
                    InspectorUtilities.DrawProperty(targetProp);
                    isInReference.Value = previous;
                }
                SirenixEditorGUI.EndFadeGroup();
                SirenixEditorGUI.EndBox();
            }
            else
            {
                this.CallNextDrawer(entry.Property, label);
            }
        }
Example #13
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <long> entry, PropertyRangeAttribute attribute, GUIContent label)
        {
            long uValue = entry.SmartValue;

            if (uValue < int.MinValue)
            {
                uValue = int.MinValue;
            }
            else if (uValue > int.MaxValue)
            {
                uValue = int.MaxValue;
            }

            int value = label == null?
                        EditorGUILayout.IntSlider((int)uValue, (int)attribute.Min, (int)attribute.Max) :
                            EditorGUILayout.IntSlider(label, (int)uValue, (int)attribute.Min, (int)attribute.Max);

            entry.SmartValue = value;
        }
Example #14
0
        private void DrawValues(IPropertyValueEntry <Rect> entry)
        {
            var value = entry.SmartValue;

            // Position
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUI.BeginChangeCheck();
                value.position = SirenixEditorFields.VectorPrefixLabel("Position", value.position);
                if (EditorGUI.EndChangeCheck())
                {
                    entry.SmartValue = value;
                }

                GUIHelper.PushIndentLevel(0);
                GUIHelper.PushLabelWidth(SirenixEditorFields.SingleLetterStructLabelWidth);
                entry.Property.Children[0].Draw(GUIHelper.TempContent("X"));
                entry.Property.Children[1].Draw(GUIHelper.TempContent("Y"));
                GUIHelper.PopLabelWidth();
                GUIHelper.PopIndentLevel();
            }
            EditorGUILayout.EndHorizontal();

            // Size
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUI.BeginChangeCheck();
                value.size = SirenixEditorFields.VectorPrefixLabel("Size", value.size);
                if (EditorGUI.EndChangeCheck())
                {
                    entry.SmartValue = value;
                }

                GUIHelper.PushIndentLevel(0);
                GUIHelper.PushLabelWidth(SirenixEditorFields.SingleLetterStructLabelWidth);
                entry.Property.Children[2].Draw(GUIHelper.TempContent("X"));
                entry.Property.Children[3].Draw(GUIHelper.TempContent("Y"));
                GUIHelper.PopLabelWidth();
                GUIHelper.PopIndentLevel();
            }
            EditorGUILayout.EndHorizontal();
        }
        private static void DrawObjectField(IPropertyValueEntry <T> entry, GUIContent label, ref bool isToggled, bool showToggle = true)
        {
            var prev = EditorGUI.showMixedValue;

            if (entry.ValueState == PropertyValueState.ReferenceValueConflict)
            {
                EditorGUI.showMixedValue = true;
            }

            object newValue;

            GUI.changed = false;
            if (showToggle == false)
            {
#pragma warning disable 0618 // Type or member is obsolete
                newValue = SirenixEditorGUI.ObjectField(entry, entry.BaseValueType, label, entry.SmartValue, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null);
#pragma warning restore 0618 // Type or member is obsolete
            }
            else if (label == null)
            {
                EditorGUI.indentLevel++;
#pragma warning disable 0618 // Type or member is obsolete
                newValue = SirenixEditorGUI.ObjectField(entry, entry.BaseValueType, label, entry.SmartValue, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null);
#pragma warning restore 0618 // Type or member is obsolete
                EditorGUI.indentLevel--;
            }
            else
            {
                newValue = SirenixEditorFields.PolymorphicObjectField(GUIHelper.TempContent("   " + label.text, label.tooltip), entry.SmartValue, entry.BaseValueType, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null);
            }
            if (GUI.changed)
            {
                //entry.WeakSmartValue = newValue;
                entry.Property.Tree.DelayActionUntilRepaint(() => entry.WeakSmartValue = newValue);
            }
            if (showToggle)
            {
                isToggled = SirenixEditorGUI.Foldout(GUILayoutUtility.GetLastRect(), isToggled, GUIContent.none);
            }

            EditorGUI.showMixedValue = prev;
        }
        /// <summary>
        /// Draws the property in the Rect provided. This method does not support the GUILayout, and is only called by DrawPropertyImplementation if the GUICallType is set to Rect, which is not the default.
        /// If the GUICallType is set to Rect, both GetRectHeight and DrawPropertyRect needs to be implemented.
        /// If the GUICallType is set to GUILayout, implementing DrawPropertyLayout will suffice.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="entry">The value entry.</param>
        /// <param name="attribute">The attribute.</param>
        /// <param name="label">The label. This can be null, so make sure your drawer supports that.</param>
        protected override void DrawPropertyRect(Rect position, IPropertyValueEntry <string> entry, TextAreaAttribute attribute, GUIContent label)
        {
            if (EditorGUI_ScrollableTextAreaInternal == null)
            {
                EditorGUI.LabelField(position, label, GUIHelper.TempContent("Cannot draw TextArea because Unity's internal API has changed."));
                return;
            }

            var scrollPosition = entry.Context.Get(this, "scroll_position", Vector2.zero);

            if (label != null)
            {
                Rect labelPosition = position;
                labelPosition.height = 16f;
                position.yMin       += labelPosition.height;
                EditorGUI.HandlePrefixLabel(position, labelPosition, label);
            }

            entry.SmartValue = EditorGUI_ScrollableTextAreaInternal(position, entry.SmartValue, ref scrollPosition.Value, EditorStyles.textArea);
        }
Example #17
0
        void IDefinesGenericMenuItems.PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu)
        {
            var content = new GUIContent("Set to null");
            IPropertyValueEntry <T?> entry = (IPropertyValueEntry <T?>)property.ValueEntry;

            if (entry.SmartValue.HasValue)
            {
                genericMenu.AddItem(content, false, () =>
                {
                    property.Tree.DelayActionUntilRepaint(() =>
                    {
                        entry.SmartValue = null;
                    });
                });
            }
            else
            {
                genericMenu.AddDisabledItem(content);
            }
        }
Example #18
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <ulong> entry, PropertyRangeAttribute attribute, GUIContent label)
        {
            ulong uValue = entry.SmartValue;

            if (uValue > int.MaxValue)
            {
                uValue = int.MaxValue;
            }

            int value = label == null?
                        EditorGUILayout.IntSlider((int)uValue, Math.Max(0, (int)attribute.Min), (int)attribute.Max) :
                            EditorGUILayout.IntSlider(label, (int)uValue, Math.Max(0, (int)attribute.Min), (int)attribute.Max);

            if (value < 0)
            {
                value = 0;
            }

            entry.SmartValue = (ulong)value;
        }
Example #19
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <Rect> entry, GUIContent label)
        {
            if (label == null)
            {
                this.DrawValues(entry);
            }
            else
            {
                var isVisible = entry.Property.Context.GetPersistent <bool>(this, "IsVisible", GeneralDrawerConfig.Instance.ExpandFoldoutByDefault);

                isVisible.Value = AllEditorGUI.Foldout(isVisible.Value, label);
                if (AllEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry, this), isVisible.Value))
                {
                    EditorGUI.indentLevel++;
                    this.DrawValues(entry);
                    EditorGUI.indentLevel--;
                }
                AllEditorGUI.EndFadeGroup();
            }
        }
Example #20
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <Vector3> entry, GUIContent label)
        {
            if (label == null)
            {
                AllEditorGUI.BeginIndentedHorizontal(EditorGUI.indentLevel == 0 ? GUIStyle.none : SirenixGUIStyles.PropertyMargin);
            }
            else
            {
                GUILayout.BeginHorizontal();
            }

            if (label != null)
            {
                EditorGUI.BeginChangeCheck();
                var value = SirenixEditorFields.VectorPrefixLabel(label, entry.SmartValue);
                if (EditorGUI.EndChangeCheck())
                {
                    entry.SmartValue = value;
                }
            }

            var  r          = GUIHelper.GetCurrentLayoutRect();
            bool showLabels = !(SirenixEditorFields.ResponsiveVectorComponentFields && (label != null ? r.width - EditorGUIUtility.labelWidth : r.width) < 185);

            GUIHelper.PushLabelWidth(SirenixEditorFields.SingleLetterStructLabelWidth);
            GUIHelper.PushIndentLevel(0);
            entry.Property.Children[0].Draw(showLabels ? GUIHelper.TempContent("X") : null);
            entry.Property.Children[1].Draw(showLabels ? GUIHelper.TempContent("Y") : null);
            entry.Property.Children[2].Draw(showLabels ? GUIHelper.TempContent("Z") : null);
            GUIHelper.PopIndentLevel();
            GUIHelper.PopLabelWidth();

            if (label == null)
            {
                AllEditorGUI.EndIndentedHorizontal();
            }
            else
            {
                GUILayout.EndHorizontal();
            }
        }
Example #21
0
        private static bool CheckKeyIsValid(IPropertyValueEntry <TDictionary> entry, TKey key, out string errorMessage)
        {
            if (!KeyIsValueType && object.ReferenceEquals(key, null))
            {
                errorMessage = "Key cannot be null.";
                return(false);
            }

            var keyStr = DictionaryKeyUtility.GetDictionaryKeyString(key);

            if (entry.Property.Children[keyStr] == null)
            {
                errorMessage = "";
                return(true);
            }
            else
            {
                errorMessage = "An item with the same key already exists.";
                return(false);
            }
        }
 /// <summary>
 /// Draws the property.
 /// </summary>
 protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label)
 {
     if (entry.ValueState == PropertyValueState.ReferencePathConflict)
     {
         if (IsUnityObject)
         {
             bool prev = EditorGUI.showMixedValue;
             EditorGUI.showMixedValue = true;
             this.CallNextDrawer(entry, label);
             EditorGUI.showMixedValue = prev;
         }
         else
         {
             EditorGUILayout.LabelField(label, new GUIContent("Reference path conflict... (right-click to resolve)"));
         }
     }
     else
     {
         this.CallNextDrawer(entry.Property, label);
     }
 }
Example #23
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <T?> entry, GUIContent label)
        {
            var context = entry.Property.Context.Get(this, "context", (PropertyTree <Wrapper>)null);

            if (context.Value == null)
            {
                Wrapper[] wrappers = new Wrapper[entry.ValueCount];

                for (int i = 0; i < wrappers.Length; i++)
                {
                    var wrapper = new Wrapper();
                    wrappers[i] = wrapper;
                }

                context.Value = new PropertyTree <Wrapper>(wrappers);
                context.Value.UpdateTree();
            }

            for (int i = 0; i < context.Value.Targets.Count; i++)
            {
                context.Value.Targets[i].SetValue(entry.Values[i]);
            }

            context.Value.GetRootProperty(0).Label = label;
            context.Value.Draw(false);

            for (int i = 0; i < context.Value.Targets.Count; i++)
            {
                var value = context.Value.Targets[i];

                if (value.Value == null)
                {
                    entry.Values[i] = null;
                }
                else
                {
                    entry.Values[i] = value.Value.Value;
                }
            }
        }
        /// <summary>
        /// Draws the actual property. This method is called by this.DrawProperty(...)
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="label">The label. This can be null, so make sure your drawer supports that.</param>
        /// <exception cref="System.ArgumentNullException">property</exception>
        /// <exception cref="System.ArgumentException">The given property to draw at path '" + property.Path + "' does not have a value of required type " + typeof(IPropertyValueEntry).GetNiceName() + ".</exception>
        protected sealed override void DrawPropertyImplementation(InspectorProperty property, GUIContent label)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            IPropertyValueEntry <T> castEntry = property.ValueEntry as IPropertyValueEntry <T>;

            if (castEntry == null)
            {
                property.Update();
                castEntry = property.ValueEntry as IPropertyValueEntry <T>;
            }

            if (castEntry == null)
            {
                throw new ArgumentException("The given property to draw at path '" + property.Path + "' does not have a value of required type " + typeof(IPropertyValueEntry <T>).GetNiceName() + ".");
            }

            this.DrawProperty(castEntry, label);
        }
Example #25
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label)
        {
            PropertyContext <DrawerPropertyHandlerBuffer> buffer;

            if (entry.Context.Get(this, "DrawerPropertyHandlerBuffer", out buffer))
            {
                buffer.Value = new DrawerPropertyHandlerBuffer
                {
                    Drawer = new UnityEditorInternal.UnityEventDrawer()
                };

                if (UnityPropertyHandlerUtility.IsAvailable)
                {
                    buffer.Value.PropertyHandler = UnityPropertyHandlerUtility.CreatePropertyHandler(buffer.Value.Drawer);
                }
            }

            this.drawer          = buffer.Value.Drawer;
            this.propertyHandler = buffer.Value.PropertyHandler;

            FieldInfo          fieldInfo;
            SerializedProperty unityProperty = entry.Property.Tree.GetUnityPropertyForPath(entry.Property.Path, out fieldInfo);

            if (unityProperty == null)
            {
                if (UnityVersion.IsVersionOrGreater(2017, 1))
                {
                    this.CallNextDrawer(entry, label);
                    return;
                }
                else if (!typeof(T).IsDefined <SerializableAttribute>())
                {
                    SirenixEditorGUI.ErrorMessageBox("You have likely forgotten to mark your custom UnityEvent class '" + typeof(T).GetNiceName() + "' with the [Serializable] attribute! Could not get a Unity SerializedProperty for the property '" + entry.Property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'.");
                    return;
                }
            }

            base.DrawPropertyLayout(entry, label);
        }
        private void DrawProperty(IPropertyValueEntry <T> entry, GUIContent label)
        {
            switch (this.GUICallType)
            {
            case GUICallType.GUILayout:
            {
                this.DrawPropertyLayout(entry, label);
            }
            break;

            case GUICallType.Rect:
            {
                float height   = this.GetRectHeight(entry, label);
                Rect  position = EditorGUILayout.GetControlRect(false, height);
                this.DrawPropertyRect(position, entry, label);
            }
            break;

            default:
                throw new NotImplementedException(this.GUICallType.ToString() + " has not been implemented.");
            }
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected sealed override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label)
        {
            bool conflict   = false;
            int  childCount = entry.Property.Children.Count;

            for (int i = 0; i < childCount; i++)
            {
                var child = entry.Property.Children[i];

                if (child.ValueEntry != null && child.ValueEntry.ValueState == PropertyValueState.PrimitiveValueConflict)
                {
                    conflict = true;
                    break;
                }
            }

            if (conflict)
            {
                EditorGUI.showMixedValue = true;
                GUI.changed = false;
            }

            this.DrawPropertyField(entry, label);

            if (conflict)
            {
                EditorGUI.showMixedValue = false;

                if (GUI.changed)
                {
                    var value = entry.SmartValue;

                    for (int i = 0; i < entry.ValueCount; i++)
                    {
                        entry.Values[i] = value;
                    }
                }
            }
        }
Example #28
0
            protected override void DrawPropertyLayout(IPropertyValueEntry <ToggleableAsset> entry, GUIContent label)
            {
                if (entry.SmartValue.AutoToggle)
                {
#pragma warning disable 0618 // Type or member is obsolete
                    AllEditorGUI.ObjectField(null, entry.SmartValue.Object, entry.SmartValue.Object.GetType(), false, true);
#pragma warning restore 0618 // Type or member is obsolete
                }
                else
                {
                    var rect            = GUILayoutUtility.GetRect(16, 16, GUILayoutOptions.ExpandWidth(true));
                    var toggleRect      = new Rect(rect.x, rect.y, 16, 16);
                    var objectFieldRect = new Rect(rect.x + 20, rect.y, rect.width - 20, 16);

                    if (Event.current.type != EventType.Repaint)
                    {
                        toggleRect.x      -= 5;
                        toggleRect.y      -= 5;
                        toggleRect.width  += 10;
                        toggleRect.height += 10;
                    }
                    var prevChanged = GUI.changed;

                    entry.SmartValue.Toggled = GUI.Toggle(toggleRect, entry.SmartValue.Toggled, "");

                    if (prevChanged != GUI.changed)
                    {
                        entry.ApplyChanges();
                    }

                    GUIHelper.PushGUIEnabled(entry.SmartValue.Toggled);

#pragma warning disable 0618 // Type or member is obsolete
                    AllEditorGUI.ObjectField(objectFieldRect, null, entry.SmartValue.Object, entry.SmartValue.Object.GetType(), false, true);
#pragma warning restore 0618 // Type or member is obsolete

                    GUIHelper.PopGUIEnabled();
                }
            }
Example #29
0
        private void Popup(IPropertyValueEntry <T> entry, Rect rect, UnityEngine.Object target)
        {
            Type returnType = InvokeMethod.ReturnType;

            Type[]      parameters = InvokeMethod.GetParameters().Select(n => n.ParameterType).ToArray();
            GenericMenu menu       = new GenericMenu();

            if (target == null)
            {
                menu.AddDisabledItem(new GUIContent("No target selected"));
            }
            else
            {
                var targetGameObject = target as GameObject;
                var targetComponent  = target as Component;

                if (targetGameObject == null && targetComponent != null)
                {
                    targetGameObject = targetComponent.gameObject;
                }

                if (targetGameObject != null)
                {
                    RegisterGameObject(menu, entry, "", targetGameObject, returnType, parameters);
                }
                else
                {
                    RegisterUnityObject(menu, entry, "", target, returnType, parameters);
                }

                if (menu.GetItemCount() == 0)
                {
                    menu.AddDisabledItem(new GUIContent("No suitable method found on target"));
                }
            }

            menu.DropDown(rect);
        }
        /// <summary>
        /// Not yet documented.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <string> entry, FolderPathAttribute attribute, GUIContent label)
        {
            // Create a property context for the parent path.
            InspectorProperty parentProperty = entry.Property.FindParent(PropertyValueCategory.Member, true);
            PropertyContext <FolderPathContext> context;

            if (entry.Context.Get <FolderPathContext>(this, "FolderPath", out context))
            {
                context.Value = new FolderPathContext()
                {
                    ParentPath = new StringMemberHelper(parentProperty.ParentType, attribute.ParentFolder),
                };

                context.Value.Exists = PathExists(entry.SmartValue, context.Value.ParentPath.GetString(entry));
            }

            // Display evt. errors in creating context.
            if (context.Value.ParentPath.ErrorMessage != null)
            {
                SirenixEditorGUI.ErrorMessageBox(context.Value.ParentPath.ErrorMessage);
            }

            // Display required valid path error if enabled.
            if (attribute.RequireValidPath && context.Value.Exists == false)
            {
                SirenixEditorGUI.ErrorMessageBox("The path is invalid.");
            }

            // Draw field.
            EditorGUI.BeginChangeCheck();
            entry.SmartValue = SirenixEditorFields.FolderPathField(label, entry.SmartValue, context.Value.ParentPath.GetString(entry), attribute.AbsolutePath, attribute.UseBackslashes);

            // Update existing check
            if (EditorGUI.EndChangeCheck() && attribute.RequireValidPath)
            {
                context.Value.Exists = PathExists(entry.SmartValue, context.Value.ParentPath.GetString(entry));
            }
        }