Exemple #1
0
 public TransitionDefinition(IAnimationDefinition parent, StateDefinition from, StateDefinition to, string name = null)
 {
     Name   = name ?? parent.Name;
     Parent = parent;
     From   = from;
     To     = to;
 }
 public MotionDefinition(IAnimationDefinition parent, Motion motion)
 {
     Name       = motion != null ? motion.name : "NULL";
     Parent     = parent;
     Motion     = motion;
     Type       = motion is BlendTree ? MotionType.BlendTree : MotionType.AnimationClip;
     IsRealized = true;
     if (motion is BlendTree blendTree)
     {
         if (!string.IsNullOrEmpty(blendTree.blendParameter))
         {
             BlendParameters.Add(
                 Children.AddChild(
                     new ParameterDefinition(this, blendTree.blendParameter, nameof(blendTree.blendParameter))));
         }
         if (!string.IsNullOrEmpty(blendTree.blendParameterY))
         {
             BlendParameters.Add(
                 Children.AddChild(
                     new ParameterDefinition(this, blendTree.blendParameterY, nameof(blendTree.blendParameterY))));
         }
         foreach (ChildMotion blendTreeChild in blendTree.children)
         {
             AddMotion(blendTreeChild.motion);
         }
     }
 }
Exemple #3
0
        private ObjectHolder Setup(Action selectionAction, string text, IAnimationDefinition def)
        {
            Container           = new VisualElement();
            ObjectField         = new ObjectField();
            DeleteButton        = new Button();
            AnimationDefinition = def;

            Container.Add(DeleteButton);
            Container.Add(ObjectField);
            Container.style.flexDirection = FlexDirection.Row;

            ObjectField.RemoveObjectSelector();
            ObjectField.AddToClassList("object-field--left-flushed");
            DeleteButton.AddToClassList("button--danger");

            name            = $"{text}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ";
            SelectionAction = selectionAction;

            void Callback(MouseDownEvent e)
            {
                e.StopImmediatePropagation();
                selectionAction?.Invoke();
            }

            ObjectField.RegisterCallback <MouseDownEvent>(Callback);
            ObjectField.value = this;
            return(this);
        }
 public MotionDefinition(IAnimationDefinition parent, bool isBlendTree, string name = null)
 {
     Name       = name ?? parent.Name;
     Parent     = parent;
     Type       = isBlendTree ? MotionType.BlendTree : MotionType.AnimationClip;
     IsRealized = false;
 }
Exemple #5
0
            public static List <Item> GetOptions(Sim target)
            {
                List <Item> items = new List <Item>();

                Dictionary <string, bool> existing = new Dictionary <string, bool>();

                List <InteractionObjectPair> results = GetInteractions(target);

                foreach (InteractionObjectPair pair in results)
                {
                    IAnimationDefinition animation = pair.InteractionDefinition as IAnimationDefinition;
                    if (string.IsNullOrEmpty(animation.ClipName))
                    {
                        continue;
                    }

                    if (existing.ContainsKey(animation.ClipName))
                    {
                        continue;
                    }

                    existing.Add(animation.ClipName, true);

                    items.Add(new Item(animation.InteractionName, animation.ClipName, animation.Type, pair.InteractionDefinition));
                }

                return(items);
            }
Exemple #6
0
 public ConditionDefinition(IAnimationDefinition parent, AnimatorConditionMode mode, float threshold, string name = null)
 {
     Mode      = mode;
     Threshold = threshold;
     Name      = name ?? parent.Name;
     Parent    = parent;
     AddParameter(false, Name);
 }
Exemple #7
0
 public ConditionDefinition(IAnimationDefinition parent, AnimatorCondition condition)
 {
     AnimatorCondition = condition;
     Name      = condition.parameter;
     Parent    = parent;
     Mode      = condition.mode;
     Threshold = condition.threshold;
     AddParameter(true, Name);
 }
 public MenuDefinition(IAnimationDefinition parent, VRCExpressionsMenu menu)
 {
     Name   = menu.name;
     Parent = parent;
     Menu   = menu;
     foreach (VRCExpressionsMenu.Control menuControl in menu.controls)
     {
         AddControl(menuControl);
     }
 }
