UIAddMaterialPanel.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. public static List<GameObject> pfablist = new List<GameObject>();
  74. private void CreateUpLoadDataUI()
  75. {
  76. var materialsData = DataManager.Instance.AllMaterials;
  77. foreach (string item in materialsData.Keys)
  78. {
  79. var data = materialsData[item];
  80. for (int i = 0; i < data.Count; i++)
  81. {
  82. var mat = data[i];
  83. var obj = Instantiate(m_ItenPrefab, m_UpLoadItemParent, false);
  84. obj.SetActive(true);
  85. obj.transform.localScale = new Vector3(1, 1, 1);
  86. obj.transform.localRotation = Quaternion.identity;
  87. var matitem = obj.GetComponent<SingleMaterialItem>();
  88. pfablist.Add(obj);
  89. matitem.OnSelectMaterial += OnSelectMat;
  90. matitem.SetData(mat, false);
  91. }
  92. }
  93. }
  94. private void CreateLocalDataUI()
  95. {
  96. string str = "Template/Texture/Dir_";
  97. string[] names = { "前进", "右", "左", "掉头", "右转", "左转" };
  98. for (int i = 0; i < 6; i++)
  99. {
  100. string path = str + i.ToString();
  101. var obj = Instantiate(m_ItenPrefab, m_LocalItemParent, false);
  102. obj.SetActive(true);
  103. obj.transform.localScale = new Vector3(1, 1, 1);
  104. obj.transform.localRotation = Quaternion.identity;
  105. pfablist.Add(obj);
  106. var item = obj.GetComponent<SingleMaterialItem>();
  107. item.OnSelectMaterial += OnSelectMat;
  108. MaterialObl material = new MaterialObl();
  109. material.icon = path;
  110. material.name = names[i];
  111. material.type = 1;
  112. material.materialList = new List<MaterialObjValue>();
  113. MaterialObjValue value = new MaterialObjValue();
  114. value.DownloadPath = path;
  115. value.name = "";
  116. value.type = ((int)MaterialType.LocaImage);
  117. value.ObjectTransform = new ObjectTransform();
  118. material.materialList.Add(value);
  119. item.SetData(material, true);
  120. }
  121. }
  122. private void OnSelectMat(MaterialObl material, bool islocal)
  123. {
  124. m_SelectData = material;
  125. m_IsLoca = islocal;
  126. }
  127. private void OnDisable()
  128. {
  129. m_SelectData = null;
  130. m_IsLoca = false;
  131. }
  132. }