using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; // Overwrite ControlsletterManager & PrologueLetterMoanager // to extend this public class WindowController : MonoBehaviour, IOpenable { public virtual string PANEL_NAME => "Wizard.Letter"; public GameObject Window; public GameObject _panel; // Start is called before the first frame update void Start() { } public void OpenPanel() { _panel = Instantiate(Window, GameObject.FindGameObjectWithTag("GUI").transform); _panel.transform.Find("Button").GetComponent().onClick.AddListener(DestroyPanel); } public void DestroyPanelWithSaving() { Destroy(_panel); PlayerPrefs.SetInt(GetKeyName(), 1); } public void DestroyPanel() { Destroy(_panel); } // true if is opened public bool IsOpened() { return _panel != null; } public bool WasDisplayed() { return PlayerPrefs.HasKey(GetKeyName()) ? Convert.ToBoolean(PlayerPrefs.GetInt(GetKeyName())) : false; } public string GetKeyName() { return PANEL_NAME + ".WhereDisplayed"; } } public interface IOpenable { public void OpenPanel(); public void DestroyPanel(); public bool IsOpened(); public bool WasDisplayed(); }