Files
av3-animation-as-crab/Packages/dev.hai-vr.animator-as-code.v1/V1/Editor/AacAnimatorNode.cs
T
Haï~ 582b109a82 Accomodate new VRCAnimatorPlayAudio requirements:
- Nodes need to know the Animator Root, so that relative paths can be resolved during the creation of State behaviours (i.e. Relative path of an AudioSource).
- Nodes need to have the ability to create a New Behaviour, even if one already exists.
2024-06-30 13:58:54 +02:00

75 lines
2.8 KiB
C#

using UnityEngine;
// ReSharper disable once CheckNamespace
namespace AnimatorAsCode.V1
{
public abstract class AacAnimatorNode
{
protected internal abstract Vector3 GetPosition();
protected internal abstract void SetPosition(Vector3 position);
}
public abstract class AacAnimatorNode<TNode> : AacAnimatorNode where TNode : AacAnimatorNode<TNode>
{
protected readonly AacFlStateMachine ParentMachine;
protected readonly IAacDefaultsProvider DefaultsProvider;
protected readonly Transform AnimatorRoot;
protected AacAnimatorNode(AacFlStateMachine parentMachine, IAacDefaultsProvider defaultsProvider, Transform animatorRoot)
{
ParentMachine = parentMachine;
DefaultsProvider = defaultsProvider;
AnimatorRoot = animatorRoot;
}
public TNode LeftOf(AacAnimatorNode otherNode) => MoveNextTo(otherNode, -1, 0);
public TNode RightOf(AacAnimatorNode otherNode) => MoveNextTo(otherNode, 1, 0);
public TNode Over(AacAnimatorNode otherNode) => MoveNextTo(otherNode, 0, -1);
public TNode Under(AacAnimatorNode otherNode) => MoveNextTo(otherNode, 0, 1);
public TNode LeftOf() => MoveNextTo(null, -1, 0);
public TNode RightOf() => MoveNextTo(null, 1, 0);
public TNode Over() => MoveNextTo(null, 0, -1);
public TNode Under() => MoveNextTo(null, 0, 1);
public TNode At(int x, int y)
{
SetPosition(new Vector3(x * DefaultsProvider.Grid().x, y * DefaultsProvider.Grid().y, 0));
return (TNode) this;
}
public TNode Shift(AacAnimatorNode otherState, int shiftX, int shiftY) => MoveNextTo(otherState, shiftX, shiftY);
private TNode MoveNextTo(AacAnimatorNode otherStateOrSecondToLastWhenNull, int x, int y)
{
if (otherStateOrSecondToLastWhenNull == null)
{
var siblings = ParentMachine.GetChildNodes();
var other = siblings[siblings.Count - 2];
Shift(other.GetPosition(), x, y);
return (TNode) this;
}
Shift(otherStateOrSecondToLastWhenNull.GetPosition(), x, y);
return (TNode) this;
}
public TNode Shift(Vector3 otherPosition, int shiftX, int shiftY)
{
SetPosition(otherPosition + new Vector3(shiftX * DefaultsProvider.Grid().x, shiftY * DefaultsProvider.Grid().y, 0));
return (TNode) this;
}
public string ResolveRelativePath(Transform item)
{
return AacInternals.ResolveRelativePath(AnimatorRoot, item);
}
public abstract TBehaviour EnsureBehaviour<TBehaviour>() where TBehaviour : StateMachineBehaviour;
public abstract TBehaviour CreateNewBehaviour<TBehaviour>() where TBehaviour : StateMachineBehaviour;
}
}