using System.Collections.Generic; using UnityEngine; namespace UI.PartnerGather.Mining { /// /// 事件合作伙伴挖矿点管理器 /// 管理所有挖矿点的位置,提供按顺序获取挖矿点的功能 /// /// 建议挂载在:MiningPoints容器对象上 /// /// 场景结构建议: /// MiningPoints (挂载此脚本) /// ├── MiningPoint1 (挖矿点1) /// ├── MiningPoint2 (挖矿点2) /// ├── MiningPoint3 (挖矿点3) /// └── ... (更多挖矿点) /// /// 使用说明: /// - 将所有挖矿点的Transform拖拽到points数组中 /// - 或者脚本会自动获取所有子Transform作为挖矿点 /// public class EventPartnerMiningPointManager : MonoBehaviour { [Header("挖矿点配置")] [Tooltip("挖矿点Transform数组 - 手动拖拽或自动获取子Transform")] public List points = new List(); [Header("调试信息")] [Tooltip("当前挖矿点索引")] [SerializeField] private int _index = 0; private void Awake() { // 如果没有手动设置挖矿点,自动获取子Transform if (points == null || points.Count == 0) { AutoCollectMiningPoints(); } ValidateMiningPoints(); } /// /// 自动收集所有子Transform作为挖矿点 /// private void AutoCollectMiningPoints() { points = new List(); for (int i = 0; i < transform.childCount; i++) { Transform child = transform.GetChild(i); if (child.gameObject.activeInHierarchy) { points.Add(child); } } Log($"自动收集到 {points.Count} 个挖矿点"); } /// /// 验证挖矿点配置 /// private void ValidateMiningPoints() { if (points == null || points.Count == 0) { Log("警告:未找到任何挖矿点,请检查配置"); return; } // 移除空引用 for (int i = points.Count - 1; i >= 0; i--) { if (!points[i]) { points.RemoveAt(i); Log($"移除了空的挖矿点引用,索引:{i}"); } } Log($"✓ 挖矿点验证完成,有效点数:{points.Count}"); } public Transform GetNextPoint() { if (points == null || points.Count == 0) return null; var t = points[_index % points.Count]; _index++; return t; } public void ResetPoints() { _index = 0; } private static void Log(object t) { Debug.Log($"EventPartnerMiningPointManager-> {t} "); } } }