Exemple #9
0
        public static bool TryGetFirstParent <T>(this IAnimationDefinition instance, out T result) where T : IAnimationDefinition
        {
            result = default;
            foreach (T parent in GetParents <T>(instance))
            {
                result = parent;
                return(true);
            }

            return(false);
        }
Exemple #10
0
        public static void Delete(this IAnimationDefinition definition, IEnumerable <IAnimationDefinition> skip = null)
        {
            if (definition.ShouldSkip(skip))
            {
                return;
            }

            definition.DeleteInternal(skip);
            definition.Parent?.Children.Remove(definition);
            AssetDatabase.Refresh();
        }
Exemple #11
0
        private static void DeleteInternal(this IAnimationDefinition definition, IEnumerable <IAnimationDefinition> skip = null)
        {
            if (definition.ShouldSkip(skip))
            {
                return;
            }

            $"DELETING: {definition}".Log();
            definition.Children.ForEach(c => c.DeleteInternal(skip));
            definition.Children.Clear();
            definition.DeleteSelf();
        }
        public bool UnMarkForDeletion(IAnimationDefinition definition)
        {
            if (!_toDelete.TryGetValue(definition, out ObjectField objectField))
            {
                return(false);
            }

            objectField.RemoveFromHierarchy();
            _toDelete.Remove(definition);
            _deletionHolder.Display(_toDelete.Any());
            return(true);
        }
Exemple #13
0
        public TransitionDefinition(IAnimationDefinition parent, AnimatorTransitionBase transition, StateDefinition from, StateDefinition to)
        {
            StateTransition = transition;
            Name            = string.IsNullOrEmpty(transition.name) ? parent.Name : transition.name;
            Parent          = parent;
            From            = from;
            To = to;

            foreach (AnimatorCondition condition in transition.conditions)
            {
                AddCondition(condition);
            }
        }
        public StateMachineDefinition(IAnimationDefinition parent, AnimatorStateMachine stateMachine)
        {
            Parent = parent;
            if (stateMachine == null)
            {
                $"StateMachine of parent {parent.Name} is null!".LogError();
                return;
            }

            StateMachine = stateMachine;
            Name         = stateMachine.name;

            Entry = new StateDefinition(this, nameof(Entry))
            {
                Type = StateDefinition.StateType.Entry
            };
            Exit = new StateDefinition(this, nameof(Exit))
            {
                Type = StateDefinition.StateType.Exit
            };
            Any = new StateDefinition(this, nameof(Any))
            {
                Type = StateDefinition.StateType.Any
            };

            foreach (ChildAnimatorState childAnimatorState in stateMachine.states)
            {
                var state           = childAnimatorState.state;
                var stateDefinition = AddState(state);
                if (stateMachine.defaultState == state)
                {
                    DefaultState = stateDefinition;
                }

                foreach (AnimatorTransition transition in stateMachine.entryTransitions)
                {
                    if (transition.destinationState == state)
                    {
                        AddTransition(transition, Entry, stateDefinition);
                    }
                }

                foreach (AnimatorStateTransition transition in stateMachine.anyStateTransitions)
                {
                    if (transition.destinationState == state)
                    {
                        AddTransition(transition, Any, stateDefinition);
                    }
                }
            }
        }
Exemple #15
0
        public static IEnumerable <T> GetChildren <T>(this IAnimationDefinition instance) where T : IAnimationDefinition
        {
            foreach (var child in instance.Children)
            {
                if (child is T value)
                {
                    yield return(value);
                }

                foreach (var t in child.GetChildren <T>())
                {
                    yield return(t);
                }
            }
        }
 public StateMachineDefinition(IAnimationDefinition parent, string name = null)
 {
     Name   = name ?? parent.Name;
     Parent = parent;
     Entry  = new StateDefinition(this, nameof(Entry))
     {
         Type = StateDefinition.StateType.Entry
     };
     Exit = new StateDefinition(this, nameof(Exit))
     {
         Type = StateDefinition.StateType.Exit
     };
     Any = new StateDefinition(this, nameof(Any))
     {
         Type = StateDefinition.StateType.Any
     };
 }
