Example #1
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(InspectorProperty property, TableListAttribute attribute, GUIContent label)
        {
            var context = property.Context.Get(this, "Context", (Context)null);

            if (context.Value == null)
            {
                context.Value             = new Context();
                context.Value.ListChanger = property.ValueEntry.GetListValueEntryChanger();
                context.Value.Paging      = new GUIPagingHelper();
                context.Value.Paging.NumberOfItemsPerPage = attribute.NumberOfItemsPerPage == 0 ? GeneralDrawerConfig.Instance.NumberOfItemsPrPage : attribute.NumberOfItemsPerPage;

                property.Context.GetPersistent(this, "DrawList", out context.Value.DrawList);
            }

            context.Value.ObjectPicker = ObjectPicker.GetObjectPicker(UniqueDrawerKey.Create(property, this), context.Value.ListChanger.ElementType);
            context.Value.UpdateTable(property, attribute, label == null ? string.Empty : label.text); // @todo @fix passing null to update table for label causes OutOfRangeExceptions to be thrown.

            if (context.Value.DrawList.Value)
            {
                if (GUILayout.Button("Show table"))
                {
                    context.Value.SwitchView = true;
                }

                this.CallNextDrawer(property, label);
            }
            else
            {
                if (context.Value.Table != null)
                {
                    if (context.Value.WasUpdated && Event.current.type == EventType.Repaint)
                    {
                        // Everything is messed up the first frame. Lets not show that.
                        GUIHelper.PushColor(new Color(0, 0, 0, 0));
                    }

                    context.Value.Table.DrawTable();

                    if (context.Value.WasUpdated && Event.current.type == EventType.Repaint)
                    {
                        context.Value.WasUpdated = false;
                        GUIHelper.PopColor();
                    }
                }

                if (context.Value.ObjectPicker.IsReadyToClaim && Event.current.type == EventType.Repaint)
                {
                    var      value  = context.Value.ObjectPicker.ClaimObject();
                    object[] values = new object[context.Value.ListChanger.ValueCount];
                    values[0] = value;
                    for (int j = 1; j < values.Length; j++)
                    {
                        values[j] = SerializationUtility.CreateCopy(value);
                    }
                    context.Value.ListChanger.AddListElement(values, CHANGE_ID);
                }
            }

            GUILayout.Space(3);
        }
Example #2
0
        public NodeModelBase Clone()
        {
            // Doing a shallow copy
            var clone = (NodeModelBase)SerializationUtility.CreateCopy(this);

            // Exposed references are not copied in serialization as they are external Unity references so they will refer to the same exposed reference instance not just the unity object reference, we need to copy them additionally
            FieldInfo[] fields = clone.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
            fields.ToList().FindAll(f => f.FieldType.IsGenericType && f.FieldType.GetGenericTypeDefinition() == typeof(ExposedReference <>)).ForEach(f =>
            {
                Type exposedRefType = typeof(ExposedReference <>).MakeGenericType(f.FieldType.GenericTypeArguments[0]);

                if (DashEditorCore.EditorConfig.editingController != null)
                {
                    IExposedPropertyTable propertyTable = DashEditorCore.EditorConfig.editingController;
                    var curExposedRef = f.GetValue(clone);
                    UnityEngine.Object exposedValue = (UnityEngine.Object)curExposedRef.GetType().GetMethod("Resolve")
                                                      .Invoke(curExposedRef, new object[] { propertyTable });

                    var clonedExposedRef        = Activator.CreateInstance(exposedRefType);
                    PropertyName newExposedName = new PropertyName(UnityEditor.GUID.Generate().ToString());
                    propertyTable.SetReferenceValue(newExposedName, exposedValue);
                    clonedExposedRef.GetType().GetField("exposedName")
                    .SetValue(clonedExposedRef, newExposedName);
                    f.SetValue(clone, clonedExposedRef);
                }
            });

            return(clone);
        }
