using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using UnityEngine;

public class TestSceneManager : MonoBehaviour
{
    public GameObject testObj;
    void Start()
    {
        Bootstrap.Instance.eventCenter.AddEventListener(Enum_EventType.TestEvent1, TestFunc1);
        Bootstrap.Instance.eventCenter.AddEventListener<int>(Enum_EventType.TestEvent2, TestFunc2);
        Bootstrap.Instance.eventCenter.AddEventListener<string>(Enum_EventType.TestEvent3, TestFunc3);
    }

    void Update()
    {
        if (Input.GetKeyDown("v"))
        {
            Bootstrap.Instance.uiManager.ShowPanel<UI_LoadingPanel>(this, E_UI_Layer.System, (panel) =>
            {
                Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.1f);
                Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "TestScene1", () =>
            {
                Debug.Log("¼ÓÔØ³¡¾°³É¹¦");
                Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.9f);
            });
            });
        }
    }
    public void TestFunc1()
    {
        testObj.GetComponent<MeshRenderer>().material.color = new Color(Random.Range(1, 255f) / 255f, Random.Range(1, 255f) / 255f, Random.Range(1, 255f) / 255f, 1f);
    }
    public void TestFunc2(int idnex)
    {
        Debug.Log($"TestFunc2++{idnex}");
    }
    public void TestFunc3(string info)
    {
        Debug.Log($"TestFunc3++{info}");
    }

    private void OnDisable()
    {
        Debug.Log("OnDisable");
        if (Bootstrap.Instance != null)
        {
            Bootstrap.Instance.eventCenter.RemoveEventListener(Enum_EventType.TestEvent1, TestFunc1);
            Bootstrap.Instance.eventCenter.RemoveEventListener<int>(Enum_EventType.TestEvent2, TestFunc2);
            Bootstrap.Instance.eventCenter.RemoveEventListener<string>(Enum_EventType.TestEvent3, TestFunc3);
        }
    }

}