CoolTrainStudyCtrl.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using GameFramework.Event;
  5. using UnityEngine;
  6. public class CoolTrainStudyCtrl : MonoBehaviour
  7. {
  8. private Ray _ray;
  9. private RaycastHit _raycastHit;
  10. public bool _learnTarget = false;
  11. private Dictionary<CoolHardWaryType, RayCastColliders> _colliderList;
  12. private void Awake()
  13. {
  14. _colliderList = new Dictionary<CoolHardWaryType, RayCastColliders>();
  15. for (int i = 1; i < 7; i++)
  16. {
  17. _colliderList.Add((CoolHardWaryType)i,this.transform.Find($"{(CoolHardWaryType)i}Collider").GetComponent<RayCastColliders>());
  18. }
  19. foreach (var item in _colliderList.Values)
  20. {
  21. item.SetMeshEnable(false);
  22. }
  23. }
  24. void Start()
  25. {
  26. _learnTarget = false;
  27. GameMain.Event.Subscribe(Cool_StartLearnTargetInfoEvent.EventId,StartLearn);
  28. }
  29. // Update is called once per frame
  30. void Update()
  31. {
  32. if (_learnTarget)
  33. {
  34. foreach (var item in _colliderList.Values)
  35. {
  36. item.SetMeshEnable(false);
  37. }
  38. _ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  39. if (Physics.Raycast(_ray,out _raycastHit))
  40. {
  41. switch (_raycastHit.collider.gameObject.name)
  42. {
  43. case "CoolingTowerCollider":
  44. _colliderList[CoolHardWaryType.CoolingTower].SetMeshEnable(true);
  45. GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.CoolingTower));
  46. break;
  47. case "ChilledWaterPumpCollider":
  48. _colliderList[CoolHardWaryType.ChilledWaterPump].SetMeshEnable(true);
  49. GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.ChilledWaterPump));
  50. break;
  51. case "BufferTankCollider":
  52. _colliderList[CoolHardWaryType.BufferTank].SetMeshEnable(true);
  53. GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.BufferTank));
  54. break;
  55. case "PrecisionAirConditionerCollider":
  56. _colliderList[CoolHardWaryType.PrecisionAirConditioner].SetMeshEnable(true);
  57. GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.PrecisionAirConditioner));
  58. break;
  59. case "CompressorCollider":
  60. _colliderList[CoolHardWaryType.Compressor].SetMeshEnable(true);
  61. GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.Compressor));
  62. break;
  63. case "CoolingUnitControlCollider":
  64. _colliderList[CoolHardWaryType.CoolingUnitControl].SetMeshEnable(true);
  65. GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.CoolingUnitControl));
  66. break;
  67. default:
  68. GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.none));
  69. break;
  70. }
  71. }
  72. else
  73. {
  74. GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.none));
  75. }
  76. }
  77. }
  78. private void OnDestroy()
  79. {
  80. if (GameMain.Event.Check(Cool_StartLearnTargetInfoEvent.EventId, StartLearn))
  81. {
  82. GameMain.Event.Unsubscribe(Cool_StartLearnTargetInfoEvent.EventId,StartLearn);
  83. }
  84. }
  85. private void StartLearn(object sender,GameEventArgs e)
  86. {
  87. Cool_StartLearnTargetInfoEvent args = (Cool_StartLearnTargetInfoEvent)e;
  88. _learnTarget = args.start;
  89. }
  90. private void ReStartTrain(object sender,GameEventArgs e)
  91. {
  92. foreach (var item in _colliderList.Values)
  93. {
  94. item.SetMeshEnable(false);
  95. }
  96. GameMain.Event.Fire(this,Cool_TrainStudyShowTargetInfoEvent.Create(CoolHardWaryType.none));
  97. }
  98. }