Example #3
0
        private void DrawInlinePropertyReferencePicker()
        {
            EditorGUI.BeginChangeCheck();
            var prev = EditorGUI.showMixedValue;

            if (this.ValueEntry.ValueState == PropertyValueState.ReferenceValueConflict)
            {
                EditorGUI.showMixedValue = true;
            }
            var newValue = SirenixEditorFields.PolymorphicObjectField(this.ValueEntry.WeakSmartValue, this.ValueEntry.BaseValueType, this.allowSceneObjects);

            EditorGUI.showMixedValue = prev;

            if (EditorGUI.EndChangeCheck())
            {
                this.ValueEntry.Property.Tree.DelayActionUntilRepaint(() =>
                {
                    this.ValueEntry.WeakValues[0] = newValue;
                    for (int j = 1; j < this.ValueEntry.ValueCount; j++)
                    {
                        this.ValueEntry.WeakValues[j] = SerializationUtility.CreateCopy(newValue);
                    }
                });
            }
        }
Example #4
0
        private void AddResult(IEnumerable <object> query)
        {
            if (this.isList)
            {
                var changer = this.Property.ChildResolver as IOrderedCollectionResolver;

                if (this.enableMultiSelect)
                {
                    changer.QueueClear();
                }

                foreach (var item in query)
                {
                    object[] arr = new object[this.Property.ParentValues.Count];

                    for (int i = 0; i < arr.Length; i++)
                    {
                        arr[i] = SerializationUtility.CreateCopy(item);
                    }

                    changer.QueueAdd(arr);
                }
            }
            else
            {
                var first = query.FirstOrDefault();
                for (int i = 0; i < this.Property.ValueEntry.WeakValues.Count; i++)
                {
                    this.Property.ValueEntry.WeakValues[i] = SerializationUtility.CreateCopy(first);
                }
            }
        }
Example #5
0
    protected override void OnEnable()
    {
        base.OnEnable();
        ExecutedEvents = new List <object>();

        TreeIteration.OnDecisionTreeIterated = (TreeIterationResult p_choices) =>
        {
            ExecutedEvents.Add(
                new AIDecisionTreeEntry()
            {
                ExecutionTime = DateTime.Now.ToString("hh:mm:ss.fff tt"),
                ExecutedEvent = SerializationUtility.CreateCopy(p_choices)
            }
                );
        };

        /*
         * _AI._DecisionTree._Algorithm.Algorithm.OnAIDecisionTreeTraversed = (AIdecisionTreeTraversalResponse p_choices) =>
         * {
         *  ExecutedEvents.Add(
         *      new AIDecisionTreeEntry()
         *      {
         *          ExecutionTime = DateTime.Now.ToString("hh:mm:ss.fff tt"),
         *          ExecutedEvent = SerializationUtility.CreateCopy(p_choices)
         *      }
         *  );
         * };.*/
    }
Example #6
0
    private List <GameObject> FindAllSpriteShapesInScene()
    {
        GameObject[] spriteShapesInScene = GameObject.FindGameObjectsWithTag("SpriteShape");

        List <GameObject> output = new List <GameObject>();

        foreach (GameObject spriteShape in spriteShapesInScene)
        {
            output.Add(SerializationUtility.CreateCopy(spriteShape) as GameObject);
        }

        return(output);
    }
 private void HandleObjectPickerEvents()
 {
     if (this.picker.IsReadyToClaim && Event.current.type == EventType.Repaint)
     {
         var      value  = this.picker.ClaimObject();
         object[] values = new object[this.Property.Tree.WeakTargets.Count];
         values[0] = value;
         for (int j = 1; j < values.Length; j++)
         {
             values[j] = SerializationUtility.CreateCopy(value);
         }
         this.resolver.QueueAdd(values);
     }
 }
