usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.UI;publicclassBattleUIController : MonoBehaviour{publicstaticList<Window> openWindows;//Transient Windows are windows that will close should a significant event happenpublicstaticList<Window> transientWindows;//A dummy objectpublicstaticWindow HighestWindow;//Prefab of the back buttonGameObject backButton;BattleController BC;Window focusedWindow;publicvoidinitialize(BattleControllerBaCo){BC=BaCo;BattleUIController.openWindows=newList<Window>();BattleUIController.transientWindows=newList<Window>();backButton=Resources.Load<GameObject>("UIElements/uI_BackButton_Panel");}//Makes it so that only one window is interactablepublicvoidlockFocus(WindowfocusedWindow){foreach(WindowwindowinopenWindows){if (window.getAffectedByFocus() &&focusedWindow!=window){foreach (Buttonbuttoninwindow.GetComponentsInChildren<Button>()){button.interactable=false;}}}}//Inverse of lock focuspublicvoidreleaseFocus(){foreach (WindowwindowinopenWindows.ToArray()){foreach (Buttonbuttoninwindow.GetComponentsInChildren<Button>()){button.interactable=true;}}}//This is to just cleanup the lists incase windows get closedpublicvoidcheckForDeleted(){foreach(WindowwindowinopenWindows.ToArray()){if (window==null){openWindows.Remove(window);}}foreach(WindowwindowintransientWindows.ToArray()){if(window==null){transientWindows.Remove(window);}}}publicvoidcloseWindow(Windowwindow){lockFocus(window.getParent());}publicBattleUIController(){}publicvoidcloseWindow(GameObjectitem){GameObject.Destroy(item);}publicvoidcloseAllTransient(){foreach(WindowwindowintransientWindows){//This checks if it's null, please don't be dumb and remove this, you will regret itif(window)window.closeWindow();}}publicGameObjectopenWindow(stringwindowName,booltransient=true,stringgameObjectName="Canvas",boolhasBackButton=true){GameObjectgo=GameObject.Instantiate(Resources.Load<GameObject>("UIElements/"+windowName),GameObject.Find(gameObjectName).transform);if (transient){BattleUIController.transientWindows.Add(go.GetComponent<Window>());}openWindows.Add(go.GetComponent<Window>());if (hasBackButton){GameObject.Instantiate(backButton,go.transform).GetComponentInChildren<BackButtonController>().initialize(this);}returngo;}publicvoidmakeActive(booltoggle){checkForDeleted();foreach(WindowwindowinopenWindows){window.enabled=toggle;}}}//An abstract class. //Note: this should be abstracted more out. Elements such as "ability" and "attack attempt" are specific// to certain implmemetnations. publicabstractclassWindow : MonoBehaviour{bool affectdByFocus =true;List<Window> childrenWindows;Window parentWindow;protectedBattleCharacterObject character =null;protectedAttackAttempt attackAttempt;protectedAbility ability;publicWindowgetParent(){returnparentWindow;}publicboolgetAffectedByFocus(){returnaffectdByFocus;}publicvoidinitialize(Windowparent){parentWindow=parent;childrenWindows=newList<Window>();}publicvoidinitialize(Windowparent,BattleCharacterObjectchara){parentWindow=parent;character=chara;childrenWindows=newList<Window>();}publicvoidinitialize(Windowparent,AttackAttemptaa){attackAttempt=aa;parentWindow=parent;childrenWindows=newList<Window>();}publicvoidinitialize(Windowparent,Abilityabilty){ability=abilty;parentWindow=parent;childrenWindows=newList<Window>();}//It needs to be recursive, because the childen may not necissarily be children in unitylandpublicvirtualvoidcloseWindow(){try{GameObject.Destroy(this.gameObject);}catch(MissingReferenceExceptione){}if (!(childrenWindowsisnull)){if (childrenWindows.Count>0){foreach (WindowchildinchildrenWindows){child.closeWindow();}}}}}