using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SUIObjectBase : MonoBehaviour
{

    public GameObject _rootPanel;

    public delegate void ClickDelegate(GameObject buttonObject);

    void Awake()
    {
        UI_Awake();
    }

    void Start()
    {
        UI_Start();

        UI_RegisterEvent();
        UI_RefreshInfo();
        UI_BindTouchEvent();
    }

    void Update()
    {
        UI_Update();
    }

    void OnDestroy()
    {
        UI_UnregisterEvent();

        UI_OnDestroy();
    }

    public void BindButtonClick(string gameObjectPathName, ClickDelegate clickFunc)
    {
        Debug.Assert(_rootPanel != null);

        GameObject buttonObject = _rootPanel.transform.Find(gameObjectPathName).gameObject as GameObject;
        UnityEngine.UI.Button buttonControl = buttonObject.GetComponent<UnityEngine.UI.Button>();
        buttonControl.onClick.AddListener(delegate ()
        {
            clickFunc(buttonObject);
        });
    }

    public virtual void UI_Awake() { }
    public virtual void UI_Start() { }
    public virtual void UI_Update() { }
    public virtual void UI_OnDestroy() { }
    public virtual void UI_RegisterEvent() { }
    public virtual void UI_UnregisterEvent() { }
    public virtual void UI_RefreshInfo() { }
    public virtual void UI_BindTouchEvent() { }
}