Example #8
0
    /*
     * private IEnumerable<Type> GetAllTypes()
     * {
     *  List<Type> l_types = new List<Type>();
     *  if(ExecutedEvents != null)
     *  {
     *      for(int i = 0; i < ExecutedEvents.Count; i++)
     *      {
     *          EventEntry l_eventEntry = (EventEntry) ExecutedEvents[i];
     *          if (!l_types.Contains(l_eventEntry.ExecutedEvent.GetType()))
     *          {
     *              l_types.Add(l_eventEntry.ExecutedEvent.GetType());
     *          }
     *      }
     *  }
     *  return l_types;
     * }
     */

    protected override void OnEnable()
    {
        base.OnEnable();
        ExecutedEvents = new List <object>();


        EventQueue.OnEventExecuted = (AEvent p_event) =>
        {
            EventEntry l_eventEntry = new EventEntry()
            {
                ExecutionTime = DateTime.Now.ToString("hh:mm:ss.fff tt"),
                ExecutedEvent = (AEvent)SerializationUtility.CreateCopy(p_event)
            };
            ExecutedEvents.Add(l_eventEntry);
        };
    }
Example #9
0
        /// <summary> Generates and returns a deep copy of class member value. </summary>
        /// <param name="subject"> Subject to copy. </param>
        /// <returns> A deep copy of value. For null returns null. For UnityEngine.Objects, returns source as is. </returns>
        public static object Copy([CanBeNull] object subject)
        {
                        #if DONT_USE_ODIN_SERIALIZER
            if (subject == null)
            {
                return(null);
            }
            if (subject is Object)
            {
                return(subject);
            }

            using (var stream = new System.IO.MemoryStream())
            {
                var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                formatter.Serialize(stream, subject);
                stream.Position = 0;
                return(formatter.Deserialize(stream));
            }
                        #else
            return(SerializationUtility.CreateCopy(subject));
                        #endif
        }
        /// <summary>
        /// Provides a deep copy of the given object
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static object Clone(this object source)
        {
            return(SerializationUtility.CreateCopy(source));
            //// 1. Get the type of source object
            //Type sourceType = source.GetType();
            //object target = Activator.CreateInstance(sourceType);

            //// 2. Get all the properties of the source object type
            //PropertyInfo[] propertyInfo = sourceType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            //// 3. Assign all source property to target object properties
            //foreach (PropertyInfo property in propertyInfo)
            //{
            //  // Check whether the property can be written to
            //  if (property.CanWrite)
            //  {
            //    // Check whether the property type is value type, enum, or string type
            //    if (property.PropertyType.IsValueType || property.PropertyType.IsEnum || property.PropertyType.Equals(typeof(System.String)))
            //    {
            //      property.SetValue(target, property.GetValue(source, null), null);
            //    }
            //    // Else the property type is object/complex types so need to recursively call this method
            //    // until the end of the tree is reached
            //    else
            //    {
            //      object objPropertyValue = property.GetValue(source, null);
            //      if (objPropertyValue == null)
            //        property.SetValue(target, null, null);
            //      else
            //        property.SetValue(target, objPropertyValue.Clone(), null);
            //    }
            //  }
            //}

            //return target;
        }
 /// <summary>
 /// Provides a deep copy of the given object
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static T Clone <T>(this T source)
 {
     return((T)SerializationUtility.CreateCopy(source));
 }
