DevicesItemBase.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityGameFramework.Runtime;
  7. public class DevicesItemBase : MonoBehaviour
  8. {
  9. public MachineMessageData data;
  10. private Button itemButton;
  11. public Image burstImage;
  12. RawImage rawImage;
  13. Text titleText;
  14. Text nameText;
  15. private void Start()
  16. {
  17. itemButton = this.GetComponent<Button>();
  18. itemButton.onClick.AddListener(() =>
  19. {
  20. GameMain.Event.Fire( this,ChangeDevicesModelEvent.Create(data));
  21. });
  22. }
  23. public void Init()
  24. {
  25. rawImage = this.transform.Find("RawImage").GetComponent<RawImage>();
  26. titleText = this.transform.Find("Title1").GetComponent<Text>();
  27. nameText = this.transform.Find("Name").GetComponent<Text>();
  28. titleText.text = data.name;
  29. nameText.text = data.typeId;
  30. try
  31. {
  32. Texture2D tex = Resources.Load<Texture2D>("DevicesPic/" + data.modelName);
  33. rawImage.texture = tex;
  34. }
  35. catch (Exception e)
  36. {
  37. Debug.Log(e.Message);
  38. }
  39. }
  40. }