1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.UI;
- public class SingleMaterialItem : MonoBehaviour
- {
- public event Action<MaterialObl, bool> OnSelectMaterial;
- private Button m_Btn;
- private Image m_Icon;
- private Text m_Name;
- private MaterialObl m_Data;
- private bool m_IsLocal;
- private void Awake()
- {
- m_Btn = GetComponent<Button>();
- m_Btn.onClick.AddListener(OnClickBtn);
- m_Icon = transform.Find("Image").GetComponent<Image>();
- m_Name = transform.Find("Name").GetComponent<Text>();
- }
- private void OnClickBtn()
- {
- if (OnSelectMaterial != null)
- {
- OnSelectMaterial(m_Data, m_IsLocal);
- }
- }
- public void SetData(MaterialObl material, bool islocal)
- {
- m_Data = material;
- m_IsLocal = islocal;
- if (m_IsLocal)
- {
- CalLocaldata();
- }
- else
- {
- CalUpdateData();
- }
- }
- private void CalLocaldata()
- {
- m_Name.text = m_Data.name;
- m_Icon.sprite = ResMgr.Instance.Load<Sprite>(m_Data.icon);
- }
- private void CalUpdateData()
- {
- DownloadData data = new DownloadData();
- string filename = Path.GetFileName(m_Data.icon);
- data.name = filename;
- data.type = 1;
- data.downloadPath = m_Data.icon;
- data.localSavePath = DownloadManager.Instance.LocaDataPath + "/Icon/" + filename;
- data.updateTime = m_Data.updateTime;
- if (!string.IsNullOrWhiteSpace((data.downloadPath)))
- {
- DownloadManager.Instance.LoadMap(data, m_Icon, (tex) =>
- {
- Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
- m_Icon.sprite = sprite;
- });
- }
- m_Name.text = string.IsNullOrWhiteSpace(m_Data.name) ? "" : m_Data.name;
- }
- }
|