Example #12
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var  resolver   = this.Property.ChildResolver as ICollectionResolver;
            bool isReadOnly = resolver.IsReadOnly;

            if (this.errorMessage != null)
            {
                SirenixEditorGUI.ErrorMessageBox(errorMessage);
            }

            if (info.Label == null || (label != null && label.text != info.Label.text))
            {
                info.Label = new GUIContent(label == null || string.IsNullOrEmpty(label.text) ? Property.ValueEntry.TypeOfValue.GetNiceName() : label.text, label == null ? string.Empty : label.tooltip);
            }

            info.IsReadOnly = resolver.IsReadOnly;

            info.ListItemStyle.padding.left  = info.Draggable ? 25 : 7;
            info.ListItemStyle.padding.right = info.IsReadOnly || info.HideRemoveButton ? 4 : 20;

            if (Event.current.type == EventType.Repaint)
            {
                info.DropZoneTopLeft = GUIUtility.GUIToScreenPoint(new Vector2(0, 0));
            }

            info.CollectionResolver        = Property.ChildResolver as ICollectionResolver;
            info.OrderedCollectionResolver = Property.ChildResolver as IOrderedCollectionResolver;
            info.Count   = Property.Children.Count;
            info.IsEmpty = Property.Children.Count == 0;

            SirenixEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding);
            this.BeginDropZone();
            {
                this.DrawToolbar();
                if (SirenixEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(Property, this), info.Toggled.Value))
                {
                    GUIHelper.PushLabelWidth(GUIHelper.BetterLabelWidth - info.ListItemStyle.padding.left);
                    this.DrawItems();
                    GUIHelper.PopLabelWidth();
                }
                SirenixEditorGUI.EndFadeGroup();
            }
            this.EndDropZone();
            SirenixEditorGUI.EndIndentedVertical();

            if (info.OrderedCollectionResolver != null)
            {
                if (info.RemoveAt >= 0 && Event.current.type == EventType.Repaint)
                {
                    try
                    {
                        if (info.CustomRemoveIndexFunction != null)
                        {
                            foreach (var parent in this.Property.ParentValues)
                            {
                                info.CustomRemoveIndexFunction(
                                    parent,
                                    info.RemoveAt);
                            }
                        }
                        else if (info.CustomRemoveElementFunction != null)
                        {
                            for (int i = 0; i < this.Property.ParentValues.Count; i++)
                            {
                                info.CustomRemoveElementFunction(
                                    this.Property.ParentValues[i],
                                    this.Property.Children[info.RemoveAt].ValueEntry.WeakValues[i]);
                            }
                        }
                        else
                        {
                            info.OrderedCollectionResolver.QueueRemoveAt(info.RemoveAt);
                        }
                    }
                    finally
                    {
                        info.RemoveAt = -1;
                    }

                    GUIHelper.RequestRepaint();
                }
            }
            else if (info.RemoveValues != null && Event.current.type == EventType.Repaint)
            {
                try
                {
                    if (info.CustomRemoveElementFunction != null)
                    {
                        for (int i = 0; i < this.Property.ParentValues.Count; i++)
                        {
                            info.CustomRemoveElementFunction(
                                this.Property.ParentValues[i],
                                this.info.RemoveValues[i]);
                        }
                    }
                    else
                    {
                        info.CollectionResolver.QueueRemove(info.RemoveValues);
                    }
                }
                finally
                {
                    info.RemoveValues = null;
                }
                GUIHelper.RequestRepaint();
            }

            if (info.ObjectPicker != null && info.ObjectPicker.IsReadyToClaim && Event.current.type == EventType.Repaint)
            {
                var value = info.ObjectPicker.ClaimObject();

                if (info.JumpToNextPageOnAdd)
                {
                    info.StartIndex = int.MaxValue;
                }

                object[] values = new object[info.Property.Tree.WeakTargets.Count];

                values[0] = value;
                for (int j = 1; j < values.Length; j++)
                {
                    values[j] = SerializationUtility.CreateCopy(value);
                }

                info.CollectionResolver.QueueAdd(values);
            }
        }
