备份CatanBuilding瘦身独立工程
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI.PartnerGather.Mining
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件合作伙伴挖矿点管理器
|
||||
/// 管理所有挖矿点的位置,提供按顺序获取挖矿点的功能
|
||||
///
|
||||
/// 建议挂载在:MiningPoints容器对象上
|
||||
///
|
||||
/// 场景结构建议:
|
||||
/// MiningPoints (挂载此脚本)
|
||||
/// ├── MiningPoint1 (挖矿点1)
|
||||
/// ├── MiningPoint2 (挖矿点2)
|
||||
/// ├── MiningPoint3 (挖矿点3)
|
||||
/// └── ... (更多挖矿点)
|
||||
///
|
||||
/// 使用说明:
|
||||
/// - 将所有挖矿点的Transform拖拽到points数组中
|
||||
/// - 或者脚本会自动获取所有子Transform作为挖矿点
|
||||
/// </summary>
|
||||
public class EventPartnerMiningPointManager : MonoBehaviour
|
||||
{
|
||||
[Header("挖矿点配置")]
|
||||
[Tooltip("挖矿点Transform数组 - 手动拖拽或自动获取子Transform")]
|
||||
public List<Transform> points = new List<Transform>();
|
||||
|
||||
[Header("调试信息")]
|
||||
[Tooltip("当前挖矿点索引")]
|
||||
[SerializeField] private int _index = 0;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 如果没有手动设置挖矿点,自动获取子Transform
|
||||
if (points == null || points.Count == 0)
|
||||
{
|
||||
AutoCollectMiningPoints();
|
||||
}
|
||||
|
||||
ValidateMiningPoints();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动收集所有子Transform作为挖矿点
|
||||
/// </summary>
|
||||
private void AutoCollectMiningPoints()
|
||||
{
|
||||
points = new List<Transform>();
|
||||
|
||||
for (int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
Transform child = transform.GetChild(i);
|
||||
if (child.gameObject.activeInHierarchy)
|
||||
{
|
||||
points.Add(child);
|
||||
}
|
||||
}
|
||||
|
||||
Log($"自动收集到 {points.Count} 个挖矿点");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证挖矿点配置
|
||||
/// </summary>
|
||||
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($"<color=cyan>EventPartnerMiningPointManager-> {t} </color>");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user