123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /// <summary>
- /// 场景组件 机关/道具 管理者
- /// </summary>
- public class SceneCmptManager : MonoSingleton<SceneCmptManager>
- {
- /// <summary>
- /// 所有宝箱
- /// </summary>
- private List<GameObject> _allTreasureBox;
- /// <summary>
- /// 追踪的宝箱
- /// </summary>
- private List<GameObject> _allTrackBox;
- /// <summary>
- /// 打开的宝箱
- /// </summary>
- private List<GameObject> _openTreasureBox;
- /// <summary>
- /// 可破坏物体
- /// </summary>
- private List<GameObject> _damageCmpt;
- private List<GameObject> _mapSwitchList;
- private List<GameObject> _backDoorList;
- /// <summary>
- /// 机关 装置
- /// </summary>
- private List<GameObject> _allMechanism;
- private List<GameObject> _openMechanism;
- private void Awake()
- {
- _allTreasureBox = new List<GameObject>();
- _allTrackBox = new List<GameObject>();
- _openTreasureBox = new List<GameObject>();
- _allMechanism = new List<GameObject>();
- _openMechanism = new List<GameObject>();
- _damageCmpt = new List<GameObject>();
- _mapSwitchList = new List<GameObject>();
- _backDoorList = new List<GameObject>();
- }
- // Start is called before the first frame update
- void Start()
- {
-
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- public void Reset()
- {
- _allTreasureBox.Clear();
- _allTrackBox.Clear();
- _openTreasureBox.Clear();
- _allMechanism.Clear();
- _openMechanism.Clear();
- _damageCmpt.Clear();
- _mapSwitchList.Clear();
- _backDoorList.Clear();
- }
- public List<GameObject> GetAllTreasureBox()
- {
- return _allTreasureBox;
- }
- /// <summary>
- /// 添加宝箱
- /// </summary>
- /// <param name="obj"></param>
- public void AddTreasureBox(GameObject obj)
- {
- _allTreasureBox.Add(obj);
- // 网格优化分配
- if(GameObject.Find("GridMap"))
- {
- MyGridMap gridMap = GameObject.Find("GridMap").GetComponent<MyGridMap>();
- gridMap.AddOneObjToGrid(obj);
- }
- }
- /// <summary>
- /// 移除宝箱
- /// </summary>
- /// <param name="obj"></param>
- public void RemoveTreasureBox(GameObject obj)
- {
- _allTreasureBox.Remove(obj);
- }
- /// <summary>
- /// 打开宝箱
- /// </summary>
- /// <param name="obj"></param>
- public void OpenTreasureBox(GameObject obj)
- {
- _openTreasureBox.Add(obj);
- }
- public List<GameObject> GetAllTrackBox()
- {
- return _allTrackBox;
- }
- /// <summary>
- /// 添加宝箱
- /// </summary>
- /// <param name="obj"></param>
- public void AddTrackBox(GameObject obj)
- {
- _allTrackBox.Add(obj);
- }
- public void RemoveTrackBox(GameObject obj)
- {
- _allTrackBox.Remove(obj);
- }
- /// <summary>
- /// 获取打开宝箱数量
- /// </summary>
- /// <returns></returns>
- public int GetOpenBoxNum()
- {
- return _openTreasureBox.Count;
- }
- /// <summary>
- /// 获取宝箱总数
- /// </summary>
- /// <returns></returns>
- public int GetAllBoxNum()
- {
- return _allTreasureBox.Count;
- }
- /// <summary>
- /// 所有宝箱是否开启
- /// </summary>
- /// <returns></returns>
- public bool IsAllTreasureBoxFinish()
- {
- return _allTreasureBox.Count == _openTreasureBox.Count;
- }
- /// <summary>
- /// 添加机关
- /// </summary>
- /// <param name="obj"></param>
- public void AddMechanism(GameObject obj)
- {
- _allMechanism.Add(obj);
- // 网格优化分配
- if (GameObject.Find("GridMap") != null)
- {
- MyGridMap gridMap = GameObject.Find("GridMap").GetComponent<MyGridMap>();
- gridMap.AddOneObjToGrid(obj);
- }
- }
- /// <summary>
- /// 移除机关
- /// </summary>
- /// <param name="obj"></param>
- public void RemoveMechanism(GameObject obj)
- {
- _allMechanism.Remove(obj);
- }
- /// <summary>
- /// 触发机关
- /// </summary>
- /// <param name="obj"></param>
- public void OpenMechanism(GameObject obj)
- {
- _openMechanism.Add(obj);
- }
- /// <summary>
- /// 获取触发机关数量
- /// </summary>
- /// <returns></returns>
- public int GetMechanismNumber()
- {
- return _openMechanism.Count;
- }
- /// <summary>
- /// 是否避让所有机关?
- /// </summary>
- /// <returns></returns>
- public bool IsAllMechanismFinish()
- {
- return _openMechanism.Count == 0;
- }
- /// <summary>
- /// 获取所有可破坏组件
- /// </summary>
- /// <returns></returns>
- public List<GameObject> GetAllDamageCmpt()
- {
- return _damageCmpt;
- }
- public void AddDamageCmpt(GameObject obj)
- {
- this._damageCmpt.Add(obj);
- // 网格优化分配
- GameObject gridMap = GameObject.Find("GridMap");
- if(gridMap)
- {
- gridMap.GetComponent<MyGridMap>().AddOneObjToGrid(obj);
- }
- }
- public void RemoveDamageCmpt(GameObject obj)
- {
- this._damageCmpt.Remove(obj);
- }
- public void AddMapSwitchCmpt(GameObject obj)
- {
- this._mapSwitchList.Add(obj);
- //// 网格优化分配
- //if(GameObject.Find("GridMap"))
- //{
- // MyGridMap gridMap = GameObject.Find("GridMap").GetComponent<MyGridMap>();
- // gridMap.AddOneObjToGrid(obj);
- //}
- }
- public void RemoveMapSwitchCmpt(GameObject obj)
- {
- this._mapSwitchList.Remove(obj);
- }
- public SceneEventMapSwitchLogic GetMapSwitchCmptByIndex(int index)
- {
- if(_mapSwitchList == null)
- {
- return null;
- }
- for(int i = 0; i < _mapSwitchList.Count; ++i)
- {
- SceneEventMapSwitchLogic mapSwitch = _mapSwitchList[i].GetComponent<SceneEventMapSwitchLogic>();
- if(mapSwitch.info.switchIndex == index)
- {
- return mapSwitch;
- }
- }
- return null;
- }
- public List<GameObject> GetAllMapSwitchCmpt()
- {
- return this._mapSwitchList;
- }
- public void AddBackDoorCmpt(GameObject obj)
- {
- this._backDoorList.Add(obj);
- // 网格优化分配
- MyGridMap gridMap = GameObject.Find("GridMap").GetComponent<MyGridMap>();
- gridMap.AddOneObjToGrid(obj);
- }
- public void RemoveBackDoorCmpt(GameObject obj)
- {
- this._backDoorList.Remove(obj);
- }
- public SceneEventBackDoorLogic GetBackDoorCmptByIndex(int index)
- {
- if (_backDoorList == null)
- {
- return null;
- }
- for (int i = 0; i < _backDoorList.Count; ++i)
- {
- SceneEventBackDoorLogic bd = _backDoorList[i].GetComponent<SceneEventBackDoorLogic>();
- if (bd.info.Index == index)
- {
- return bd;
- }
- }
- return null;
- }
- public List<GameObject> GetAllBackDoorCmpt(GameObject obj)
- {
- return this._backDoorList;
- }
- /// <summary>
- /// 获取离指定玩家最近 且距离小于10米的 可破坏组件
- /// </summary>
- /// <param name="player"></param>
- /// <returns></returns>
- public GameObject GetDistanceMinDamageObj(Role player)
- {
- float minDis = 10;
- GameObject cmptObj = null;
- foreach(var item in _damageCmpt)
- {
- if (item == null)
- {
- continue;
- }
- float dis = Vector3.Distance(item.transform.position, player.transform.position);
- if(dis < minDis)
- {
- cmptObj = item;
- dis = minDis;
- }
- }
- return cmptObj;
- }
- }
|