using System; using System.Collections; using System.Collections.Generic; using GameFramework.Event; using UnityEngine; public class CoolTrainStudyCtrl : MonoBehaviour { private Ray _ray; private RaycastHit _raycastHit; public bool _learnTarget = false; private Dictionary _colliderList; private void Awake() { _colliderList = new Dictionary(); for (int i = 1; i < 7; i++) { _colliderList.Add((CoolHardWaryType)i,this.transform.Find($"{(CoolHardWaryType)i}Collider").GetComponent()); } foreach (var item in _colliderList.Values) { item.SetMeshEnable(false); } } void Start() { _learnTarget = false; GameMain.Event.Subscribe(Cool_StartLearnTargetInfoEvent.EventId,StartLearn); } // Update is called once per frame void Update() { if (_learnTarget) { foreach (var item in _colliderList.Values) { item.SetMeshEnable(false); } _ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(_ray,out _raycastHit)) { switch (_raycastHit.collider.gameObject.name) { case "CoolingTowerCollider": _colliderList[CoolHardWaryType.CoolingTower].SetMeshEnable(true); GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.CoolingTower)); break; case "ChilledWaterPumpCollider": _colliderList[CoolHardWaryType.ChilledWaterPump].SetMeshEnable(true); GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.ChilledWaterPump)); break; case "BufferTankCollider": _colliderList[CoolHardWaryType.BufferTank].SetMeshEnable(true); GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.BufferTank)); break; case "PrecisionAirConditionerCollider": _colliderList[CoolHardWaryType.PrecisionAirConditioner].SetMeshEnable(true); GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.PrecisionAirConditioner)); break; case "CompressorCollider": _colliderList[CoolHardWaryType.Compressor].SetMeshEnable(true); GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.Compressor)); break; case "CoolingUnitControlCollider": _colliderList[CoolHardWaryType.CoolingUnitControl].SetMeshEnable(true); GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.CoolingUnitControl)); break; default: GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.none)); break; } } else { GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.none)); } } } private void OnDestroy() { if (GameMain.Event.Check(Cool_StartLearnTargetInfoEvent.EventId, StartLearn)) { GameMain.Event.Unsubscribe(Cool_StartLearnTargetInfoEvent.EventId,StartLearn); } } private void StartLearn(object sender,GameEventArgs e) { Cool_StartLearnTargetInfoEvent args = (Cool_StartLearnTargetInfoEvent)e; _learnTarget = args.start; } private void ReStartTrain(object sender,GameEventArgs e) { foreach (var item in _colliderList.Values) { item.SetMeshEnable(false); } GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.none)); } }