}//ClearUI() /// <summary> /// Add a new screen. /// </summary> /// <value>The screen to add.</value> public void AddScreen(UIScreen screen) { Log.Debug("Add screen: <color=yellow>"+screen.Name+"</color>"); if(screens.ContainsKey(screen.Name)) { throw new System.Exception("This screen already exist: <color=cyan>" + screen.name+"</color>"); } //screen.SetActive(false); screens.Add(screen.Name, screen); }//AddScreen()
}//ClearScreens() /// <summary> /// Activate a screen by name. /// This function will deactivat old screen and activate the new one. /// It will also send a notification to screenChanged(old, new) if any delegates is set. /// </summary> /// <param name="screenName">The name of the screen.</param> public UIScreen ActivateScreen(string screenName) { Log.Info("Activate screen:<color=yellow>"+screenName+"</color> leaving:"+activeScreen); //Log.Assert(screens.ContainsKey(screenName), // "No screen "+screenName+" registered in UIManager!"); // if(tooltip) tooltip.Hide(); if(!screens.ContainsKey(screenName)) { //try to add it from file string path = configResources + "UI/" + screenName; Log.Debug("Screen not yet exist, create it from file:"+path); LoadResources(path, uiParent); } UIScreen oldScreen = activeScreen; if(oldScreen != null) oldScreen.gameObject.SetActive(false); //ClearUI(UIType.Image); //ClearUI(UIType.Button); activeScreen = screens[screenName]; if(activeScreen != null) { activeScreen.gameObject.SetActive(true); } else { Log.Warning("??????? Where is this screen:"+screenName); } //send event about the change gpm.Event("SCREEN", "ENTER", screenName); return activeScreen; }//ActivateScreen()
//------------------------------------------------------------------------------ /// <summary> /// Event handler to process Screen events and re-register buttons. /// </summary> public void ScreenChanged(UIScreen oldScreeen, UIScreen newScreen) { if(newScreen != null) { //reenable each, so they on OnEnable() will do the registration foreach(GameObject child in childrens) { child.SetActive(false); child.SetActive(true); } } }
// test function to notify us when screen changes public void notifyScreenChanged(UIScreen oldScreen, UIScreen newScreen) { string tmp = (oldScreen != null) ? oldScreen.Name : "NONE"; Debug.Log("Swtich screen <color=cyan>"+tmp+" -> "+newScreen.Name+"</color>"); }
/// <summary> /// Reset the slots after every screen change, /// This will make sure we have a valid state /// </summary> public void ScreenChanged(UIScreen oldScreeen, UIScreen newScreen) { if(gameObject.active && newScreen != null) { ResetSlots(activePage); } }
/// <summary> /// Re Init the button on screen change. /// This will make sure we have a valid button after screen /// has been changed. /// In case the button is disabled, this function will do nothing. /// </summary> public void ScreenChanged(UIScreen oldScreeen, UIScreen newScreen) { //// Log.Info(" ---------------------------------------------- ##################### screen:"+newScreen); if(gameObject.active && newScreen != null) { ActivateAll(false); //ActivateAll(true); } }