AnchorBtnItem.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /****************************
  2. summary:
  3. ****************************/
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class AnchorBtnItem : MonoBehaviour,EventObserver
  9. {
  10. private Toggle m_Toggle;
  11. private Image m_Image;
  12. public Text m_Text;
  13. private GameObject m_AnchorObj;
  14. private Anchor m_Anchor;
  15. public GameObject AnchorObj
  16. {
  17. get { return m_AnchorObj; }
  18. set { m_AnchorObj = value; }
  19. }
  20. public Anchor Anchor
  21. {
  22. get { return m_Anchor; }
  23. set { m_Anchor = value; }
  24. }
  25. public void HandleEvent(EventData resp)
  26. {
  27. }
  28. private void Start()
  29. {
  30. EventManager.Instance.Register(this, EventID.EVENT_3);
  31. m_Toggle = GetComponent<Toggle>();
  32. // m_Image = transform.Find("Image").GetComponent<Image>();
  33. m_Text = transform.Find("Name").GetComponent<Text>();
  34. m_Text.text = Anchor.pictureName;
  35. m_Toggle.onValueChanged.AddListener((state) =>
  36. {
  37. if (state)
  38. {
  39. EventData1 data1 = new EventData1(EventID.EVENT_3, AnchorObj);
  40. data1.Send();
  41. }
  42. });
  43. }
  44. public void SetData(GameObject anchorObj ,Anchor anchor)
  45. {
  46. AnchorObj = anchorObj;
  47. Anchor = anchor;
  48. }
  49. }