using System;
using UnityEngine;

public class BackKeyAdd : MyCoroutine
{
    public static bool DontBack;
    Action Act_Back;

    protected virtual void Awake()
    {
    }

    public void Check()
    {
        if (gameObject.activeSelf)
            Set_Off();
    }

    public virtual void Set()
    {
        Act_Back = null;
        Set_On();
    }
    public virtual void Set(Action _actback = null)
    {
        Act_Back = _actback;
        Set_On();
    }
    public virtual void Set(int _id)
    {
        Set();
    }
    protected void Set_BackAction(Action _actback) { Act_Back = _actback; }
    protected void Set_On()
    {
        gameObject.SetActive(true);
        BackKeyMgr.Ins.Add_Back(OnClick_Back);
    }
    protected void Set_Off()
    {
        gameObject.SetActive(false);
        BackKeyMgr.Ins.Del_Back(OnClick_Back);
        Act_Back?.Invoke();
    }

    public virtual void OnClick_Back()
    {
        if (DontBack) return;
        Set_Off();
    }

    public virtual void Set_Chat()
    {
        transform.localPosition = new Vector3(86.4f, 0f);
        BackKeyMgr.Ins.Add_Back(OnClick_ChatBack);
    }

    public virtual void OnClick_ChatBack()
    {
        transform.localPosition = Vector3.left * 600f;
        BackKeyMgr.Ins.Del_Back(OnClick_ChatBack);
    }
}