//This function returns the data of the active boxes public UIBox[] GetActiveBoxData() { //Create a new array the size of the active boxes list UIBox[] returnArray = new UIBox[activeBoxes.Count]; //Loop through all the active boxes for (int i = 0; i < activeBoxes.Count; i++) { //Add their data to the array returnArray [i] = activeBoxes [i].boxData; } //Return the array return(returnArray); }
//Handles adding listenerd to buttons on boxes public void AddButtonListener(Button b, UIBox box, UIButton button, int index) { b.onClick.AddListener(() => { box.buttons[index].clickCallback(box, button); }); }
//Handles opening UI boxes void OpenBox(UIBox box) { //We start by trying to retrieve the correct object for the type of box we're showing (If it's a custom type we retrieve it) GameObject objectToShow = box.customTypeResourceName == null || box.customTypeResourceName == "" ? FetchObjectForEnum(box.GetUIType(), false) : FetchCustomObject(box.customTypeResourceName, false); //When then check if we loaded a box if (!objectToShow) { //If we haven't, show an error and exit the function Debug.LogError("The Box you wanted to spawn cannot be found. This means we either had trouble loading the default boxes or you tried to load a custom box with a wrong name."); return; } //If we did load a box, we check if we're using an underlay, and if it's not already active if (useUnderlay && !underlay.activeSelf) { //If it's not active and we do want to use one, we activate it underlay.SetActive(true); } //We spawn the box onto the box canvas GameObject shownBox = Instantiate(objectToShow, boxCanvas.transform, false); //We change the title and message shownBox.transform.Find("Header").GetComponentInChildren <Text> ().text = box.header; shownBox.transform.Find("Body").Find("Message").GetComponent <Text> ().text = box.body; //This is making a refrence to the Buttons part of the UI Box GameObject buttons = shownBox.transform.Find("Body").Find("Buttons").gameObject; //We check if there are any buttons the user wants to add to the UIBox for (int i = 0; i < box.buttons.Count; i++) { //Creating a refrence to the button we're adding UIButton button = box.buttons [i]; //We create a desired button variable GameObject desiredButton = null; //Here we do a bunch of checks, if we use a different button type, load that if (button.hasDifferentButtonType) { desiredButton = FetchObjectForEnum(button.customButtonType, true); } //If the user wants to use a custom made button, we load that else if (button.hasCustomButtonPrefab) { desiredButton = FetchCustomObject(button.customButtonPrefabName, true); } //Otherwise we just use the UI type of the box it's in else { desiredButton = FetchObjectForEnum(box.GetUIType(), true); } //If there is we spawn a button of the type of the box GameObject spawnedButton = Instantiate(desiredButton, buttons.transform, false); //We change the text of the button to the desired text spawnedButton.GetComponentInChildren <Text> ().text = box.buttons [i].buttonText; //Finally we add a listener to the button AddButtonListener(spawnedButton.GetComponent <Button> (), box, button, i); } //We add the just opened box to the active box list activeBoxes.Add(new BoxDataCombo(shownBox, box)); //If the box-specific callback has been set, we call that too if (box.onOpenedCallback != null) { box.onOpenedCallback(new BoxDataCombo(shownBox, box)); } //And finally we call the callback if there is one if (boxOpenedCallback != null) { boxOpenedCallback(new BoxDataCombo(shownBox, box)); } }
//This function closes a UIBox using a UIBox variable public void CloseBox(UIBox box) { //Again we just call the CloseBox function variant that uses the ID CloseBox(box.id); }
//This function is used to remove a box from the queue by a UIBox variable public void RemoveFromQueue(UIBox box) { //We simply call the other function with the ID of the UIBox variable RemoveFromQueue(box.id); }
//This function is used to add a box to the queue public void AddToQueue(UIBox box) { //We simply add the desired box the the queue list queuedBoxes.Add(box); }
public BoxDataCombo(GameObject BoxObject, UIBox BoxData) { boxObject = BoxObject; boxData = BoxData; }