SUIObjectBase.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SFramework
  5. {
  6. public class SUIObjectBase : MonoBehaviour
  7. {
  8. public GameObject _rootPanel;
  9. public delegate void ClickDelegate(GameObject buttonObject);
  10. void Awake()
  11. {
  12. UI_Awake();
  13. }
  14. void Start()
  15. {
  16. UI_Start();
  17. UI_RegisterEvent();
  18. UI_RefreshInfo();
  19. UI_BindTouchEvent();
  20. }
  21. void Update()
  22. {
  23. UI_Update();
  24. }
  25. void OnDestroy()
  26. {
  27. UI_UnregisterEvent();
  28. UI_OnDestroy();
  29. }
  30. public GameObject GetSubUI(string subUIName)
  31. {
  32. Debug.Assert(_rootPanel != null);
  33. Transform subUITransform = _rootPanel.transform.Find(subUIName);
  34. Debug.Assert(subUITransform != null, string.Format("GetSubUI Failed For Name : {0}", subUIName));
  35. return subUITransform.gameObject;
  36. }
  37. public void BindButtonClick(string gameObjectPathName, ClickDelegate clickFunc)
  38. {
  39. Debug.Assert(_rootPanel != null);
  40. GameObject buttonObject = _rootPanel.transform.Find(gameObjectPathName).gameObject as GameObject;
  41. UnityEngine.UI.Button buttonControl = buttonObject.GetComponent<UnityEngine.UI.Button>();
  42. buttonControl.onClick.AddListener(delegate ()
  43. {
  44. clickFunc(buttonObject);
  45. });
  46. }
  47. public void BindButtonClick(GameObject buttonObject, ClickDelegate clickFunc)
  48. {
  49. Debug.Assert(_rootPanel != null);
  50. UnityEngine.UI.Button buttonControl = buttonObject.GetComponent<UnityEngine.UI.Button>();
  51. buttonControl.onClick.AddListener(delegate ()
  52. {
  53. clickFunc(buttonObject);
  54. });
  55. }
  56. public virtual void UI_Awake() { }
  57. public virtual void UI_Start() { }
  58. public virtual void UI_Update() { }
  59. public virtual void UI_OnDestroy() { }
  60. public virtual void UI_RegisterEvent() { }
  61. public virtual void UI_UnregisterEvent() { }
  62. public virtual void UI_RefreshInfo() { }
  63. public virtual void UI_BindTouchEvent() { }
  64. }
  65. }