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()); }
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); }
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("/"))); }
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); })); }
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); })); }
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); }
public static Option <TimeScale> FindTimeScale(this IAnimationGraph graph, string path) { Ensure.Any.IsNotNull(graph, nameof(graph)); return(graph.FindDescendantControl <TimeScale>(path)); }
public static Option <Blender2D> FindBlender2D(this IAnimationGraph graph, string path) { Ensure.Any.IsNotNull(graph, nameof(graph)); return(graph.FindDescendantControl <Blender2D>(path)); }
public static Option <SeekableAnimator> FindSeekableAnimator(this IAnimationGraph graph, string path) { Ensure.Any.IsNotNull(graph, nameof(graph)); return(graph.FindDescendantControl <SeekableAnimator>(path)); }
public static Option <BlendTree> FindBlendTree(this IAnimationGraph graph, string path) { Ensure.That(graph, nameof(graph)).IsNotNull(); return(graph.FindDescendantGraph <BlendTree>(path)); }
public static Option <T> FindDescendantControl <T>( this IAnimationGraph graph, string path) where T : IAnimationControl => FindDescendantControl(graph, path).OfType <T>().HeadOrNone();
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)));
public static Option <IAnimator> FindAnimator(this IAnimationGraph graph, string path) { Ensure.That(graph, nameof(graph)).IsNotNull(); return(graph.FindDescendantControl <IAnimator>(path)); }