fix: bind fighter animator controller in lobby

This commit is contained in:
ud18010
2026-07-30 17:15:09 +08:00
parent e9efa8a567
commit d3c4bba5b2
5 changed files with 178 additions and 1 deletions
@@ -0,0 +1,72 @@
using System;
using System.Collections;
using UnityEngine;
using UObject = UnityEngine.Object;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace XGame.ActorBehavior
{
public static class ActorBehaviorAnimatorControllerPaths
{
public static string GetControllerPath(string catalogType)
{
return string.Equals(catalogType, LobbyActorBehaviorRuntime.DefaultCatalogType, StringComparison.OrdinalIgnoreCase)
? "Assets/Game/Art/Actor/Controller/fighter.controller"
: null;
}
}
public static class ActorBehaviorAnimatorControllerLoader
{
public static IEnumerator ApplyController(string catalogType, Animator animator, Action<bool> onApplied = null)
{
if (animator == null)
{
onApplied?.Invoke(false);
yield break;
}
string controllerPath = ActorBehaviorAnimatorControllerPaths.GetControllerPath(catalogType);
if (string.IsNullOrEmpty(controllerPath))
{
onApplied?.Invoke(false);
yield break;
}
RuntimeAnimatorController controller = LoadControllerInEditor(controllerPath);
if (controller == null)
{
UObject loaded = null;
yield return XGame.XResLoader.coLoadRes(controllerPath, typeof(RuntimeAnimatorController), obj => loaded = obj);
controller = loaded as RuntimeAnimatorController;
}
if (controller == null)
{
Debug.LogWarning("[ActorBehaviorAnimatorControllerLoader] controller load failed: " + controllerPath);
onApplied?.Invoke(false);
yield break;
}
if (animator.runtimeAnimatorController != controller)
{
animator.runtimeAnimatorController = controller;
animator.Rebind();
animator.Update(0f);
}
onApplied?.Invoke(true);
}
private static RuntimeAnimatorController LoadControllerInEditor(string controllerPath)
{
#if UNITY_EDITOR
return AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(controllerPath);
#else
return null;
#endif
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a9d2d021b3b4de0a1e9437e62a08f6a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: