private IEnumerator LoadSceneAsync(SceneProperties _scene) { previousScene = currentScene; currentScene = _scene; LoadingScreenProperties _loadingScreen = null; // if this scene have loading screen if (_scene.isLoadingScreen) { // if is anything in loading screens array if (loadingScreens.Count > 0) { // if scane loading screen indeks is in this array if (_scene.loadingScreenIndex < loadingScreens.Count) { _loadingScreen = loadingScreens[_scene.loadingScreenIndex]; } else // if not then set first loading screen { _loadingScreen = loadingScreens[0]; } } // if this scene is first in game dont fade out from previouse if (previousScene.scene != null) { // if nextscene has loading screen fadeOut from scene FadeOut(_loadingScreen); yield return(new WaitForSeconds(_loadingScreen.fadeOutDuration)); } } // load scene asynch AsyncOperation ao = SceneManager.LoadSceneAsync(_scene.buildIndex, _scene.loadSceneMode); // while loading while (!ao.isDone) { float progress = Mathf.Clamp01(ao.progress / 0.9f); //Debug.Log("Loading progress: " + (progress * 100) + "%"); // if is loading screen then push there progress e.g for progress bars if (_scene.isLoadingScreen) { _loadingScreen.OnLoading(progress); } yield return(null); } // if scene is loaded and has loading screen then FadeIn to scene if (_scene.isLoadingScreen) { FadeIn(_loadingScreen); } // close opened ui when loaded new scene if (_scene.closeAllUIScreenImmediately) { UIManager.Instance.CloseAllUIScreenImmediately(); } UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "LoadSceneAsync", "Scene loaded build index " + _scene.buildIndex + "."); // invoke event on loaded scene (open some new ui or something) _scene.OnSceneLoaded(); }
public override void OnPointerUp(PointerEventData eventData) { if (interactable) { base.OnPointerUp(eventData); actionsOnPointerUp.Action(); isPressed = false; if (!isLongClick) { StopCoroutine("LongClickChecker"); if (actionsOnDoubleClick.IsEnable()) { _clickCount = eventData.clickCount; if (!isCheckerRunning) { StartCoroutine("OneAndDoubleClickChecker"); } } else { //Debug.Log("One Click"); UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIButton", "OnClick", "Button was clicked once."); actionsOnClick.Action(); } } else { isLongClick = false; } } }
public virtual void OpenScreen(object _object = null) { UIDebug.PrintDebug(UIDebug.DebugType.SCREEN, transform, "UIScreen", "OpenScreen", "Open UI Screen."); if (isCustomPosition) { GetComponent <RectTransform>().anchoredPosition = Vector2.zero; } if (onScreenOpen != null) { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UIScreen", "On Screen Open", "Event invoke."); onScreenOpen.Invoke(); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event OnScreenOpen in " + name + ". Error: " + exception.Message); } } if (!_isOpen) { HandleAnimator("Open"); } _isOpen = true; }
public virtual void Open() { if (!isOpen) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UISidePanel", "Open", "Open side panel."); isOpen = true; switch (side) { case 0: // Left StartCoroutine(MoveTo(new Vector2(panel.rect.width, 0f), 1f / speed)); break; case 1: // Top StartCoroutine(MoveTo(new Vector2(0f, -panel.rect.height), 1f / speed)); break; case 2: // Right StartCoroutine(MoveTo(new Vector2(-panel.rect.width, 0f), 1f / speed)); break; case 3: // Bottom StartCoroutine(MoveTo(new Vector2(0f, panel.rect.height), 1f / speed)); break; } } }
public virtual void Close() { if (isOpen) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UISidePanel", "Close", "Close side panel."); isOpen = false; switch (side) { case 0: // Left StartCoroutine(MoveTo(Vector2.zero, 1f / speed)); break; case 1: // Top StartCoroutine(MoveTo(Vector2.zero, 1f / speed)); break; case 2: // Right StartCoroutine(MoveTo(Vector2.zero, 1f / speed)); break; case 3: // Bottom StartCoroutine(MoveTo(Vector2.zero, 1f / speed)); break; } } }
public virtual void OnEndDrag(PointerEventData eventData) { if (interactable) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIDraggable", "OnEndDrag", "End drag."); GetComponent <Canvas>().overrideSorting = false; GetComponent <Canvas>().sortingOrder--; GetComponent <CanvasGroup>().blocksRaycasts = true; draggedObject = null; if (transform.parent == startParent) { transform.position = startPosition; } if (onDropped != null) { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UIDraggable", "On Dropped", "Event invoke."); onDropped.Invoke(); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event OnDropped in " + name + ". Error: " + exception.Message); } } } else { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIDraggable", "OnEndDrag", "Can not end drag because element is not interactable."); } }
//------------------------------------------------------------------------ public void OnBeginDrag(PointerEventData aEventData) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UICarouselPanel", "OnBeginDrag", "Begin drag carousel panel."); // if currently lerping, then stop it as user is draging _lerp = false; // not dragging yet _dragging = false; }
public void OnChange() { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UIDropArea", "On Change", "Event invoke."); onChanged.Invoke(); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event OnChanged in " + name + ". Error: " + exception.Message); } }
private void FadeOut(LoadingScreenProperties _loadingScreen) { if (_loadingScreen.canvasGroup) { UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "FadeOut", "Fade out loading screen " + _loadingScreen.canvasGroup.name + "."); StartCoroutine(_FadeOut(_loadingScreen)); } else { Debug.LogWarning("Cant fade out loading screen because is not selected"); } }
public void OnBeginDrag(PointerEventData eventData) { if (interactable) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIRadialSlider", "OnBeginDrag", "Slider handle begin drag."); offsetDrag = handle.anchoredPosition - eventData.position; } else { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIRadialSlider", "OnBeginDrag", "Can not begin drag radial slider because is not interactable."); } }
public void UnloadScene(int _buildIndex) { Debug.Log("UnloadScene: " + Time.time); if (_buildIndex < sceneProperties.Count) { UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "UnloadScene", "Start unloading scene build index " + _buildIndex + "."); StartCoroutine(UnloadSceneAsync(_buildIndex)); } else { UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "UnloadScene", "Can not unload scene " + _buildIndex + " because it is not added to build settings."); } }
private void GoToUIScreen() { if (uiScreen != null) { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, null, "Action", "GoToUIScreen", "Go to screen " + uiScreen.name + "."); UIManager.Instance.GoToScreen(uiScreen); } else { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, null, "Action", "GoToUIScreen", "Go to previous screen."); UIManager.Instance.GoToPreviuosScreen(); } }
public void UnloadPreviousScene() { Debug.Log("UnloadPreviousScene: " + Time.time); if (previousScene != null) { UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "UnloadPreviousScene", "Start unloading previous scene build index " + previousScene.buildIndex + "."); StartCoroutine(UnloadPreviousSceneAsync()); } else { UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "UnloadPreviousScene", "Can not unload previous scene because history is empty."); } }
public void LoadScene(SceneProperties sceneProperties) { if (sceneProperties.buildIndex <= SceneManager.sceneCountInBuildSettings && sceneProperties.buildIndex >= 0) { //Debug.Log("Scene to load: " + sceneProperties.scene.name); UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "LoadScene", "Start loading scene build index " + sceneProperties.buildIndex + "."); StartCoroutine(LoadSceneAsync(sceneProperties)); } else { Debug.LogWarning("Can not load scene " + sceneProperties.scene.name + " because it is not added to Build Settings."); } }
public virtual void OnDrop(PointerEventData eventData) { if (UIDraggable.draggedObject && interactable) { if (!item) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIDropArea", "OnDrop", "Dropped element to area."); // call OnChange to UIDropArea from which UIDragable was pull out UIDraggable.draggedObject.transform.parent.SendMessage("OnChange", SendMessageOptions.DontRequireReceiver); // call OnChange to UIDragable UIDraggable.draggedObject.OnChanged(); // call OnChange to this UIDropArea OnChange(); // drop to UIDropArea UIDraggable.draggedObject.transform.SetParent(transform); } else if (item.replaceable && item.interactable) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIDropArea", "OnDrop", "Dropped element to area and replace with " + item.name); // call OnChange to UIDropArea from which UIDragable was pull out UIDraggable.draggedObject.transform.parent.SendMessage("OnChange", SendMessageOptions.DontRequireReceiver); // call OnChange to UIDragable UIDraggable.draggedObject.OnChanged(); // call OnChange to this UIDropArea OnChange(); // take item from this UIDropArea and replace it item.transform.SetParent(UIDraggable.draggedObject.transform.parent); // drop to UIDropArea UIDraggable.draggedObject.transform.SetParent(transform); } else { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIDropArea", "OnDrop", "Can not drop to this area because there is not interactable UIDraggable."); } } else { if (!interactable) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIDropArea", "OnDrop", "Can not drop to this area because is not interactable."); } if (UIDraggable.draggedObject == null) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIDropArea", "OnDrop", "Can not drop to this area because dropped element do not have UIDraggable script."); } } }
IEnumerator LongClickChecker() { yield return(new WaitForSeconds(0.5f)); if (isPressed) { if (actionsOnLongClick.IsEnable()) { //Debug.Log("Long Click"); UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIButton", "OnLongClick", "Button was long pressed."); isLongClick = true; actionsOnLongClick.Action(); } } }
private void InvokeEvent() { if (unityEvent != null) { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, null, "Action", "InvokeEvent", "Event invoke."); unityEvent.Invoke(); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event Action. Error: " + exception.Message); } } }
private void OnSceneUnloadedEvent(Scene _scene) { if (onSceneUnloaded != null) { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UISceneManager", "On Scene Unloaded", "Event invoke."); onSceneUnloaded.Invoke(_scene); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event onSceneUnloaded. Error: " + exception.Message); } } }
public void GoToPreviuosScreen() { // if history is not empty then if (_historyStack.Count > 0) { // set last index int lastIndex = _historyStack.Count - 1; UIDebug.PrintDebug(UIDebug.DebugType.SCREEN, transform, "UIManager", "GoToPreviuosScreen", "Go to previous UI Screen " + _historyStack[lastIndex].name + ","); // call metod GoToScreen with last closed screen GoToScreen(_historyStack[lastIndex]); // remove all index from history array from "lastIndex" to end of array // Called GoToScreen add new screens to history then we have to remove from lastIndex to end of array _historyStack.RemoveRange(lastIndex, _historyStack.Count - lastIndex); } else { UIDebug.PrintDebug(UIDebug.DebugType.SCREEN, transform, "UIManager", "GoToPreviuosScreen", "Can not go to previous UI Screen because history stack is empty."); } }
protected virtual void OnClose() { if (closeOnBackground) { background.raycastTarget = false; } if (onClose != null) { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UISidePanel", "On Close", "Event invoke."); onClose.Invoke(); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event onClose in " + name + ". Error: " + exception.Message); } } }
public void OnChangedValue() { RedrawSlider(); RedrawText(); RedrawHandle(); if (onValueChanged != null) { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UIRadialSlider", "On Changed Value", "Event invoke."); onValueChanged.Invoke(Value); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event onValueChanged in " + name + ". Error: " + exception.Message); } } }
IEnumerator OneAndDoubleClickChecker() { isCheckerRunning = true; yield return(new WaitForSeconds(0.25f)); if (_clickCount >= 2) { //Debug.Log("Double Click"); UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIButton", "OnDoubleClick", "Button was clicked twice."); actionsOnDoubleClick.Action(); } else if (_clickCount == 1) { //Debug.Log("One Click 2"); UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UIButton", "OnClick", "Button was clicked once."); actionsOnClick.Action(); } isCheckerRunning = false; }
private void LoadScene() { if (UISceneManager.Instance) { if (buildIndex == -100) { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, null, "Action", "LoadScene", "Go to previous scene."); UISceneManager.Instance.LoadPreviousScene(); } else { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, null, "Action", "LoadScene", "Go to scene (buildindex " + buildIndex + ")."); UISceneManager.Instance.LoadScene(buildIndex); } } else { Debug.LogWarning("Can not load scene because UI Scene Manager instance not found."); } }
//------------------------------------------------------------------------ public void OnEndDrag(PointerEventData aEventData) { if (isOneSwipeMove) { // how much was container's content dragged float difference; if (isHorizontal) { difference = _startPosition.x - content.anchoredPosition.x; } else { difference = -(_startPosition.y - content.anchoredPosition.y); } // test for fast swipe - swipe that moves only +/-1 item if (Time.unscaledTime - _timeStamp < fastSwipeThresholdTime && Mathf.Abs(difference) > fastSwipeThresholdDistance && Mathf.Abs(difference) < _fastSwipeThresholdMaxLimit) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UICarouselPanel", "OnEndDrag", "Fast swipe - move by once."); if (difference > 0) { NextScreen(); } else { PreviousScreen(); } } else { // if not fast time, look to which page we got to UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UICarouselPanel", "OnEndDrag", "Fast swipe - scroll carousel freely"); LerpToPage(GetNearestPage()); } } _canSnap = true; _dragging = false; }
public virtual void CloseScreenImmediately() { UIDebug.PrintDebug(UIDebug.DebugType.SCREEN, transform, "UIScreen", "CloseScreenImmediately", "Close UI Screen immediatyly."); if (onScreenClose != null) { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UIScreen", "On Screen Close", "Event invoke."); onScreenClose.Invoke(); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event OnScreenClose in " + name + ". Error: " + exception.Message); } } if (_isOpen) { HandleAnimator("CloseImmediately"); } _isOpen = false; }
//------------------------------------------------------------------------ public void LerpToPage(int aPageIndex) { aPageIndex = Mathf.Clamp(aPageIndex, 0, _pageCount - 1); _lerpTo = _pagePositions[aPageIndex]; _lerp = true; _currentPage = aPageIndex; SetIcon(); if (onSelected != null) { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UICarouselPanel", "On Selected", "Event invoke."); onSelected.Invoke(aPageIndex); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event onSelected. Error: " + exception.Message); } } //GameManager.Instance.guiManager.panelMainMenu.GetComponent<MainMenuGUI>().OnSelected(_currentPage); }
//------------------------------------------------------------------------ private int GetNearestPage() { // based on distance from current position, find nearest page Vector2 currentPosition = content.anchoredPosition; _canSnap = false; float distance = float.MaxValue; int nearestPage = _currentPage; for (int i = 0; i < _pagePositions.Count; i++) { float testDist = Vector2.SqrMagnitude(currentPosition - _pagePositions[i]); if (testDist < distance) { distance = testDist; nearestPage = i; } } UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "UICarouselPanel", "GetNearestPage", "Go to page " + nearestPage + "."); return(nearestPage); }
public void LoadPreviousScene() { UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "LoadPreviousScene", "Start loading previous scene build index " + previousScene.buildIndex + "."); LoadScene(previousScene); }
public void OnEndDrag(PointerEventData eventData) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "SwipeBar", "OnEndDrag", "End drag swipe area."); sidePanel.OnEndDragSwipeBar(); }
private Vector2 offsetDrag; // offset from center of swipeBar to begin drag public void OnBeginDrag(PointerEventData eventData) { UIDebug.PrintDebug(UIDebug.DebugType.UI, transform, "SwipeBar", "OnBeginDrag", "Begin drag swipe area."); offsetDrag = GetComponent <RectTransform>().anchoredPosition - eventData.position; }