ZhaJiCtrl.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityCommon;
  5. using UnityEngine;
  6. using Sirenix.OdinInspector;
  7. namespace DTYJ
  8. {
  9. public class ZhaJiCtrl : SerializedMonoBehaviour
  10. {
  11. public static ZhaJiCtrl Instance;
  12. private Dictionary<MeshRenderer, Material> dicMatOld;
  13. private void Awake()
  14. {
  15. Instance = this;
  16. }
  17. private void Start()
  18. {
  19. dicMatOld = new Dictionary<MeshRenderer, Material>();
  20. foreach (var item in dic)
  21. {
  22. dicMatOld[item.Value.mrJin] = item.Value.mrJin.material;
  23. dicMatOld[item.Value.mrChu] = item.Value.mrChu.material;
  24. }
  25. }
  26. public Material mKai, mGuan;
  27. public Dictionary<string, ZhaJiModelItem> dic = new Dictionary<string, ZhaJiModelItem>();
  28. [Serializable]
  29. public class ZhaJiModelItem
  30. {
  31. public Animation anim;
  32. public MeshRenderer mrJin, mrChu;
  33. }
  34. public void SetGateState(string id, int state, int dir)
  35. {
  36. if (dic.ContainsKey(id))
  37. {
  38. var item = dic[id];
  39. var anim = item.anim;
  40. var animationName = dic[id].anim.clip.name;
  41. anim[animationName].time = state == 1 ? 0 : anim[animationName].length;
  42. anim[animationName].speed = state == 1 ? 1 : -1;
  43. anim[animationName].wrapMode = WrapMode.Once;
  44. anim.CrossFade(animationName);
  45. if (state == 2 || state == 3)
  46. {
  47. item.mrJin.material = mGuan;
  48. item.mrChu.material = mGuan;
  49. }
  50. else
  51. {
  52. item.mrJin.material = dicMatOld[item.mrJin];
  53. item.mrChu.material = dicMatOld[item.mrChu];
  54. if (dir == 0 || dir == 1)
  55. {//TODO 乘客导航方向需要变更
  56. Debug.LogWarning("变更闸机方向");
  57. return;//张海军接口方向控制错误,直接返回,不受他direction字段控制闸机方向
  58. item.mrJin.material = dir == 0 ? mKai : mGuan;
  59. item.mrChu.material = dir == 1 ? mKai : mGuan;
  60. }
  61. }
  62. }
  63. }
  64. [ContextMenu("处理")]
  65. public void HandleTemp()
  66. {
  67. Dictionary<string, ZhaJiModelItem> dicNew = new Dictionary<string, ZhaJiModelItem>();
  68. foreach (var kvp in dic)
  69. {
  70. var animPath = Utility.GetPathInHierichy(kvp.Value.anim.transform, null);
  71. var mrChuPath = Utility.GetPathInHierichy(kvp.Value.mrChu.transform, null);
  72. var mrJinPath = Utility.GetPathInHierichy(kvp.Value.mrJin.transform, null);
  73. ZhaJiModelItem zhaJiModelItem = new ZhaJiModelItem();
  74. zhaJiModelItem.anim = GameObject.Find("StationOthers/1/" + animPath).GetComponent<Animation>();
  75. zhaJiModelItem.mrChu = GameObject.Find("StationOthers/1/" + mrChuPath).GetComponent<MeshRenderer>();
  76. zhaJiModelItem.mrJin = GameObject.Find("StationOthers/1/" + mrJinPath).GetComponent<MeshRenderer>();
  77. dicNew["1_" + kvp.Key] = zhaJiModelItem;
  78. zhaJiModelItem = new ZhaJiModelItem();
  79. zhaJiModelItem.anim = GameObject.Find("StationOthers/2/" + animPath).GetComponent<Animation>();
  80. zhaJiModelItem.mrChu = GameObject.Find("StationOthers/2/" + mrChuPath).GetComponent<MeshRenderer>();
  81. zhaJiModelItem.mrJin = GameObject.Find("StationOthers/2/" + mrJinPath).GetComponent<MeshRenderer>();
  82. dicNew["2_" + kvp.Key] = zhaJiModelItem;
  83. }
  84. foreach (var kvp in dicNew)
  85. {
  86. dic[kvp.Key] = kvp.Value;
  87. }
  88. }
  89. //public List<MeshRenderer> list = new List<MeshRenderer>();
  90. //[ContextMenu("处理2")]
  91. //public void HandleTemp2()
  92. //{
  93. // foreach(var item in dic)
  94. // {
  95. // list.Add(item.Value.mrChu);
  96. // list.Add(item.Value.mrJin);
  97. // }
  98. //}
  99. }
  100. }