mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-01 20:25:07 +08:00
Added support for AnimatorOverrideController (#139)
This commit is contained in:
parent
d72e529ad7
commit
811c934f40
@ -36,6 +36,8 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
internal class AnimatorCombiner
|
||||
{
|
||||
private readonly AnimatorController _combined;
|
||||
|
||||
private AnimatorOverrideController _overrideController;
|
||||
|
||||
private List<AnimatorControllerLayer> _layers = new List<AnimatorControllerLayer>();
|
||||
|
||||
@ -90,6 +92,20 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOverrideController(string basePath, AnimatorOverrideController overrideController, bool? writeDefaults)
|
||||
{
|
||||
AnimatorController controller = overrideController.runtimeAnimatorController as AnimatorController;
|
||||
if (controller == null) return;
|
||||
_overrideController = overrideController;
|
||||
try
|
||||
{
|
||||
this.AddController(basePath, controller, writeDefaults);
|
||||
} finally
|
||||
{
|
||||
_overrideController = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void insertLayer(string basePath, AnimatorControllerLayer layer, bool first, bool? writeDefaults)
|
||||
{
|
||||
var newLayer = new AnimatorControllerLayer()
|
||||
@ -260,6 +276,16 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
throw new Exception($"Unknown type referenced from animator: {original.GetType()}");
|
||||
}
|
||||
|
||||
// When using AnimatorOverrideController, replace the original AnimationClip based on AnimatorOverrideController.
|
||||
if (_overrideController != null && original is AnimationClip srcClip)
|
||||
{
|
||||
T overrideClip = _overrideController[srcClip] as T;
|
||||
if (overrideClip != null)
|
||||
{
|
||||
original = overrideClip;
|
||||
}
|
||||
}
|
||||
|
||||
if (cloneMap == null) cloneMap = new Dictionary<Object, Object>();
|
||||
|
||||
if (cloneMap.ContainsKey(original))
|
||||
|
@ -126,6 +126,12 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
{
|
||||
if (willPurgeAnimators) break; // animator will be deleted in subsequent processing
|
||||
|
||||
// RuntimeAnimatorController may be AnimatorOverrideController, convert in case of AnimatorOverrideController
|
||||
if (anim.runtimeAnimatorController is AnimatorOverrideController overrideController)
|
||||
{
|
||||
anim.runtimeAnimatorController = Util.ConvertAnimatorController(overrideController);
|
||||
}
|
||||
|
||||
var controller = anim.runtimeAnimatorController as AnimatorController;
|
||||
if (controller != null)
|
||||
{
|
||||
@ -138,6 +144,12 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
|
||||
case ModularAvatarMergeAnimator merger:
|
||||
{
|
||||
|
||||
// RuntimeAnimatorController may be AnimatorOverrideController, convert in case of AnimatorOverrideController
|
||||
if (merger.animator is AnimatorOverrideController overrideController)
|
||||
{
|
||||
merger.animator = Util.ConvertAnimatorController(overrideController);
|
||||
}
|
||||
var controller = merger.animator as AnimatorController;
|
||||
if (controller != null)
|
||||
{
|
||||
|
@ -118,6 +118,13 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
return merger.Finish();
|
||||
}
|
||||
|
||||
public static AnimatorController ConvertAnimatorController(AnimatorOverrideController overrideController)
|
||||
{
|
||||
var merger = new AnimatorCombiner();
|
||||
merger.AddOverrideController("", overrideController, null);
|
||||
return merger.Finish();
|
||||
}
|
||||
|
||||
public static bool IsTemporaryAsset(Object obj)
|
||||
{
|
||||
var path = AssetDatabase.GetAssetPath(obj);
|
||||
|
Loading…
Reference in New Issue
Block a user