void Start() { Manager = new UIScreenManager(); Manager.SceneObjects = this; Manager.TransitionDuration = TransitionDuration; foreach (var p in this.Pages) { Manager.RegisteredScreens.Add(p); } if (MenuButton != null) { MenuButton.onClick.AddListener(delegate() { this.Manager.OpenAppMenu(); }); } if (Header != null && Header.BackButton != null) { Header.BackButton.onClick.AddListener(delegate() { this.Manager.Back(); }); } }
public void Awake(){ if(Application.isPlaying){ // Singleton logic if(UIScreenManager.instance == null){ UIScreenManager.instance = this; GameObject.DontDestroyOnLoad(this.gameObject); } else{ GameObject.Destroy(this.gameObject); return; } } }
public void SwitchScreen(UIScreenManager nextScreen, Vector2 direction, float duration) { // Creates a new screen, animates this into the view and animates the current screen out of view // The new screen is now the current screen UIScreenManager nextScreenInstance = Instantiate(nextScreen, transform); nextScreenInstance.Animate(-direction, direction, duration, false, false); currentScreen.Animate(Vector2.zero, direction, duration, true, false); currentScreen = nextScreenInstance; if (currentOverlayScreen != null) { currentOverlayScreen.Animate(Vector2.zero, direction, duration, true, false); } }
private void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); } foreach (GameObject g in Resources.LoadAll("Screens", typeof(GameObject))) { GameObject go = Instantiate(g.gameObject, transform.position, Quaternion.identity) as GameObject; go.transform.SetParent(transform); //go.SetActive(false); go.SetActive(false); screens.Add(go); } }
/// <summary> /// Initializes a new instance of the <see cref="UIScreenController"/> class. /// </summary> /// <param name="uniqueId">Unique identifier.</param> /// <param name="prefab">Prefab.</param> /// <param name="currentObject">Current object.</param> /// <param name="position">Position.</param> public UIScreenController(Service manager, string uniqueId, UIScreenManager prefab, UIScreenManager currentObject, Vector3 position) { myManager = manager; uiUniqueId = uniqueId; uiScreenPrefab = prefab; if (manager.IsLoggedService()) { Debug.LogWarningFormat("Setting screen object to [{0}]", currentObject); } uiScreenObject = currentObject; uiScreenPosition = position; isActive = uiScreenObject != null; if (isActive) { uiScreenObject.uniqueScreenId = uiUniqueId; uiScreenObject.SetPosition(uiScreenPosition); } }
void UpdatePrefabs() { for (int i = 0; i < uiManager.allScreenControllers.Count; i++) { if (uiManager.allScreenControllers[i].uiScreenObject != null) { Object prefab = PrefabUtility.GetCorrespondingObjectFromSource((Object)uiManager.allScreenControllers[i].uiScreenObject); if (prefab != null) { //is a prefab string path = AssetDatabase.GetAssetPath(prefab); UIScreenManager uism = AssetDatabase.LoadAssetAtPath <UIScreenManager>(path); if (uism != null) { uiManager.allScreenControllers[i].uiScreenPrefab = uism; } } } } }
public void Initialize(UIScreenManager scrnMgr, bool isCopy = false) { mUIManager = scrnMgr; mIsduplicate = isCopy; mCanvasGroup = gameObject.GetComponentInChildren <CanvasGroup>(); InteractionsEnabled(false); gameObject.SetActive(false); mIsVisible = false; var list = this.GetComponentsInChildren <CancelTrigger>(true); foreach (var subcancelTrigger in list) { //Debug.Log("subcancelTrigger " + name + " + " + subcancelTrigger + " / " + list.Length + " -- " + submitSelection + " / " + cancelSelection, this.gameObject); if (CancelSelection != null) { subcancelTrigger.SetCancelAction((e) => SelectOrInvokeButton(CancelSelection.gameObject, e)); } } OnInitialize(); }
// Methods // // Use this for initialization void Start () { //GameObject.DontDestroyOnLoad(this.gameObject); /* // If there is an instance, and it's not this game object if (UIScreenManager.Instance != null && UIScreenManager.Instance != this) { GameObject.DestroyImmediate(this.gameObject); return; } */ // Init the manager this.Screens.Clear (); this.Popups.Clear (); this.Dialogs.Clear (); // Destroy old holder that tend to stay in the scene GameObject.DestroyImmediate(GameObject.Find("UI")); // Create a Holder if (this.UIRoot == null) { // Init a UI root object this.UIRoot = new GameObject ("UI"); this.UIRoot.transform.SetParent (this.transform.parent); if(Application.isPlaying){ GameObject.DontDestroyOnLoad (this.UIRoot.transform.root); } // Init the inscene canvas this.inSceneCanvas = GameObject.Instantiate(this.InSceneCanvasPrefab).GetComponent<Canvas>(); this.inSceneCanvas.transform.SetParent(this.UIRoot.transform); // Init a Screen object this.ScreenRoot = new GameObject("Screens"); this.ScreenRoot.transform.SetParent(this.UIRoot.transform); // Init the Popup canvas this.PopupCanvas = new GameObject ("Popups").AddComponent<Canvas> (); this.PopupCanvas.gameObject.AddComponent<CanvasRenderer>(); this.PopupCanvas.gameObject.AddComponent<CanvasScaler>(); this.PopupCanvas.gameObject.AddComponent<Text>().text = " "; this.PopupCanvas.renderMode = RenderMode.ScreenSpaceOverlay; this.PopupCanvas.transform.SetParent (this.UIRoot.transform); this.PopupCanvas.sortingOrder = 10; this.PopupCanvas.pixelPerfect = false; // Init the popup cache this.PopupCache = GameObject.Instantiate<RectTransform>(this.PopupCachePrefab); this.PopupCache.SetParent(this.PopupCanvas.transform); this.PopupCache.offsetMax = Vector2.zero; this.PopupCache.offsetMin = Vector2.zero; this.PopupCache.SetAsFirstSibling(); // Init the dialog canvas this.DialogCanvas = new GameObject ("Dialogs").AddComponent<Canvas>(); this.DialogCanvas.gameObject.AddComponent<CanvasRenderer>(); this.DialogCanvas.gameObject.AddComponent<CanvasScaler>(); this.DialogCanvas.gameObject.AddComponent<Text>().text = " "; this.DialogCanvas.renderMode = RenderMode.ScreenSpaceOverlay; this.DialogCanvas.transform.SetParent (this.UIRoot.transform); this.DialogCanvas.sortingOrder = 20; // Init the dialog cache this.DialogCache = GameObject.Instantiate<RectTransform>(this.DialogCachePrefab); this.DialogCache.SetParent(this.DialogCanvas.transform); this.DialogCache.offsetMax = Vector2.zero; this.DialogCache.offsetMin = Vector2.zero; this.DialogCache.SetAsFirstSibling(); } // Instantiate the Screen prefabs foreach (UIScreen uis in this.ScreensPrefab) { #if UNITY_EDITOR UIScreen screen = ((GameObject)PrefabUtility.InstantiatePrefab(uis.gameObject)).GetComponent<UIScreen>(); #else UIScreen screen = GameObject.Instantiate<UIScreen>(uis); #endif screen.transform.SetParent(this.ScreenRoot.transform); this.Screens.Add(screen); } // Instantiate the popup prefabs foreach (UIPopUp uip in this.PopupsPrefab) { #if UNITY_EDITOR UIPopUp popup = ((GameObject)PrefabUtility.InstantiatePrefab(uip.gameObject)).GetComponent<UIPopUp>(); #else UIPopUp popup = GameObject.Instantiate<UIPopUp>(uip); #endif popup.transform.SetParent(this.PopupCanvas.transform, true); this.Popups.Add(popup); // Don't let Unity put false value in there RectTransform rt = popup.GetComponent<RectTransform>(); rt.offsetMax = Vector2.zero; rt.offsetMin = Vector2.zero; } // Instantiate the dialog prefabs foreach (UIDialog uid in this.DialogsPrefab) { #if UNITY_EDITOR UIDialog dialog = ((GameObject)PrefabUtility.InstantiatePrefab(uid.gameObject)).GetComponent<UIDialog>(); #else UIDialog dialog = GameObject.Instantiate<UIDialog>(uid); #endif dialog.transform.SetParent(this.DialogCanvas.transform, true); this.Dialogs.Add(dialog); // Don't let Unity put false value in there RectTransform rt = dialog.GetComponent<RectTransform>(); rt.offsetMax = Vector2.zero; rt.offsetMin = Vector2.zero; } // Close everything this.CloseAllDialog (); this.CloseAllPopUp (); this.CloseAllScreen (); this.HidePopUp (); this.HideDialog (); // Not in edit mode if (Application.isPlaying) { UIScreenManager.instance = this; this.OpenScreen(this.GetUIScreenByID(this.StartingUIScreenID)); } }
public virtual void AddScreenByName(string objName) { UIScreenManager.GetInstance().AddScreen(objName); }
// Quicker notations public void NextScreen(UIScreenManager nextScreen) { SwitchScreen(nextScreen, new Vector2(-1, 0), duration); }
public void PreviousScreen(UIScreenManager previousScreen) { SwitchScreen(previousScreen, new Vector2(1, 0), duration); }
// ReSharper disable once UnusedMember.Local private void Start() { QualitySettings.vSyncCount = 1; singleton = this; SetScreen(InitialScreen); }
public void DestroyScreen(UIScreenManager toDestroyScreen) { Destroy(toDestroyScreen.gameObject); }
protected void OnDisable() { lastUIScreenManager = uiScreenManager; }
public void SendPresentBottomOverlay(UIScreenManager overlayScreen) { uiManager.PresentBottomOverlay(overlayScreen); }
public void SendNextScreen(UIScreenManager nextScreen) { uiManager.NextScreen(nextScreen); }
public void AddScreenByType <T>() where T : UIScreen { UIScreenManager.GetInstance().AddScreen <T>(); }
/// <summary> /// Switch the specified screen. /// </summary> /// <param name="enable">If set to <c>true</c> enable.</param> /// <param name="doNotDestroy">If set to <c>true</c> do not destroy on deactivation.</param> public bool Switch(bool enable, bool doNotDestroy = false, bool forceDestroy = false) { //Debug.Log("Switching ["+_uiUniqueId+"] to ["+enable+"] GralNotDestroy["+doNotDestroy+"] PartiNotDestroy["+_doNotDestroyOnDeactivation+"]"); bool result = false; if (enable) { if (!isActive) { //Debug.Log("UIScreenObj["+(_uiScreenObject == null)+"] uiPrefab["+(_uiScreenPrefab != null)+"]"); if (uiScreenObject == null && uiScreenPrefab != null) { if (Application.isPlaying) { //Debug.LogWarning("Setting screen object to new instantiate"); // Create uiScreen uiScreenObject = GameObject.Instantiate <UIScreenManager>(uiScreenPrefab); } } if (uiScreenObject != null) { // Init uiScreen uiScreenObject.SetPosition(uiScreenPosition); uiScreenObject.Init(OnScreenStatusChanged); result = true; } } else { //just update if (uiScreenObject != null) { uiScreenObject.UpdateScreen(OnScreenUpdated); } } } else { if (uiScreenObject != null) { if (uiScreenObject.mustShowDebugInfo) { Debug.LogFormat("Switch OFF [{0}] UIScreenObj[{1}] uiPrefab[{2}] destroy[{3}] forceDestroy[{4}]", uiUniqueId, (uiScreenObject != null), (uiScreenPrefab != null), !doNotDestroy, forceDestroy); } if (isActive) { //Deactivate uiScreen uiScreenObject.Deactivate(OnScreenStatusChanged); } if (uiScreenPrefab != null && (!doNotDestroy || forceDestroy)) { //Destroy uiScreen if (Application.isPlaying) { if (!doNotDestroyOnDeactivation || forceDestroy) { GameObject.Destroy(uiScreenObject.CachedGameObject); //Debug.LogWarning("Setting screen object to null"); uiScreenObject = null; } } else { GameObject.DestroyImmediate(uiScreenObject.CachedGameObject); //Debug.LogWarning("Setting screen object to null"); uiScreenObject = null; } } result = isActive; } } isActive = enable; return(result); }
void KeyPressed() { if (Input.anyKey) { // Console if (DebugWindowOpen) { return; } if (controllable) { // Inventory if (Input.GetButtonDown("Inventory")) { UIScreenManager screenManager = FindObjectOfType <UIScreenManager>(); InventoryPanel panel = screenManager.GetComponentInChildren <InventoryPanel>(true); Debug.Assert(panel != null); if (!panel.gameObject.activeInHierarchy) { panel.gameObject.SetActive(true); } else { panel.gameObject.SetActive(false); } } // Inspection else if (Input.GetButtonDown("Inspect")) { Inspect(); } } else { // Conversation if (Input.GetButtonDown("Inspect")) { Talk(); } else { int selection = 0; if (Input.GetKeyDown(KeyCode.Alpha1)) { selection = 1; } else if (Input.GetKeyDown(KeyCode.Alpha2)) { selection = 2; } else if (Input.GetKeyDown(KeyCode.Alpha3)) { selection = 3; } else if (Input.GetKeyDown(KeyCode.Alpha4)) { selection = 4; } if (selection != 0) { Talk(selection); } } } } }
public void SendPreviousScreen(UIScreenManager previousScreen) { uiManager.PreviousScreen(previousScreen); }
public void BackScreen() { UIScreenManager.GetInstance().BackScreen(); }
/// <summary> /// Creates the a new UIScreen manager along with its controller. /// </summary> /// <returns>The new user interface screen manager.</returns> /// <param name="newScreenId">New screen identifier.</param> public GameObject CreateNewUIScreenManager(string newScreenId = "") { if (_isLogged) { Debug.LogFormat(this, "Creating new UISCreen with layer[{0}][{1}]", LayerMask.LayerToName(systemLayer), systemLayer.value); } GameObject go = new GameObject((newScreenId == "" ? GetUniqueId(allScreenControllers.Count) : newScreenId)); go.layer = systemLayer.value; Camera cam = go.AddComponent <Camera>(); if (cam != null) { cam.orthographic = true; cam.orthographicSize = 5; cam.allowHDR = false; cam.useOcclusionCulling = true; cam.clearFlags = CameraClearFlags.Depth; cam.cullingMask = 1 << systemLayer.value; cam.farClipPlane = 200.0f; //add child Canvas GameObject canvasGO = new GameObject("Canvas"); canvasGO.transform.SetParent(go.transform); canvasGO.layer = systemLayer.value; canvasGO.transform.localPosition = Vector3.zero; Canvas canvas = canvasGO.AddComponent <Canvas>(); if (canvas != null) { canvas.renderMode = RenderMode.ScreenSpaceCamera; canvas.worldCamera = cam; canvas.planeDistance = 100; canvas.sortingLayerID = systemLayer.value; CanvasScaler scaler = canvasGO.AddComponent <CanvasScaler>(); if (scaler != null) { scaler.uiScaleMode = canvasScalerMode; scaler.screenMatchMode = canvasScalerScreenMatchMode; scaler.matchWidthOrHeight = canvasMatchModeRange; scaler.referenceResolution = canvasScalerReferenceResolution; scaler.referencePixelsPerUnit = canvasScalerPixelsPerUnit; } GraphicRaycaster raycaster = canvasGO.AddComponent <GraphicRaycaster>(); if (raycaster != null) { raycaster.ignoreReversedGraphics = true; raycaster.blockingObjects = GraphicRaycaster.BlockingObjects.None; } UIScreenManager screenManager = go.AddComponent <UIScreenManager>(); if (screenManager != null) { Vector3 newPosition = CalculateNewPositionInWorld(allScreenControllers.Count); //create controller for this screenManager UIScreenController controller = new UIScreenController(this, go.name, null, screenManager, newPosition); allScreenControllers.Add(controller); } if (addHelpFrameToCreatedScreens && helpFramePrefab != null) { GameObject helpFrame = GameObject.Instantiate(helpFramePrefab); helpFrame.name = helpFramePrefab.name; helpFrame.transform.SetParent(canvasGO.transform); helpFrame.transform.localScale = Vector3.one; RectTransform rect = helpFrame.GetComponent <RectTransform>(); if (rect != null) { rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.one; rect.offsetMin = Vector2.zero; rect.offsetMax = Vector2.zero; } helpFrame.transform.localPosition = Vector3.zero; Text textId = helpFrame.GetComponentInChildren <Text>(); if (textId != null) { textId.text = go.name; } } } } return(go); }
void CreateFromSelected() { if (Selection.gameObjects.Length > 0) { for (int i = 0; i < Selection.gameObjects.Length; i++) { UIScreenManager uism = Selection.gameObjects[i].GetComponent <UIScreenManager>(); if (uism != null) { Undo.RegisterCreatedObjectUndo(uiManager, uiManager.name); PrefabType pType = PrefabUtility.GetPrefabType(uism.gameObject); bool isPrefab = pType == PrefabType.Prefab; UIScreenManager newUIScreenManager = null; //Debug.Log("Selection type ["+pType+"]"); if (isPrefab) { // Debug.Log("Creating screen from prefab reference"); GameObject instancedGO = (GameObject)PrefabUtility.InstantiatePrefab(Selection.gameObjects[i]); if (instancedGO != null) { UIScreenManager instancedUISM = instancedGO.GetComponent <UIScreenManager>(); if (instancedUISM != null) { newUIScreenManager = uiManager.CreateNewUIScreenControllerFromSceneObject(instancedUISM); if (newUIScreenManager == null) //delete newly created object { DestroyImmediate(instancedGO); EditorUtility.DisplayDialog("Cant create.", "For a new UIScreenManager to be registered/created it must have a unique Id.", "Ok"); } } } } else { newUIScreenManager = uiManager.CreateNewUIScreenControllerFromSceneObject(uism); } if (newUIScreenManager != null) { newUIScreenManager.CachedTransform.SetSiblingIndex(uiManager.GetLastScreenSiblingIndex()); Object prefab = PrefabUtility.GetCorrespondingObjectFromSource((Object)newUIScreenManager.gameObject); if (prefab != null) { //is a prefab string path = AssetDatabase.GetAssetPath(prefab); UIScreenManager prefabUIsm = AssetDatabase.LoadAssetAtPath <UIScreenManager>(path); if (prefabUIsm != null) { for (int j = 0; j < uiManager.allScreenControllers.Count; j++) { if (uiManager.allScreenControllers[j].uiUniqueId == newUIScreenManager.uniqueScreenId) { uiManager.allScreenControllers[j].uiScreenPrefab = prefabUIsm; break; } } } } ArrayList sceneViews = UnityEditor.SceneView.sceneViews; if (sceneViews != null) { if (sceneViews.Count > 0) { UnityEditor.SceneView sceneView = (UnityEditor.SceneView)sceneViews[0]; sceneView.AlignViewToObject(newUIScreenManager.transform); } } } } } } }
protected void OnEnable() { uiScreenManager = (UIScreenManager)target; serializedObj = serializedObject; script = MonoScript.FromMonoBehaviour((UIScreenManager)target); }