コード例 #1
0
        private void SortHierarchy()
        {
            popupHierarchy = new Hierarchy(windowSize.x - 26.0f, 17.0f, this);

            var favourites            = propertyBoxes.Where(propertyBox => propertyBox.Favourite);
            var suggestions           = propertyBoxes.Where(propertyBox => PropertyFieldInfoUtility.IsSuggestedProperty(propertyBox.Component, propertyBox.PropertyName));
            var displayableProperties = propertyBoxes.ToList();

            var favouritesItem = new LabelHierarchyItem("Favourites");

            popupHierarchy.AddChild(favouritesItem);

            if (!favourites.Any())
            {
                var emptyLabelItem = new LabelHierarchyItem("Click the heart next to any property.");
                favouritesItem.Children = new List <IHierarchyItem>()
                {
                    emptyLabelItem,
                };
            }
            else
            {
                favouritesItem.Children = new List <IHierarchyItem>();
                foreach (var favourite in favourites)
                {
                    favouritesItem.Children.Add(new FavouriteHierarchyItem(favourite));
                }
            }

            if (suggestions.Any())
            {
                var suggestionsLabel = new LabelHierarchyItem("Suggestions");
                popupHierarchy.AddChild(suggestionsLabel);
                suggestionsLabel.Children = new List <IHierarchyItem>();

                foreach (var suggested in suggestions)
                {
                    if (favourites.Contains(suggested))
                    {
                        continue;
                    }

                    suggestionsLabel.Children.Add(new SuggestionHierarchyItem(suggested));
                }
            }

            var allPropertiesItem = new LabelHierarchyItem("All Properties");

            allPropertiesItem.Children = new List <IHierarchyItem>();
            popupHierarchy.AddChild(allPropertiesItem);

            var components = displayableProperties.Select(displayableProperty => displayableProperty.Component);

            components = components.Distinct().ToList();
            foreach (var component in components)
            {
                var properties = displayableProperties.Where(displayableProperty => displayableProperty.Component == component).ToList();
                allPropertiesItem.Children.Add(new ComponentHierarchyItem(component, properties));
            }
        }
コード例 #2
0
        public override void DoGUI(int depth)
        {
            BaseTimeline.ShouldRenderGizmos = IsExpanded && USPreferenceWindow.RenderHierarchyGizmos;

            using (new Shared.GUIBeginHorizontal())
            {
                using (new Shared.GUIBeginVertical(GUILayout.MaxWidth(FloatingWidth)))
                {
                    FloatingOnGUI(depth);

                    if (IsExpanded)
                    {
                        var propertyArea = FloatingBackgroundRect;
                        propertyArea.y     += ItemHeightStep;
                        propertyArea.x      = GetXOffsetForDepth(depth + 1);
                        propertyArea.width -= propertyArea.x;

                        using (new Shared.GUIBeginArea(propertyArea))
                        {
                            foreach (var propertyBox in propertyBoxes)
                            {
                                using (new Shared.GUIBeginHorizontal())
                                {
                                    propertyBox.OnGUI();

                                    using (new Shared.GUIChangeColor(Color.red))
                                    {
                                        if (GUILayout.Button("-", GUILayout.Width(20.0f)))
                                        {
                                            removingProperty = propertyBox;
                                        }
                                    }

                                    // This can happen during undo redo.
                                    if (propertyBox.PropertyFieldInfo == null)
                                    {
                                        continue;
                                    }

                                    var preFix       = propertyBox.PropertyFieldInfo.Name;
                                    var propertyInfo = PropertyTimeline.GetProperty(preFix, propertyBox.PropertyFieldInfo.Component);
                                    using (new Shared.GUIChangeColor(propertyInfo.UseCurrentValue ? Color.red : GUI.color))
                                    {
                                        if (GUILayout.Button("C"))
                                        {
                                            propertyInfo.UseCurrentValue = !propertyInfo.UseCurrentValue;
                                        }
                                    }
                                }
                            }

                            if (GUILayout.Button("Animate"))
                            {
                                if (Event.current.type == EventType.Repaint)
                                {
                                    animateButton = GUILayoutUtility.GetLastRect();
                                }

                                var components = PropertyTimeline.AffectedObject.GetComponents <Component>().ToList();

                                var allPropertyBoxes = new List <PropertyBox>();
                                foreach (var component in components)
                                {
                                    var properties = component.GetType().GetProperties().Where(property => !PropertyFieldInfoUtility.ShouldIgnoreProperty(property, component));
                                    var fields     = component.GetType().GetFields().Where(field => !PropertyFieldInfoUtility.shouldIgnoreField(field, component));

                                    foreach (var property in properties)
                                    {
                                        allPropertyBoxes.Add(new PropertyBox(new PropertyFieldInfo(component, property), true));
                                    }

                                    foreach (var field in fields)
                                    {
                                        allPropertyBoxes.Add(new PropertyBox(new PropertyFieldInfo(component, field), true));
                                    }
                                }

                                foreach (var propertyBox in propertyBoxes)
                                {
                                    var overlappingProperties = allPropertyBoxes.Where(innerPropertyBox => innerPropertyBox.Component == propertyBox.Component && innerPropertyBox.PropertyName == propertyBox.PropertyName);
                                    foreach (var overlappingProperty in overlappingProperties)
                                    {
                                        overlappingProperty.AddingProperty = true;
                                    }
                                }

                                USWindow.ShowPopupForProperties(animateButton, allPropertyBoxes, CommitModifications);
                            }
                        }
                    }
                }

                if (Event.current.type == EventType.Repaint)
                {
                    var newMaxHeight = GUILayoutUtility.GetLastRect().height;

                    if (MaxHeight != newMaxHeight)
                    {
                        EditorWindow.Repaint();
                        MaxHeight = newMaxHeight;
                    }
                }

                ContentOnGUI();
            }

            if (removingProperty != null)
            {
                RemoveProperty(removingProperty);
            }

            removingProperty = null;

            if (Event.current.commandName == "UndoRedoPerformed")
            {
                return;
            }

            if (CurveEditor.AreCurvesDirty)
            {
                PropertyTimeline.Process(PropertyTimeline.Sequence.RunningTime, PropertyTimeline.Sequence.PlaybackRate);
                CurveEditor.AreCurvesDirty = false;
            }
        }
