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(); // 初始化为普通状态 // bg_current if (bg_current) { var fx = bg_current.transform.Find("fx_ui_partnermining_target_glow"); if (fx) { fx.gameObject.SetActive(false); } } UpdateStatus(LevelStatus.Normal); } /// /// 验证必要的UI组件是否设置 /// private void ValidateComponents() { bool hasError = false; if (bg_normal == null) { LogError("MissingComponent component=bg_normal"); hasError = true; } if (bg_current == null) { LogError("MissingComponent component=bg_current"); hasError = true; } if (bg_done == null) { LogError("MissingComponent component=bg_done"); hasError = true; } if (!hasError) { ELog("ValidateComponents success=true"); } } #endregion #region 公共接口 /// /// 更新等级状态 /// /// 新的状态 public void UpdateStatus(LevelStatus status) { if (_currentStatus == status) return; // 避免重复设置 _currentStatus = status; // 先隐藏所有背景 SetAllBackgroundsActive(false); // 根据状态激活对应背景 switch (status) { case LevelStatus.Normal: if (bg_normal) bg_normal.SetActive(true); break; case LevelStatus.Current: if (bg_current) bg_current.SetActive(true); break; case LevelStatus.Done: if (bg_done) { bg_done.SetActive(true); // bg_done.GetComponent().Play("level_done"); } break; } ELog($"UpdateLevelStatus status={status}"); } /// /// 获取当前状态 /// public LevelStatus GetCurrentStatus() { return _currentStatus; } /// /// 重置到普通状态 /// public void ResetToNormal() { UpdateStatus(LevelStatus.Normal); } #endregion #region 私有方法 /// /// 设置所有背景的激活状态 /// private void SetAllBackgroundsActive(bool active) { if (bg_normal) bg_normal.SetActive(active); if (bg_current) bg_current.SetActive(active); if (bg_done) bg_done.SetActive(active); } private static void ELog(object message) { #if UNITY_EDITOR Debug.Log($"EventPartnerMiningLevelController-> {message} "); #endif } private static void LogError(object message) { Debug.LogError($"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 } }