TvmCtrl.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using System;
  6. using UnityCommon;
  7. namespace DTYJ
  8. {
  9. public class TvmCtrl : SerializedMonoBehaviour
  10. {
  11. public static TvmCtrl Instance;
  12. public Material mt_0, mt_1, mt_2;
  13. public Dictionary<string, GameObject> map = new Dictionary<string, GameObject>();
  14. private void Awake()
  15. {
  16. Instance = this;
  17. }
  18. [Serializable]
  19. public class TvmItem
  20. {
  21. }
  22. public void SetTVM(string id, int state)
  23. {
  24. if (map.ContainsKey(id))
  25. SetState(map[id], state);
  26. }
  27. /// <summary>
  28. /// 0Õý³£
  29. /// 1ÔÝÍ£
  30. /// </summary>
  31. /// <param name="state"></param>
  32. public void SetState(GameObject goRoot, int state)
  33. {
  34. Material mat = null;
  35. switch (state)
  36. {
  37. case 0:
  38. mat = mt_0;
  39. break;
  40. case 1:
  41. mat = mt_1;
  42. break;
  43. case 2:
  44. mat = mt_2;
  45. break;
  46. }
  47. goRoot.transform.GetChild(11).GetComponent<MeshRenderer>().material = mat;
  48. goRoot.transform.GetChild(13).GetComponent<MeshRenderer>().material = mat;
  49. goRoot.transform.GetChild(19).GetComponent<MeshRenderer>().material = mat;
  50. goRoot.transform.GetChild(21).GetComponent<MeshRenderer>().material = mat;
  51. goRoot.transform.GetChild(22).GetComponent<MeshRenderer>().material = mat;
  52. }
  53. [ContextMenu("´¦Àí")]
  54. public void HandleTemp()
  55. {
  56. Dictionary<string, GameObject> mapNew = new Dictionary<string, GameObject>();
  57. foreach (var kvp in map)
  58. {
  59. var goPath = Utility.GetPathInHierichy(kvp.Value.transform, null);
  60. mapNew["1_" + kvp.Key] = GameObject.Find("StationOthers/1/" + goPath);
  61. mapNew["2_" + kvp.Key] = GameObject.Find("StationOthers/2/" + goPath);
  62. }
  63. foreach (var kvp in mapNew)
  64. {
  65. map[kvp.Key] = kvp.Value;
  66. }
  67. }
  68. }
  69. }