예제 #1
0
        public static Option <T> FindControl <T>(this IAnimationGraph graph, string name)
            where T : IAnimationControl
        {
            Ensure.That(graph, nameof(graph)).IsNotNull();

            return(graph.FindControl(name).OfType <T>().HeadOrNone());
        }
예제 #2
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);
        }
예제 #3
0
        public static Option <IAnimationGraph> FindDescendantGraph(
            this IAnimationGraph graph, string path)
        {
            Option <IAnimationGraph> Find(IAnimationGraph parent, IEnumerable <string> segments) =>
            segments.Match(
                () => None,
                parent.FindGraph,
                (head, tail) => parent.FindGraph(head).Bind(p => Find(p, tail)));

            return(Find(graph, path.Split("/")));
        }
예제 #4
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);
            }));
        }
예제 #5
0
파일: Trigger.cs 프로젝트: kitfka/AlleyCat
        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);
            }));
        }
예제 #6
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);
        }
예제 #7
0
        public static Option <TimeScale> FindTimeScale(this IAnimationGraph graph, string path)
        {
            Ensure.Any.IsNotNull(graph, nameof(graph));

            return(graph.FindDescendantControl <TimeScale>(path));
        }
예제 #8
0
        public static Option <Blender2D> FindBlender2D(this IAnimationGraph graph, string path)
        {
            Ensure.Any.IsNotNull(graph, nameof(graph));

            return(graph.FindDescendantControl <Blender2D>(path));
        }
예제 #9
0
        public static Option <SeekableAnimator> FindSeekableAnimator(this IAnimationGraph graph, string path)
        {
            Ensure.Any.IsNotNull(graph, nameof(graph));

            return(graph.FindDescendantControl <SeekableAnimator>(path));
        }
예제 #10
0
        public static Option <BlendTree> FindBlendTree(this IAnimationGraph graph, string path)
        {
            Ensure.That(graph, nameof(graph)).IsNotNull();

            return(graph.FindDescendantGraph <BlendTree>(path));
        }
예제 #11
0
 public static Option <T> FindDescendantControl <T>(
     this IAnimationGraph graph, string path) where T : IAnimationControl =>
 FindDescendantControl(graph, path).OfType <T>().HeadOrNone();
예제 #12
0
 public static Option <IAnimationControl> FindDescendantControl(
     this IAnimationGraph graph, string path) =>
 path.Split("/").Rev().Match(
     () => None,
     graph.FindControl,
     (x, xs) => graph.FindDescendantGraph(string.Join("/", xs.Rev())).Bind(p => p.FindControl(x)));
예제 #13
0
        public static Option <IAnimator> FindAnimator(this IAnimationGraph graph, string path)
        {
            Ensure.That(graph, nameof(graph)).IsNotNull();

            return(graph.FindDescendantControl <IAnimator>(path));
        }