Exemple #17
0
        public static IEnumerable <T> GetParents <T>(this IAnimationDefinition instance) where T : IAnimationDefinition
        {
            if (instance.Parent == null)
            {
                yield break;
            }

            if (instance.Parent is T value)
            {
                yield return(value);
            }

            foreach (var t in instance.Parent.GetParents <T>())
            {
                yield return(t);
            }
        }
Exemple #18
0
        public MenuControlDefinition(IAnimationDefinition parent, VRCExpressionsMenu.Control control)
        {
            Name    = control.name;
            Parent  = parent;
            Control = control;
            Type    = control.type;

            if (Type == VRCExpressionsMenu.Control.ControlType.SubMenu)
            {
                AddMenu(control.subMenu);
                return;
            }

            MainParameter = AddParameter(control.parameter);
            foreach (var controlSubParameter in control.subParameters)
            {
                SubParameters.Add(AddParameter(controlSubParameter));
            }
        }
Exemple #19
0
        public AnimatorDefinition(IAnimationDefinition parent, AnimatorController animator, AnimatorType type)
        {
            bool animatorIsNull = animator == null;

            Parent   = parent;
            Animator = animator;
            Name     = animatorIsNull ? type.ToString() : animator.name;
            Type     = type;

            if (animatorIsNull)
            {
                return;
            }

            foreach (AnimatorControllerLayer animatorControllerLayer in animator.layers)
            {
                AddLayer(animatorControllerLayer);
            }
            foreach (var parameter in animator.parameters)
            {
                AddParameter(parameter);
            }
        }
Exemple #20
0
        private void SetupDeletion(Button deleteButton, ObjectField field, IAnimationDefinition def, AvatarParameterData data)
        {
            string deleteText   = "x";
            string undeleteText = "+";

            deleteButton.text = deleteText;
            void DeleteClicked()
            {
                var noDelete = !data.MarkForDeletion(this);

                field.SetEnabled(noDelete);
                deleteButton.AddToClassList("button--danger--green");
                deleteButton.text = undeleteText;
                if (noDelete)
                {
                    deleteButton.text = deleteText;
                    deleteButton.RemoveFromClassList("button--danger--green");
                    data.UnMarkForDeletion(def);
                }
            }

            deleteButton.clicked += DeleteClicked;
        }
Exemple #21
0
 public ParameterDefinition(IAnimationDefinition parent, string name, string label = "")
 {
     Name   = name ?? parent.Name;
     Parent = parent;
     Label  = label;
 }
Exemple #22
0
 public MenuControlDefinition(IAnimationDefinition parent, string name = null)
 {
     Name   = name ?? parent.Name;
     Parent = parent;
 }
Exemple #23
0
 private static bool ShouldSkip(this IAnimationDefinition def, IEnumerable <IAnimationDefinition> skip)
 {
     return(skip?.Contains(def) ?? false);
 }
Exemple #24
0
 public static bool IsDescendantOf(this IAnimationDefinition def, IAnimationDefinition parent)
 {
     return(def.GetParents <IAnimationDefinition>().Contains(parent));
 }
Exemple #25
0
 public static IEnumerable <T> GetChildren <T>(this IAnimationDefinition instance, string name) where T : IAnimationDefinition
 {
     return(instance.GetChildren <T>().Where(c => c.Name == name));
 }
Exemple #26
0
 public AnimatorDefinition(IAnimationDefinition parent, AnimatorType type, string name = null)
 {
     Name   = name ?? type.ToString();
     Parent = parent;
 }
Exemple #27
0
 private static ObjectHolder CreateHolder(Action selectionAction, string text, IAnimationDefinition def)
 {
     return(CreateInstance <ObjectHolder>().Setup(selectionAction, text, def));
 }
 public static TransitionDefinition AddTransition(this IAnimationDefinition instance, StateDefinition from, StateDefinition to, string name = null)
 {
     return(instance.Children.AddChild(new TransitionDefinition(instance, from, to, name)));
 }