Ejemplo n.º 1
0
        public AnimationStateManager(
            AnimationPlayer player,
            AnimationTree animationTree,
            Option <IAnimationGraphFactory> graphFactory,
            Option <IAnimationControlFactory> controlFactory,
            ProcessMode processMode,
            ITimeSource timeSource,
            bool active,
            ILoggerFactory loggerFactory) : base(player, processMode, timeSource, active, loggerFactory)
        {
            Ensure.That(animationTree, nameof(animationTree)).IsNotNull();

            AnimationTree = animationTree;

            GraphFactory   = graphFactory.IfNone(() => new AnimationGraphFactory());
            ControlFactory = controlFactory.IfNone(() => new AnimationControlFactory());

            Context = new AnimationGraphContext(
                Player,
                AnimationTree,
                OnAdvance,
                GraphFactory,
                ControlFactory,
                loggerFactory);

            _graph = GraphFactory.TryCreate((AnimationRootNode)AnimationTree.TreeRoot, Context).IfNone(() =>
                                                                                                       throw new ArgumentException(
                                                                                                           "Failed to create animation graph from the specified animation tree.",
                                                                                                           nameof(animationTree)));

            AnimationTree.ProcessMode = AnimationTree.AnimationProcessMode.Manual;

            this.LogDebug("Using graph factory: {}.", GraphFactory);
            this.LogDebug("Using control factory: {}.", ControlFactory);
        }
Ejemplo n.º 2
0
 public BlendTree(
     string path,
     AnimationNodeBlendTree root,
     AnimationGraphContext context) : base(path, root, context)
 {
     Root = root;
 }
Ejemplo n.º 3
0
        protected AnimationControl(string key, AnimationGraphContext context)
        {
            Ensure.That(key, nameof(key)).IsNotNullOrEmpty();
            Ensure.That(context, nameof(context)).IsNotNull();

            Key     = key;
            Context = context;
            Logger  = context.LoggerFactory.CreateLogger(this.GetLogCategory());
        }
Ejemplo n.º 4
0
        protected AnimationGraph(string path, AnimationRootNode root, AnimationGraphContext context)
        {
            Ensure.That(path, nameof(path)).IsNotNull();
            Ensure.That(root, nameof(root)).IsNotNull();
            Ensure.That(context, nameof(context)).IsNotNull();

            Key     = path;
            Root    = root;
            Context = context;
            Logger  = context.LoggerFactory.CreateLogger(this.GetLogCategory());
        }
Ejemplo n.º 5
0
        public Option <IAnimationGraph> TryCreate(
            string name, IAnimationGraph parent, AnimationGraphContext context)
        {
            Ensure.That(parent, nameof(parent)).IsNotNull();

            return(parent.FindAnimationNode <AnimationRootNode>(name).Bind(node =>
            {
                var path = string.IsNullOrEmpty(parent.Key) ? name : string.Join("/", parent.Key, name);

                return TryCreate(path, node, context);
            }));
        }
Ejemplo n.º 6
0
        public Trigger(
            string key,
            string parameter,
            AnimationNodeOneShot oneShotNode,
            AnimationNodeAnimation animationNode,
            AnimationGraphContext context) : base(key, animationNode, context)
        {
            Ensure.Any.IsNotNull(parameter, nameof(parameter));
            Ensure.Any.IsNotNull(oneShotNode, nameof(oneShotNode));

            Parameter   = parameter;
            OneShotNode = oneShotNode;

            _trigger = CreateSubject <Unit>();
        }
Ejemplo n.º 7
0
        public new static Option <Trigger> TryCreate(
            string name, IAnimationGraph parent, AnimationGraphContext context)
        {
            Ensure.That(parent, nameof(parent)).IsNotNull();

            //TODO Resolve in an automatic fashion when it becomes possible to manipulate node connections from code.
            var animationNodeKey = name + " Animation";

            return((
                       from oneShot in parent.FindAnimationNode <AnimationNodeOneShot>(name)
                       from animation in parent.FindAnimationNode <AnimationNodeAnimation>(animationNodeKey)
                       select(oneShot, animation)).Map(t =>
            {
                var key = string.Join(":", parent.Key, name);
                var parameter = string.Join("/",
                                            new[] { "parameters", parent.Key, name, "scale" }.Where(v => v.Length > 0));

                return new Trigger(key, parameter, t.oneShot, t.animation, context);
            }));
        }
Ejemplo n.º 8
0
        public virtual Option <IAnimationControl> TryCreate(
            string name, IAnimationGraph parent, AnimationGraphContext context)
        {
            IAnimationControl Initialize(IAnimationControl control)
            {
                control.Initialize();

                return(control);
            }

            return
                (SeekableAnimator.TryCreate(name, parent, context).Map(Initialize) |
                 Animator.TryCreate(name, parent, context).Map(Initialize) |
                 Blender.TryCreate(name, parent, context).Map(Initialize) |
                 Blender2D.TryCreate(name, parent, context).Map(Initialize) |
                 CrossfadingAnimator.TryCreate(name, parent, context).Map(Initialize) |
                 TimeScale.TryCreate(name, parent, context).Map(Initialize) |
                 Trigger.TryCreate(name, parent, context).Map(Initialize) |
                 None);
        }
Ejemplo n.º 9
0
        protected virtual Option <IAnimationGraph> TryCreate(
            string path, AnimationRootNode node, AnimationGraphContext context)
        {
            Ensure.That(node, nameof(node)).IsNotNull();

            Option <IAnimationGraph> graph = None;

            switch (node)
            {
            case AnimationNodeStateMachine states:
                graph = new AnimationStates(path, states, context);
                break;

            case AnimationNodeBlendTree blendTree:
                graph = new BlendTree(path, blendTree, context);
                break;
            }

            graph.Iter(g => g.Initialize());

            return(graph);
        }
Ejemplo n.º 10
0
 public Option <IAnimationGraph> TryCreate(AnimationRootNode node, AnimationGraphContext context) =>
 TryCreate(string.Empty, node, context);