Added support for AnimatorOverrideController (#139)

This commit is contained in:
らいちちゃん 2022-12-10 03:55:17 +09:00 committed by GitHub
parent d72e529ad7
commit 811c934f40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -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))

View File

@ -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)
{

View File

@ -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);