UIAddMaterialPanel.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class UIAddMaterialPanel : UIPanelBase
  7. {
  8. public event Action OnClickAddMatBtn;
  9. private Button m_UCBtn;
  10. private Button m_TICBtn;
  11. private GameObject m_LocalView;
  12. private GameObject m_UpLoadView;
  13. private Button m_ADDBtn;
  14. private Button m_CloseBtn;
  15. private GameObject m_ItenPrefab;
  16. private Transform m_LocalItemParent;
  17. private Transform m_UpLoadItemParent;
  18. private MaterialObl m_SelectData;
  19. private bool m_IsLoca;
  20. public EditorPanel EditorPanel { get; set; }
  21. private void Awake()
  22. {
  23. m_UCBtn = transform.Find("Top/UCBtn").GetComponent<Button>();
  24. m_UCBtn.onClick.AddListener(onClickUCBtn);
  25. m_TICBtn = transform.Find("Top/TicBtn").GetComponent<Button>();
  26. m_TICBtn.onClick.AddListener(OnClickTicBtn);
  27. m_LocalView = transform.Find("MaterialElenemt/LocalView").gameObject;
  28. m_UpLoadView = transform.Find("MaterialElenemt/UpLoadView").gameObject;
  29. m_ADDBtn = transform.Find("ADDBtn").GetComponent<Button>();
  30. m_ADDBtn.onClick.AddListener(OnClickAddBtn);
  31. m_CloseBtn = transform.Find("CloseBtn").GetComponent<Button>();
  32. m_CloseBtn.onClick.AddListener(OnClickCloseBtn);
  33. m_ItenPrefab = transform.Find("SingleMaterial").gameObject;
  34. m_LocalItemParent = transform.Find("MaterialElenemt/LocalView/Viewport/LocalContent");
  35. m_UpLoadItemParent = transform.Find("MaterialElenemt/UpLoadView/Viewport/UpLoadContent");
  36. }
  37. public void Init()
  38. {
  39. m_LocalView.SetActive(true);
  40. m_UpLoadView.SetActive(true);
  41. CreateUpLoadDataUI();
  42. CreateLocalDataUI();
  43. m_UpLoadView.SetActive(false);
  44. gameObject.SetActive(false);
  45. }
  46. private void onClickUCBtn()
  47. {
  48. m_LocalView.gameObject.SetActive(true);
  49. m_UpLoadView.gameObject.SetActive(false);
  50. }
  51. private void OnClickTicBtn()
  52. {
  53. m_LocalView.gameObject.SetActive(false);
  54. m_UpLoadView.gameObject.SetActive(true);
  55. }
  56. private void OnClickAddBtn()
  57. {
  58. if (m_SelectData != null && GameManager.Instance.IsRuning)
  59. {
  60. GameManager.Instance.AddMaterial(m_SelectData);
  61. m_SelectData = null;
  62. m_IsLoca = false;
  63. if (OnClickAddMatBtn != null)
  64. {
  65. OnClickAddMatBtn();
  66. }
  67. }
  68. }
  69. private void OnClickCloseBtn()
  70. {
  71. EditorPanel.ChangeShowUI(true);
  72. }
  73. private void CreateUpLoadDataUI()
  74. {
  75. var materialsData = DataManager.Instance.AllMaterials;
  76. foreach (string item in materialsData.Keys)
  77. {
  78. var data = materialsData[item];
  79. for (int i = 0; i < data.Count; i++)
  80. {
  81. var mat = data[i];
  82. var obj = Instantiate(m_ItenPrefab, m_UpLoadItemParent, false);
  83. obj.SetActive(true);
  84. obj.transform.localScale = new Vector3(1, 1, 1);
  85. obj.transform.localRotation = Quaternion.identity;
  86. var matitem = obj.AddComponent<SingleMaterialItem>();
  87. matitem.OnSelectMaterial += OnSelectMat;
  88. matitem.SetData(mat, false);
  89. }
  90. }
  91. }
  92. private void CreateLocalDataUI()
  93. {
  94. string str = "Template/Texture/Dir_";
  95. string[] names = { "前进", "右", "左", "掉头", "右转", "左转" };
  96. for (int i = 0; i < 6; i++)
  97. {
  98. string path = str + i.ToString();
  99. var obj = Instantiate(m_ItenPrefab, m_LocalItemParent, false);
  100. obj.SetActive(true);
  101. obj.transform.localScale = new Vector3(1, 1, 1);
  102. obj.transform.localRotation = Quaternion.identity;
  103. var item = obj.AddComponent<SingleMaterialItem>();
  104. item.OnSelectMaterial += OnSelectMat;
  105. MaterialObl material = new MaterialObl();
  106. material.icon = path;
  107. material.name = names[i];
  108. material.type = 1;
  109. material.materialList = new List<MaterialObjValue>();
  110. MaterialObjValue value = new MaterialObjValue();
  111. value.DownloadPath = path;
  112. value.name = "";
  113. value.type = ((int)MaterialType.LocaImage).ToString();
  114. value.ObjectTransform = new ObjectTransform();
  115. material.materialList.Add(value);
  116. item.SetData(material, true);
  117. }
  118. }
  119. private void OnSelectMat(MaterialObl material, bool islocal)
  120. {
  121. m_SelectData = material;
  122. m_IsLoca = islocal;
  123. }
  124. private void OnDisable()
  125. {
  126. m_SelectData = null;
  127. m_IsLoca = false;
  128. }
  129. }