2025-12-10 18:22:26 -05:00
|
|
|
|
using System;
|
2025-10-23 00:49:44 -04:00
|
|
|
|
using System.Collections.Generic;
|
2025-12-10 18:22:26 -05:00
|
|
|
|
using AnimatorPlus;
|
2025-10-03 00:02:43 -04:00
|
|
|
|
using Continentis.MainGame.UI;
|
2026-04-17 12:01:50 -04:00
|
|
|
|
using SLSUtilities.General;
|
2025-10-03 00:02:43 -04:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Continentis.MainGame.Character
|
|
|
|
|
|
{
|
2025-12-10 18:22:26 -05:00
|
|
|
|
public partial class CombatCharacterViewBase : MonoBehaviour
|
2025-10-03 00:02:43 -04:00
|
|
|
|
{
|
|
|
|
|
|
public CharacterBase character;
|
|
|
|
|
|
|
2025-10-23 00:49:44 -04:00
|
|
|
|
public GameObject mainView;
|
|
|
|
|
|
public Animator animator;
|
2025-12-10 18:22:26 -05:00
|
|
|
|
public AnimatorPlus2D animatorPlus2D;
|
2025-10-23 00:49:44 -04:00
|
|
|
|
|
2025-10-03 00:02:43 -04:00
|
|
|
|
public Collider selector;
|
|
|
|
|
|
|
2025-10-23 00:49:44 -04:00
|
|
|
|
public Transform numbersPivot;
|
|
|
|
|
|
public Transform textsPivot;
|
2025-10-03 00:02:43 -04:00
|
|
|
|
public Transform hudPivot;
|
2025-10-23 00:49:44 -04:00
|
|
|
|
public Transform centerPoint => hudPivot;
|
2025-10-03 00:02:43 -04:00
|
|
|
|
public HUDContainer hudContainer;
|
2025-10-23 00:49:44 -04:00
|
|
|
|
|
2025-12-10 18:22:26 -05:00
|
|
|
|
public List<SpriteRenderer> spriteRenderers;
|
|
|
|
|
|
public List<Material> materials;
|
2026-04-01 12:23:27 -04:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 当前使用的动画驱动器,由 Initialize 时自动检测。
|
|
|
|
|
|
/// 外部通过此属性调用 PlayAction / ReturnToIdle 等方法。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ICharacterAnimator CharacterAnimator { get; private set; }
|
2025-12-10 18:22:26 -05:00
|
|
|
|
|
2026-04-01 12:23:27 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化角色视图:收集 SpriteRenderer / Material,自动检测并初始化动画驱动器。
|
|
|
|
|
|
/// </summary>
|
2025-12-10 18:22:26 -05:00
|
|
|
|
public void Initialize(CharacterBase character)
|
2025-10-23 00:49:44 -04:00
|
|
|
|
{
|
2025-12-10 18:22:26 -05:00
|
|
|
|
this.character = character;
|
2025-10-23 00:49:44 -04:00
|
|
|
|
|
2025-12-10 18:22:26 -05:00
|
|
|
|
spriteRenderers = new List<SpriteRenderer>(mainView.GetComponentsInChildren<SpriteRenderer>());
|
|
|
|
|
|
materials = new List<Material>();
|
|
|
|
|
|
foreach (SpriteRenderer sr in spriteRenderers)
|
2025-10-23 00:49:44 -04:00
|
|
|
|
{
|
2025-12-10 18:22:26 -05:00
|
|
|
|
materials.Add(sr.material);
|
2025-10-23 00:49:44 -04:00
|
|
|
|
}
|
2025-12-10 18:22:26 -05:00
|
|
|
|
SetOutline(false);
|
|
|
|
|
|
|
2026-04-01 12:23:27 -04:00
|
|
|
|
// 自动检测动画驱动器:优先级 Spine > Frame > Static
|
|
|
|
|
|
CharacterAnimator = GetComponent<SpineAnimator>() as ICharacterAnimator
|
|
|
|
|
|
?? GetComponent<FrameAnimator>() as ICharacterAnimator
|
|
|
|
|
|
?? GetComponent<StaticSpriteAnimator>() as ICharacterAnimator;
|
|
|
|
|
|
|
|
|
|
|
|
if (CharacterAnimator != null)
|
2025-12-10 18:22:26 -05:00
|
|
|
|
{
|
2026-04-01 12:23:27 -04:00
|
|
|
|
CharacterAnimator.InitializeAnimator(this);
|
2025-12-10 18:22:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2026-04-01 12:23:27 -04:00
|
|
|
|
Debug.LogWarning($"[CharacterView] 角色 '{character.data.displayName}' 未挂载任何 ICharacterAnimator 实现,无动画驱动器。");
|
2025-12-10 18:22:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2025-10-23 00:49:44 -04:00
|
|
|
|
{
|
2025-12-10 18:22:26 -05:00
|
|
|
|
materials.ForEach(material => material.SetFloat("_InnerOutlineFade", 0));
|
|
|
|
|
|
materials.ForEach(material => material.SetColor("_InnerOutlineColor", Color.white));
|
2025-10-23 00:49:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-03 00:02:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|