更新
This commit is contained in:
@@ -14,7 +14,6 @@ namespace Continentis.MainGame.Character
|
||||
public GameObject mainView;
|
||||
public Animator animator;
|
||||
public AnimatorPlus2D animatorPlus2D;
|
||||
public SerializableDictionary<string, AnimationClip> animations;
|
||||
|
||||
public Collider selector;
|
||||
|
||||
@@ -26,7 +25,16 @@ namespace Continentis.MainGame.Character
|
||||
|
||||
public List<SpriteRenderer> spriteRenderers;
|
||||
public List<Material> materials;
|
||||
|
||||
/// <summary>
|
||||
/// 当前使用的动画驱动器,由 Initialize 时自动检测。
|
||||
/// 外部通过此属性调用 PlayAction / ReturnToIdle 等方法。
|
||||
/// </summary>
|
||||
public ICharacterAnimator CharacterAnimator { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始化角色视图:收集 SpriteRenderer / Material,自动检测并初始化动画驱动器。
|
||||
/// </summary>
|
||||
public void Initialize(CharacterBase character)
|
||||
{
|
||||
this.character = character;
|
||||
@@ -39,21 +47,18 @@ namespace Continentis.MainGame.Character
|
||||
}
|
||||
SetOutline(false);
|
||||
|
||||
animations = new SerializableDictionary<string, AnimationClip>();
|
||||
|
||||
foreach (KeyValuePair<string, AnimationClip> anim in character.data.animations)
|
||||
// 自动检测动画驱动器:优先级 Spine > Frame > Static
|
||||
CharacterAnimator = GetComponent<SpineAnimator>() as ICharacterAnimator
|
||||
?? GetComponent<FrameAnimator>() as ICharacterAnimator
|
||||
?? GetComponent<StaticSpriteAnimator>() as ICharacterAnimator;
|
||||
|
||||
if (CharacterAnimator != null)
|
||||
{
|
||||
animations.Add(anim.Key, anim.Value);
|
||||
}
|
||||
|
||||
if (animations.TryGetValue("Idle", out AnimationClip idle))
|
||||
{
|
||||
animatorPlus2D.defaultIdleClip = idle;
|
||||
animatorPlus2D.Initialize();
|
||||
CharacterAnimator.InitializeAnimator(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"No Idle animation found for character {character.data.displayName}");
|
||||
Debug.LogWarning($"[CharacterView] 角色 '{character.data.displayName}' 未挂载任何 ICharacterAnimator 实现,无动画驱动器。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user