Example #13
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TList> entry, GUIContent label)
        {
            var property    = entry.Property;
            var infoContext = property.Context.Get(this, "Context", (ListDrawerConfigInfo)null);
            var info        = infoContext.Value;

            bool isReadOnly = false;

            if (entry.TypeOfValue.IsArray == false)
            {
                for (int i = 0; i < entry.ValueCount; i++)
                {
                    if ((entry.WeakValues[i] as IList <TElement>).IsReadOnly)
                    {
                        isReadOnly = true;
                        break;
                    }
                }
            }

            if (info == null)
            {
                var customListDrawerOptions = property.Info.GetAttribute <ListDrawerSettingsAttribute>() ?? new ListDrawerSettingsAttribute();
                isReadOnly = entry.IsEditable == false || isReadOnly || customListDrawerOptions.IsReadOnlyHasValue && customListDrawerOptions.IsReadOnly;

                info = infoContext.Value = new ListDrawerConfigInfo()
                {
                    StartIndex              = 0,
                    Toggled                 = entry.Context.GetPersistent <bool>(this, "ListDrawerToggled", customListDrawerOptions.ExpandedHasValue ? customListDrawerOptions.Expanded : GeneralDrawerConfig.Instance.OpenListsByDefault),
                    RemoveAt                = -1,
                    label                   = new GUIContent(label == null || string.IsNullOrEmpty(label.text) ? property.ValueEntry.TypeOfValue.GetNiceName() : label.text, label == null ? string.Empty : label.tooltip),
                    ShowAllWhilePageing     = false,
                    EndIndex                = 0,
                    CustomListDrawerOptions = customListDrawerOptions,
                    IsReadOnly              = isReadOnly,
                    Draggable               = !isReadOnly && (!customListDrawerOptions.IsReadOnlyHasValue)
                };

                info.listConfig = GeneralDrawerConfig.Instance;
                info.property   = property;

                if (customListDrawerOptions.DraggableHasValue && !customListDrawerOptions.DraggableItems)
                {
                    info.Draggable = false;
                }

                if (info.CustomListDrawerOptions.OnBeginListElementGUI != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .IsMethod()
                                            .IsNamed(info.CustomListDrawerOptions.OnBeginListElementGUI)
                                            .HasParameters <int>()
                                            .ReturnsVoid()
                                            .GetMember <MethodInfo>(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        info.OnBeginListElementGUI = EmitUtilities.CreateWeakInstanceMethodCaller <int>(memberInfo as MethodInfo);
                    }
                }

                if (info.CustomListDrawerOptions.OnEndListElementGUI != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .IsMethod()
                                            .IsNamed(info.CustomListDrawerOptions.OnEndListElementGUI)
                                            .HasParameters <int>()
                                            .ReturnsVoid()
                                            .GetMember <MethodInfo>(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        info.OnEndListElementGUI = EmitUtilities.CreateWeakInstanceMethodCaller <int>(memberInfo as MethodInfo);
                    }
                }

                if (info.CustomListDrawerOptions.OnTitleBarGUI != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .IsMethod()
                                            .IsNamed(info.CustomListDrawerOptions.OnTitleBarGUI)
                                            .HasNoParameters()
                                            .ReturnsVoid()
                                            .GetMember <MethodInfo>(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        info.OnTitleBarGUI = EmitUtilities.CreateWeakInstanceMethodCaller(memberInfo as MethodInfo);
                    }
                }

                if (info.CustomListDrawerOptions.ListElementLabelName != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = typeof(TElement)
                                            .FindMember()
                                            .HasNoParameters()
                                            .IsNamed(info.CustomListDrawerOptions.ListElementLabelName)
                                            .HasReturnType <object>(true)
                                            .GetMember(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        string methodSuffix = memberInfo as MethodInfo == null ? "" : "()";
                        info.GetListElementLabelText = DeepReflection.CreateWeakInstanceValueGetter(typeof(TElement), typeof(object), info.CustomListDrawerOptions.ListElementLabelName + methodSuffix);
                    }
                }
            }

            info.listConfig = GeneralDrawerConfig.Instance;
            info.property   = property;

            info.ListItemStyle.padding.left  = info.Draggable ? 25 : 7;
            info.ListItemStyle.padding.right = info.IsReadOnly ? 4 : 20;

            if (Event.current.type == EventType.Repaint)
            {
                info.DropZoneTopLeft = GUIUtility.GUIToScreenPoint(new Vector2(0, 0));
            }

            info.ListValueChanger = property.ValueEntry.GetListValueEntryChanger();
            info.Count            = property.Children.Count;
            info.IsEmpty          = property.Children.Count == 0;

            SirenixEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding);
            this.BeginDropZone(info);
            {
                this.DrawToolbar(info);
                if (SirenixEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(property, this), info.Toggled.Value))
                {
                    GUIHelper.PushLabelWidth(EditorGUIUtility.labelWidth - info.ListItemStyle.padding.left);
                    this.DrawItems(info);
                    GUIHelper.PopLabelWidth();
                }
                SirenixEditorGUI.EndFadeGroup();
            }
            this.EndDropZone(info);
            SirenixEditorGUI.EndIndentedVertical();

            if (info.RemoveAt >= 0 && Event.current.type == EventType.Repaint)
            {
                info.ListValueChanger.RemoveListElementAt(info.RemoveAt, CHANGE_ID);

                info.RemoveAt = -1;
                GUIHelper.RequestRepaint();
            }

            if (info.ObjectPicker != null && info.ObjectPicker.IsReadyToClaim && Event.current.type == EventType.Repaint)
            {
                var value = info.ObjectPicker.ClaimObject();

                if (info.JumpToNextPageOnAdd)
                {
                    info.StartIndex = int.MaxValue;
                }

                object[] values = new object[info.ListValueChanger.ValueCount];

                values[0] = value;
                for (int j = 1; j < values.Length; j++)
                {
                    values[j] = SerializationUtility.CreateCopy(value);
                }

                info.ListValueChanger.AddListElement(values, CHANGE_ID);
            }
        }
