SChooseItem.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class SChooseItem : MonoBehaviour
  7. {
  8. /// <summary>
  9. /// 当选择场景时触发事件
  10. /// </summary>
  11. public event Action<SceneValue, bool> OnSelectScene;
  12. private Text m_SceneNameT;
  13. private Image m_SceneImage;
  14. private Toggle m_Toggle;
  15. private int m_ID;
  16. private SceneValue m_SceneData;
  17. public int ID
  18. {
  19. get { return m_ID; }
  20. set { m_ID = value; }
  21. }
  22. public SceneValue SceneData
  23. {
  24. get { return m_SceneData; }
  25. set { m_SceneData = value; }
  26. }
  27. void Awake()
  28. {
  29. m_Toggle = transform.Find("Toggle").GetComponent<Toggle>();
  30. m_SceneImage = transform.Find("Scene").GetComponent<Image>();
  31. m_SceneNameT = m_Toggle.transform.Find("Label").GetComponent<Text>();
  32. m_Toggle.onValueChanged.AddListener(OnToggleValueChanged);
  33. }
  34. private void OnToggleValueChanged(bool b)
  35. {
  36. if (OnSelectScene != null)
  37. {
  38. OnSelectScene(m_SceneData, b);
  39. }
  40. }
  41. public void Init()
  42. {
  43. m_SceneNameT.text = m_SceneData.name;
  44. }
  45. }