using UnityEngine; namespace UI.PartnerGather.Mining { /// /// 等级状态枚举 /// public enum LevelStatus { Normal, // 普通状态(未到达) Current, // 当前状态(进行中) Done // 完成状态(已完成) } /// /// 事件合作伙伴挖矿等级控制器 /// 负责管理单个等级节点的视觉状态切换 /// /// 建议挂载在:每个等级节点的UI对象上 /// /// UI结构建议: /// LevelNode (挂载此脚本) /// ├── bg_normal (普通状态背景) /// ├── bg_current (当前状态背景,通常高亮显示) /// └── bg_done (完成状态背景,通常显示勾选标记) /// public class EventPartnerMiningLevelController : MonoBehaviour { #region UI引用配置 [Header("=== 状态背景配置 ===")] [Tooltip("普通状态背景GameObject")] public GameObject bg_normal; [Tooltip("当前进行状态背景GameObject")] public GameObject bg_current; [Tooltip("已完成状态背景GameObject")] public GameObject bg_done; [Header("=== 调试信息 ===")] [SerializeField] private LevelStatus _currentStatus = LevelStatus.Normal; #endregion #region Unity生命周期 private void Awake() { ValidateComponents(); // 初始化为普通状态 UpdateStatus(LevelStatus.Normal); } /// /// 验证必要的UI组件是否设置 /// private void ValidateComponents() { bool hasError = false; if (bg_normal == null) { Log("错误:缺少普通状态背景组件 (bg_normal)"); hasError = true; } if (bg_current == null) { Log("错误:缺少当前状态背景组件 (bg_current)"); hasError = true; } if (bg_done == null) { Log("错误:缺少完成状态背景组件 (bg_done)"); hasError = true; } if (!hasError) { Log("✓ 等级控制器组件验证完成"); } } #endregion #region 公共接口 /// /// 更新等级状态 /// /// 新的状态 public void UpdateStatus(LevelStatus status) { if (_currentStatus == status) return; // 避免重复设置 _currentStatus = status; // 先隐藏所有背景 SetAllBackgroundsActive(false); // 根据状态激活对应背景 switch (status) { case LevelStatus.Normal: if (bg_normal != null) bg_normal.SetActive(true); break; case LevelStatus.Current: if (bg_current != null) bg_current.SetActive(true); break; case LevelStatus.Done: if (bg_done != null) bg_done.SetActive(true); break; } Log($"等级状态已更新为: {status}"); } /// /// 获取当前状态 /// public LevelStatus GetCurrentStatus() { return _currentStatus; } /// /// 重置到普通状态 /// public void ResetToNormal() { UpdateStatus(LevelStatus.Normal); } #endregion #region 私有方法 /// /// 设置所有背景的激活状态 /// private void SetAllBackgroundsActive(bool active) { if (bg_normal != null) bg_normal.SetActive(active); if (bg_current != null) bg_current.SetActive(active); if (bg_done != null) bg_done.SetActive(active); } /// /// 日志输出 /// private static void Log(object message) { Debug.Log($"EventPartnerMiningLevelController-> {message} "); } #endregion #region 编辑器辅助 #if UNITY_EDITOR /// /// 编辑器下的状态预览功能 /// [UnityEngine.ContextMenu("预览普通状态")] private void PreviewNormal() => UpdateStatus(LevelStatus.Normal); [UnityEngine.ContextMenu("预览当前状态")] private void PreviewCurrent() => UpdateStatus(LevelStatus.Current); [UnityEngine.ContextMenu("预览完成状态")] private void PreviewDone() => UpdateStatus(LevelStatus.Done); #endif #endregion } }