private void RemoveProperty()
        {
            USUndoManager.RegisterCompleteObjectUndo(PropertyTimeline, "Remove Curve");
            USUndoManager.RegisterCompleteObjectUndo(this, "Remove Curve");
            foreach (var child in Children)
            {
                USUndoManager.RegisterCompleteObjectUndo(child, "Remove Curve");
            }

            var preFix       = PropertyFieldInfo.Name;
            var propertyInfo = PropertyTimeline.GetProperty(preFix, PropertyFieldInfo.Component);

            foreach (var child in Children)
            {
                ((USPropertyMemberHierarchyItem)child).Curve = null;
            }

            propertyInfo.RestoreBaseState();
            PropertyTimeline.RemoveProperty(propertyInfo);
            USUndoManager.DestroyImmediate(propertyInfo);

            IsSelected = false;
            foreach (var child in Children)
            {
                ((USPropertyMemberHierarchyItem)child).IsSelected = false;
            }
        }
        public bool IsPropertyUsingCurrentValue()
        {
            var preFix       = PropertyFieldInfo.Name;
            var propertyInfo = PropertyTimeline.GetProperty(preFix, PropertyFieldInfo.Component);

            return(propertyInfo.curves.Any(curve => curve.UseCurrentValue));
        }
        public void ToggleUseCurrentValue()
        {
            var preFix       = PropertyFieldInfo.Name;
            var propertyInfo = PropertyTimeline.GetProperty(preFix, PropertyFieldInfo.Component);

            foreach (var curve in propertyInfo.curves)
            {
                curve.UseCurrentValue = !curve.UseCurrentValue;
            }
        }
        public override void Initialize(USTimelineBase timeline)
        {
            var numberOfChildren = Children.Count;

            if (PropertyFieldInfo.Property != null)
            {
                numberOfChildren = USPropertyMemberUtility.GetNumberOfMembers(PropertyFieldInfo.Property.PropertyType);
            }
            else if (PropertyFieldInfo.Field != null)
            {
                numberOfChildren = USPropertyMemberUtility.GetNumberOfMembers(PropertyFieldInfo.Field.FieldType);
            }

            if (numberOfChildren != Children.Count)
            {
                Children.Clear();
                for (var index = 0; index < numberOfChildren; index++)
                {
                    var postFix = "";
                    if (PropertyFieldInfo.Property != null)
                    {
                        postFix = USPropertyMemberUtility.GetAdditionalMemberName(PropertyFieldInfo.Property.PropertyType, index);
                    }
                    else if (PropertyFieldInfo.Field != null)
                    {
                        postFix = USPropertyMemberUtility.GetAdditionalMemberName(PropertyFieldInfo.Field.FieldType, index);
                    }

                    var preFix = PropertyFieldInfo.Name;

                    var propertyMemberItem = CreateInstance <USPropertyMemberHierarchyItem>();
                    propertyMemberItem.PostFix    = postFix;
                    propertyMemberItem.Prefix     = preFix;
                    propertyMemberItem.CurveIndex = index;
                    propertyMemberItem.Initialize(PropertyTimeline);

                    var propertyInfo = PropertyTimeline.GetProperty(preFix, PropertyFieldInfo.Component);
                    if (propertyInfo != null)
                    {
                        propertyMemberItem.Curve  = propertyInfo.curves[index];
                        propertyInfo.InternalName = MappedType;
                    }

                    Children.Add(propertyMemberItem as IUSHierarchyItem);
                }
            }
        }
Пример #5
0
        private void RemoveProperty(PropertyBox propertyBox)
        {
            Debug.Log("Removing Property " + propertyBox);
            USUndoManager.RegisterCompleteObjectUndo(PropertyTimeline, "Remove Curve");
            USUndoManager.RegisterCompleteObjectUndo(this, "Remove Curve");
            USUndoManager.PropertyChange(CurveEditor, "Add Curve");

            propertyBoxes.Remove(propertyBox);

            var preFix       = propertyBox.PropertyName;
            var propertyInfo = PropertyTimeline.GetProperty(preFix, propertyBox.Component);

            propertyInfo.curves.ForEach(curve => CurveEditor.Curves.Remove(curve));

            propertyInfo.RestoreBaseState();
            PropertyTimeline.RemoveProperty(propertyInfo);
            USUndoManager.DestroyImmediate(propertyInfo);
        }
Пример #6
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;
            }
        }