/// <summary> /// DO not use directly! Gets called from the Instance of menu! /// </summary> private void CloseGivenMenu(KAU.MenuSystem.Menu instance) { if (instance.DestroyWhenClosed) { // Addressables.ReleaseInstance(instance.gameObject); Destroy(instance.gameObject); } else { instance.gameObject.SetActive(false); instance.isInitialized = false; } // Re-activate top menu // If the re-activated menu is an overlay we need to activate the menu under it for (int i = MenuStack.Count - 1; i >= 0; i--) { if (MenuStack[i] == null) { continue; } MenuStack[i].gameObject.SetActive(true); // disable all till another DisableMenusUnderneath if (MenuStack[i].DisableMenusUnderneath) { break; } } }
/// <summary> /// DO not use directly! Gets called from the Instance of menu! /// </summary> public void CloseMenu(KAU.MenuSystem.Menu intance) { if (intance.IsPausing) { PausedMenus--; } _paused = PausedMenus > 0; intance.onMenuAction?.Invoke(); if (MenuStack.Count == 0) { CloseGivenMenu(intance); return; } MenuStack.Remove(intance); CloseGivenMenu(intance); }
/// <summary> /// DO not use directly! Gets called from the Instance of menu! /// </summary> public void OpenMenu(KAU.MenuSystem.Menu instance) { if (instance.IsPausing) { PausedMenus++; } _paused = PausedMenus > 0; instance.onMenuAction?.Invoke(); // De-activate top menu if (instance.DisableMenusUnderneath) { for (int i = MenuStack.Count - 1; i >= 0; i--) { if (MenuStack[i] == null) { continue; } MenuStack[i].gameObject.SetActive(false); // disable all till another DisableMenusUnderneath if (MenuStack[i].DisableMenusUnderneath) { break; } } } MenuStack.Add(instance); int sortOrderForTops = 0; int odrinaly = 0; for (int i = 0; i < MenuStack.Count; i++) { if (MenuStack[i] == null) { MenuStack.RemoveAt(i); i--; continue; } if (!MenuStack[i].AlwaysOnTop) { odrinaly++; } else { sortOrderForTops++; } } odrinaly++; sortOrderForTops += odrinaly; if (instance.AlwaysOnTop) { // Always on top instance.MyCanvas.sortingOrder = sortOrderForTops; } else { // Ordinary instance.MyCanvas.sortingOrder = odrinaly; } Debug.LogWarning(" Sort : " + instance.MyCanvas.sortingOrder + " on : " + instance.gameObject); instance.isInitialized = true; }