83 lines
3.0 KiB
C#
83 lines
3.0 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using AnimatorPlus;
|
||
using Continentis.MainGame.UI;
|
||
using SLSUtilities.General;
|
||
using UnityEngine;
|
||
|
||
namespace Continentis.MainGame.Character
|
||
{
|
||
public partial class CombatCharacterViewBase : MonoBehaviour
|
||
{
|
||
public CharacterBase character;
|
||
|
||
public GameObject mainView;
|
||
public Animator animator;
|
||
public AnimatorPlus2D animatorPlus2D;
|
||
|
||
public Collider selector;
|
||
|
||
public Transform numbersPivot;
|
||
public Transform textsPivot;
|
||
public Transform hudPivot;
|
||
public Transform centerPoint => hudPivot;
|
||
public HUDContainer hudContainer;
|
||
|
||
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;
|
||
|
||
spriteRenderers = new List<SpriteRenderer>(mainView.GetComponentsInChildren<SpriteRenderer>());
|
||
materials = new List<Material>();
|
||
foreach (SpriteRenderer sr in spriteRenderers)
|
||
{
|
||
materials.Add(sr.material);
|
||
}
|
||
SetOutline(false);
|
||
|
||
// 自动检测动画驱动器:优先级 Spine > Frame > Static
|
||
CharacterAnimator = GetComponent<SpineAnimator>() as ICharacterAnimator
|
||
?? GetComponent<FrameAnimator>() as ICharacterAnimator
|
||
?? GetComponent<StaticSpriteAnimator>() as ICharacterAnimator;
|
||
|
||
if (CharacterAnimator != null)
|
||
{
|
||
CharacterAnimator.InitializeAnimator(this);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning($"[CharacterView] 角色 '{character.data.displayName}' 未挂载任何 ICharacterAnimator 实现,无动画驱动器。");
|
||
}
|
||
}
|
||
}
|
||
|
||
public partial class CombatCharacterViewBase
|
||
{
|
||
public void SetOutline(bool isEnabled)
|
||
{
|
||
if (isEnabled)
|
||
{
|
||
Color fractionColor = MainGameManager.Instance.basePrefabs.fractionColors[character.fraction];
|
||
materials.ForEach(material => material.SetFloat("_InnerOutlineFade", 1));
|
||
materials.ForEach(material => material.SetColor("_InnerOutlineColor", fractionColor * 2));
|
||
}
|
||
else
|
||
{
|
||
materials.ForEach(material => material.SetFloat("_InnerOutlineFade", 0));
|
||
materials.ForEach(material => material.SetColor("_InnerOutlineColor", Color.white));
|
||
}
|
||
}
|
||
}
|
||
} |