コード例 #3
0
        public override void Initialize(USTimelineBase timeline)
        {
            var properties = Component.GetType().GetProperties().Where(property => !PropertyFieldInfoUtility.ShouldIgnoreProperty(property, Component));
            var fields     = Component.GetType().GetFields().Where(field => !PropertyFieldInfoUtility.shouldIgnoreField(field, Component));

            var totalCount = properties.Count() + fields.Count();

            // Removal
            if (totalCount < Children.Count)
            {
                var propertiesNotInBoth = Children.Where((hierarchyItem) => ((hierarchyItem as USPropertyHierarchyItem).PropertyFieldInfo != null && !properties.Contains((hierarchyItem as USPropertyHierarchyItem).PropertyFieldInfo.Property)));
                var fieldsNotInBoth     = Children.Where((hierarchyItem) => ((hierarchyItem as USPropertyHierarchyItem).PropertyFieldInfo != null && !fields.Contains((hierarchyItem as USPropertyHierarchyItem).PropertyFieldInfo.Field)));

                foreach (var missingProperty in propertiesNotInBoth)
                {
                    RemoveChild(missingProperty as IUSHierarchyItem);
                }
                foreach (var missingField in fieldsNotInBoth)
                {
                    RemoveChild(missingField as IUSHierarchyItem);
                }
            }

            /*
             *              // Addition
             *              if(totalCount > Children.Count)
             *              {
             *                      var extraProperties = properties.Where((property) => !Children.Any((item) => ((item is USPropertyHierarchyItem) && (item as USPropertyHierarchyItem).PropertyFieldInfo && (item as USPropertyHierarchyItem).PropertyFieldInfo.Property == property)));
             *                      var extraFields = fields.Where((field) => !Children.Any((item) => ((item is USPropertyHierarchyItem) && (item as USPropertyHierarchyItem).PropertyFieldInfo && (item as USPropertyHierarchyItem).PropertyFieldInfo.Field == field)));
             *
             *                      foreach(var extraProperty in extraProperties)
             *                      {
             *                              PropertyFieldInfo propertyFieldInfo = ScriptableObject.CreateInstance(typeof(PropertyFieldInfo)) as PropertyFieldInfo;
             *                              propertyFieldInfo.Component = Component;
             *                              propertyFieldInfo.Property = extraProperty;
             *
             *                              var mappedType = USPropertyMemberUtility.GetUnityPropertyNameFromUSProperty(propertyFieldInfo.Property.Name, Component);
             *                              if(mappedType == string.Empty)
             *                                      continue;
             *
             *                              USPropertyHierarchyItem hierarchyItem = ScriptableObject.CreateInstance(typeof(USPropertyHierarchyItem)) as USPropertyHierarchyItem;
             *                              hierarchyItem.PropertyFieldInfo = propertyFieldInfo;
             *                              hierarchyItem.PropertyTimeline = PropertyTimeline;
             *                              hierarchyItem.MappedType = mappedType;
             *                              hierarchyItem.Initialize(PropertyTimeline);
             *
             *                              AddChild(hierarchyItem as IUSHierarchyItem);
             *                      }
             *                      foreach(var extraField in extraFields)
             *                      {
             *                              PropertyFieldInfo propertyFieldInfo = ScriptableObject.CreateInstance(typeof(PropertyFieldInfo)) as PropertyFieldInfo;
             *                              propertyFieldInfo.Component = Component;
             *                              propertyFieldInfo.Field = extraField;
             *
             *                              var mappedType = USPropertyMemberUtility.GetUnityPropertyNameFromUSProperty(propertyFieldInfo.Field.Name, Component);
             *                              if(mappedType == string.Empty)
             *                                      continue;
             *
             *                              USPropertyHierarchyItem hierarchyItem = ScriptableObject.CreateInstance(typeof(USPropertyHierarchyItem)) as USPropertyHierarchyItem;
             *                              hierarchyItem.PropertyFieldInfo = propertyFieldInfo;
             *                              hierarchyItem.PropertyTimeline = PropertyTimeline;
             *                              hierarchyItem.MappedType = mappedType;
             *                              hierarchyItem.Initialize(PropertyTimeline);
             *
             *                              AddChild(hierarchyItem as IUSHierarchyItem);
             *                      }
             *              }
             */
        }