123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class UIAddMaterialPanel : UIPanelBase
- {
- public event Action OnClickAddMatBtn;
- private Button m_UCBtn;
- private Button m_TICBtn;
- private GameObject m_LocalView;
- private GameObject m_UpLoadView;
- private Button m_ADDBtn;
- private Button m_CloseBtn;
- private GameObject m_ItenPrefab;
- private Transform m_LocalItemParent;
- private Transform m_UpLoadItemParent;
- private MaterialObl m_SelectData;
- private bool m_IsLoca;
- public EditorPanel EditorPanel { get; set; }
- private void Awake()
- {
- m_UCBtn = transform.Find("Top/UCBtn").GetComponent<Button>();
- m_UCBtn.onClick.AddListener(onClickUCBtn);
- m_TICBtn = transform.Find("Top/TicBtn").GetComponent<Button>();
- m_TICBtn.onClick.AddListener(OnClickTicBtn);
- m_LocalView = transform.Find("MaterialElenemt/LocalView").gameObject;
- m_UpLoadView = transform.Find("MaterialElenemt/UpLoadView").gameObject;
- m_ADDBtn = transform.Find("ADDBtn").GetComponent<Button>();
- m_ADDBtn.onClick.AddListener(OnClickAddBtn);
- m_CloseBtn = transform.Find("CloseBtn").GetComponent<Button>();
- m_CloseBtn.onClick.AddListener(OnClickCloseBtn);
- m_ItenPrefab = transform.Find("SingleMaterial").gameObject;
- m_LocalItemParent = transform.Find("MaterialElenemt/LocalView/Viewport/LocalContent");
- m_UpLoadItemParent = transform.Find("MaterialElenemt/UpLoadView/Viewport/UpLoadContent");
- }
- public void Init()
- {
- m_LocalView.SetActive(true);
- m_UpLoadView.SetActive(true);
- CreateUpLoadDataUI();
- CreateLocalDataUI();
- m_UpLoadView.SetActive(false);
- gameObject.SetActive(false);
- }
- private void onClickUCBtn()
- {
- m_LocalView.gameObject.SetActive(true);
- m_UpLoadView.gameObject.SetActive(false);
- }
- private void OnClickTicBtn()
- {
- m_LocalView.gameObject.SetActive(false);
- m_UpLoadView.gameObject.SetActive(true);
- }
- private void OnClickAddBtn()
- {
- if (m_SelectData != null && GameManager.Instance.IsRuning)
- {
- GameManager.Instance.AddMaterial(m_SelectData);
- m_SelectData = null;
- m_IsLoca = false;
- if (OnClickAddMatBtn != null)
- {
- OnClickAddMatBtn();
- }
- }
- }
- private void OnClickCloseBtn()
- {
- EditorPanel.ChangeShowUI(true);
- }
- private void CreateUpLoadDataUI()
- {
- var materialsData = DataManager.Instance.AllMaterials;
- foreach (string item in materialsData.Keys)
- {
- var data = materialsData[item];
- for (int i = 0; i < data.Count; i++)
- {
- var mat = data[i];
- var obj = Instantiate(m_ItenPrefab, m_UpLoadItemParent, false);
- obj.SetActive(true);
- obj.transform.localScale = new Vector3(1, 1, 1);
- obj.transform.localRotation = Quaternion.identity;
- var matitem = obj.AddComponent<SingleMaterialItem>();
- matitem.OnSelectMaterial += OnSelectMat;
- matitem.SetData(mat, false);
- }
- }
- }
- private void CreateLocalDataUI()
- {
- string str = "Template/Texture/Dir_";
- string[] names = { "前进", "右", "左", "掉头", "右转", "左转" };
- for (int i = 0; i < 6; i++)
- {
- string path = str + i.ToString();
- var obj = Instantiate(m_ItenPrefab, m_LocalItemParent, false);
- obj.SetActive(true);
- obj.transform.localScale = new Vector3(1, 1, 1);
- obj.transform.localRotation = Quaternion.identity;
- var item = obj.AddComponent<SingleMaterialItem>();
- item.OnSelectMaterial += OnSelectMat;
- MaterialObl material = new MaterialObl();
- material.icon = path;
- material.name = names[i];
- material.type = 1;
- material.materialList = new List<MaterialObjValue>();
- MaterialObjValue value = new MaterialObjValue();
- value.DownloadPath = path;
- value.name = "";
- value.type = ((int)MaterialType.LocaImage).ToString();
- value.ObjectTransform = new ObjectTransform();
- material.materialList.Add(value);
- item.SetData(material, true);
- }
- }
- private void OnSelectMat(MaterialObl material, bool islocal)
- {
- m_SelectData = material;
- m_IsLoca = islocal;
- }
- private void OnDisable()
- {
- m_SelectData = null;
- m_IsLoca = false;
- }
- }
|