Example #14
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var entry = this.ValueEntry;

            if (Event.current.type == EventType.Layout)
            {
                this.shouldDrawReferencePicker = ShouldDrawReferenceObjectPicker(this.ValueEntry);

                if (this.Property.Children.Count > 0)
                {
                    this.drawChildren = true;
                }
                else if (this.ValueEntry.ValueState != PropertyValueState.None)
                {
                    this.drawChildren = false;
                }
                else
                {
                    // Weird case: This prevents a foldout from being drawn that expands nothing.
                    // If we're the second last drawer, then the next drawer is most likely
                    // the composite drawer. And since we don't have any children in this
                    // else statement, we don't have anything else to draw.
                    this.drawChildren = this.bakedDrawerArray[this.bakedDrawerArray.Length - 2] != this;
                }
            }

            if (entry.ValueState == PropertyValueState.NullReference)
            {
                if (this.drawUnityObject)
                {
                    this.CallNextDrawer(label);
                }
                else
                {
                    if (entry.SerializationBackend == SerializationBackend.Unity && entry.IsEditable && Event.current.type == EventType.Layout)
                    {
                        Debug.LogError("Unity-backed value is null. This should already be fixed by the FixUnityNullDrawer!");
                    }
                    else
                    {
                        this.DrawField(label);
                    }
                }
            }
            else
            {
                if (this.shouldDrawReferencePicker)
                {
                    this.DrawField(label);
                }
                else
                {
                    this.CallNextDrawer(label);
                }
            }

            var objectPicker = ObjectPicker.GetObjectPicker(entry, entry.BaseValueType);

            if (objectPicker.IsReadyToClaim)
            {
                var obj = objectPicker.ClaimObject();
                entry.Property.Tree.DelayActionUntilRepaint(() =>
                {
                    entry.WeakValues[0] = obj;
                    for (int j = 1; j < entry.ValueCount; j++)
                    {
                        entry.WeakValues[j] = SerializationUtility.CreateCopy(obj);
                    }
                });
            }
        }
