Skip to content

Commit

Permalink
chore: add some convenience APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Nov 25, 2024
1 parent 4fdaae7 commit 815942d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Editor/API/AnimatorServices/CloneContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

namespace nadena.dev.ndmf.animator
{
/// <summary>
/// The CloneContext keeps track of which virtual objects have been cloned from which original objects, and
/// therefore avoids double-cloning. It also keeps track of various context used during cloning, such as virtual
/// layer offsets.
/// Most users shouldn't use CloneContext directly; use the Clone wrappers in VirtualControllerContext instead.
/// </summary>
[PublicAPI]
public sealed class CloneContext
{
Expand Down
51 changes: 51 additions & 0 deletions Editor/API/AnimatorServices/VirtualControllerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using JetBrains.Annotations;
using UnityEditor.Animations;
using UnityEngine;
#if NDMF_VRCSDK3_AVATARS
using VRC.SDK3.Avatars.Components;
Expand Down Expand Up @@ -154,5 +156,54 @@ public IEnumerable<VirtualAnimatorController> GetAllControllers()
{
return _layerStates.Select(kv => this[kv.Key]).Where(v => v != null)!;
}


[return: NotNullIfNotNull("controller")]
public VirtualAnimatorController? Clone(RuntimeAnimatorController? controller)
{
return CloneContext.Clone(controller);
}

[return: NotNullIfNotNull("layer")]
public VirtualLayer? Clone(AnimatorControllerLayer? layer, int index)
{
return CloneContext.Clone(layer, index);
}

[return: NotNullIfNotNull("stateMachine")]
public VirtualStateMachine? Clone(AnimatorStateMachine? stateMachine)
{
return CloneContext.Clone(stateMachine);
}

[return: NotNullIfNotNull("transition")]
public VirtualStateTransition? Clone(AnimatorStateTransition? transition)
{
return CloneContext.Clone(transition);
}

[return: NotNullIfNotNull("transition")]
public VirtualTransition? Clone(AnimatorTransition? transition)
{
return CloneContext.Clone(transition);
}

[return: NotNullIfNotNull("state")]
public VirtualState? Clone(AnimatorState? state)
{
return CloneContext.Clone(state);
}

[return: NotNullIfNotNull("m")]
public VirtualMotion? Clone(Motion? m)
{
return CloneContext.Clone(m);
}

[return: NotNullIfNotNull("clip")]
public VirtualClip? Clone(AnimationClip? clip)
{
return CloneContext.Clone(clip);
}
}
}

0 comments on commit 815942d

Please sign in to comment.