Example #15
0
        private void DrawField(GUIContent label)
        {
            if (this.inlinePropertyAttr != null)
            {
                var pushLabelWidth = this.inlinePropertyAttr.LabelWidth > 0;
                if (label == null)
                {
                    if (pushLabelWidth)
                    {
                        GUIHelper.PushLabelWidth(this.inlinePropertyAttr.LabelWidth);
                    }
                    this.DrawInlinePropertyReferencePicker();
                    this.CallNextDrawer(null);
                    if (pushLabelWidth)
                    {
                        GUIHelper.PopLabelWidth();
                    }
                }
                else
                {
                    SirenixEditorGUI.BeginVerticalPropertyLayout(label);
                    this.DrawInlinePropertyReferencePicker();
                    if (pushLabelWidth)
                    {
                        GUIHelper.PushLabelWidth(this.inlinePropertyAttr.LabelWidth);
                    }
                    for (int i = 0; i < this.Property.Children.Count; i++)
                    {
                        var child = this.Property.Children[i];
                        child.Draw(child.Label);
                    }
                    if (pushLabelWidth)
                    {
                        GUIHelper.PopLabelWidth();
                    }
                    SirenixEditorGUI.EndVerticalPropertyLayout();
                }
            }
            else
            {
                Rect valueRect;
                bool hasKeyboadFocus;
                int  id;
                var  rect = SirenixEditorGUI.GetFeatureRichControlRect(null, out id, out hasKeyboadFocus, out valueRect);

                if (label != null)
                {
                    rect.width     = GUIHelper.BetterLabelWidth;
                    valueRect.xMin = rect.xMax;

                    if (this.drawChildren)
                    {
                        this.isToggled.Value = SirenixEditorGUI.Foldout(rect, this.isToggled.Value, label);
                    }
                    else if (Event.current.type == EventType.Repaint)
                    {
                        rect = EditorGUI.IndentedRect(rect);
                        GUI.Label(rect, label);
                    }
                }
                else if (this.drawChildren)
                {
                    if (EditorGUIUtility.hierarchyMode)
                    {
                        rect.width = 18;
                        var preev = EditorGUIUtility.hierarchyMode;
                        this.isToggled.Value = SirenixEditorGUI.Foldout(rect, this.isToggled.Value, GUIContent.none);
                    }
                    else
                    {
                        rect.width     = 18;
                        valueRect.xMin = rect.xMax;
                        var preev = EditorGUIUtility.hierarchyMode;
                        EditorGUIUtility.hierarchyMode = false;
                        this.isToggled.Value           = SirenixEditorGUI.Foldout(rect, this.isToggled.Value, GUIContent.none);
                        EditorGUIUtility.hierarchyMode = preev;
                    }
                }

                EditorGUI.BeginChangeCheck();
                var prev = EditorGUI.showMixedValue;
                if (this.ValueEntry.ValueState == PropertyValueState.ReferenceValueConflict)
                {
                    EditorGUI.showMixedValue = true;
                }
                var newValue = SirenixEditorFields.PolymorphicObjectField(valueRect, this.ValueEntry.WeakSmartValue, this.ValueEntry.BaseValueType, this.allowSceneObjects, hasKeyboadFocus, id);
                EditorGUI.showMixedValue = prev;

                if (EditorGUI.EndChangeCheck())
                {
                    this.ValueEntry.Property.Tree.DelayActionUntilRepaint(() =>
                    {
                        this.ValueEntry.WeakValues[0] = newValue;
                        for (int j = 1; j < this.ValueEntry.ValueCount; j++)
                        {
                            this.ValueEntry.WeakValues[j] = SerializationUtility.CreateCopy(newValue);
                        }
                    });
                }

                if (this.drawChildren)
                {
                    var toggle = this.ValueEntry.ValueState == PropertyValueState.NullReference ? false : this.isToggled.Value;
                    if (SirenixEditorGUI.BeginFadeGroup(this, toggle))
                    {
                        EditorGUI.indentLevel++;
                        this.CallNextDrawer(null);
                        EditorGUI.indentLevel--;
                    }
                    SirenixEditorGUI.EndFadeGroup();
                }
            }
        }
Example #16
0
        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();
        }
 public override IUdonProgram GetProgram()
 {
     return((IUdonProgram)SerializationUtility.CreateCopy(program));
 }