/// <summary> /// Swicth the scene by sliding its with direction. /// </summary> /// <param name="towardDirection"></param> public void SwitchScene(JCS_2D8Direction towardDirection) { bool valid = CalculatePage(towardDirection); if (!valid) { return; } switch (mUnityGUIType) { case JCS_UnityGUIType.uGUI_2D: UGUISwitchScene(towardDirection); break; case JCS_UnityGUIType.nGUI_3D: NGUISwitchScene(towardDirection); break; } if (afterSceneSwitched != null) { afterSceneSwitched.Invoke(mCurrentPage); } PlaySwitchSceneSound(); }
/// <summary> /// UGUI method switch the panel. /// </summary> /// <param name="towardDirection"> direction to switch scene. </param> private void UGUISwitchScene(JCS_2D8Direction towardDirection) { // get the Screen Width and Screen Height JCS_ScreenSettings ss = JCS_ScreenSettings.instance; float screenWidth = ss.STARTING_SCREEN_WIDTH; float screenHeight = ss.STARTING_SCREEN_HEIGHT; // make a copy of old position Vector3 newScenePosition = Vector3.zero; switch (towardDirection) { case JCS_2D8Direction.TOP: newScenePosition.y += screenHeight; break; case JCS_2D8Direction.BOTTOM: newScenePosition.y -= screenHeight; break; case JCS_2D8Direction.RIGHT: newScenePosition.x += screenWidth; break; case JCS_2D8Direction.LEFT: newScenePosition.x -= screenWidth; break; // 4 corners case JCS_2D8Direction.TOP_LEFT: newScenePosition.y += screenHeight; newScenePosition.x -= screenWidth; break; case JCS_2D8Direction.TOP_RIGHT: newScenePosition.y += screenHeight; newScenePosition.x += screenWidth; break; case JCS_2D8Direction.BOTTOM_RIGHT: newScenePosition.y -= screenHeight; newScenePosition.x += screenWidth; break; case JCS_2D8Direction.BOTTOM_LEFT: newScenePosition.y -= screenHeight; newScenePosition.x -= screenWidth; break; } mPanelHolder.AddForce(newScenePosition); }
/// <summary> /// UGUI method switch the panel. /// </summary> /// <param name="towardDirection"> direction to switch scene. </param> private void UGUISwitchScene(JCS_2D8Direction towardDirection) { // get the Screen Width and Screen Height Vector2 screenSize = GetScreenSize(); float screenWidth = screenSize.x; float screenHeight = screenSize.y; // make a copy of old position Vector3 newScenePosition = Vector3.zero; switch (towardDirection) { case JCS_2D8Direction.TOP: newScenePosition.y += screenHeight; break; case JCS_2D8Direction.BOTTOM: newScenePosition.y -= screenHeight; break; case JCS_2D8Direction.RIGHT: newScenePosition.x += screenWidth; break; case JCS_2D8Direction.LEFT: newScenePosition.x -= screenWidth; break; // 4 corners case JCS_2D8Direction.TOP_LEFT: newScenePosition.y += screenHeight; newScenePosition.x -= screenWidth; break; case JCS_2D8Direction.TOP_RIGHT: newScenePosition.y += screenHeight; newScenePosition.x += screenWidth; break; case JCS_2D8Direction.BOTTOM_RIGHT: newScenePosition.y -= screenHeight; newScenePosition.x += screenWidth; break; case JCS_2D8Direction.BOTTOM_LEFT: newScenePosition.y -= screenHeight; newScenePosition.x -= screenWidth; break; } mPanelHolder.AddForce(newScenePosition); }
/// <summary> /// Calculate the currnet page with DIRECTION. /// </summary> /// <param name="direction"> Page direction. </param> /// <returns> /// Return true, if is under the min/max boundary. /// </returns> private bool CalculatePage(JCS_2D8Direction direction) { Vector2 newPage = mCurrentPage; switch (direction) { case JCS_2D8Direction.TOP: ++newPage.y; break; case JCS_2D8Direction.BOTTOM: --newPage.y; break; case JCS_2D8Direction.RIGHT: ++newPage.x; break; case JCS_2D8Direction.LEFT: --newPage.x; break; // 4 corners case JCS_2D8Direction.TOP_LEFT: ++newPage.y; --newPage.x; break; case JCS_2D8Direction.TOP_RIGHT: ++newPage.y; ++newPage.x; break; case JCS_2D8Direction.BOTTOM_RIGHT: --newPage.y; ++newPage.x; break; case JCS_2D8Direction.BOTTOM_LEFT: --newPage.y; --newPage.x; break; } bool canDo = IsValidPage(newPage); if (canDo) { mCurrentPage = newPage; } return(canDo); }
/// <summary> /// Swicth the scene by sliding its with direction. /// </summary> /// <param name="towardDirection"></param> public void SwitchScene(JCS_2D8Direction towardDirection) { switch (mUnityGUIType) { case JCS_UnityGUIType.uGUI_2D: UGUISwitchScene(towardDirection); break; case JCS_UnityGUIType.nGUI_3D: NGUISwitchScene(towardDirection); break; } }
/// <summary> /// Swicth the scene by sliding its with direction. /// </summary> /// <param name="towardDirection"></param> public void SwitchScene(JCS_2D8Direction towardDirection) { bool valid = CalculatePage(towardDirection); if (!valid) { return; } switch (mUnityGUIType) { case JCS_UnityGUIType.uGUI_2D: UGUISwitchScene(towardDirection); break; case JCS_UnityGUIType.nGUI_3D: NGUISwitchScene(towardDirection); break; } PlaySwitchSceneSound(); }
/*******************************************/ /* Protected Variables */ /*******************************************/ /*******************************************/ /* setter / getter */ /*******************************************/ public void SetDirection(JCS_2D8Direction direction) { this.mDirection = direction; }
//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions public void FollowMouse(JCS_2D8Direction point) { if (mPanelRectTransform == null) { return; } // point we going to pop this dialogue Vector3 showPoint = JCS_Input.MousePositionOnGUILayer(); Vector2 dialogueRect = mPanelRectTransform.sizeDelta; float halfPanelWidth = dialogueRect.x / 2 * mPanelRectTransform.localScale.x; float halfPanelHeight = dialogueRect.y / 2 * mPanelRectTransform.localScale.x;; switch (point) { case JCS_2D8Direction.TOP: showPoint.y -= halfPanelHeight; break; case JCS_2D8Direction.BOTTOM: showPoint.y += halfPanelHeight; break; case JCS_2D8Direction.RIGHT: showPoint.x -= halfPanelWidth; break; case JCS_2D8Direction.LEFT: showPoint.x += halfPanelWidth; break; case JCS_2D8Direction.TOP_LEFT: showPoint.y -= halfPanelHeight; showPoint.x += halfPanelWidth; break; case JCS_2D8Direction.TOP_RIGHT: showPoint.y -= halfPanelHeight; showPoint.x -= halfPanelWidth; break; case JCS_2D8Direction.BOTTOM_LEFT: showPoint.y += halfPanelHeight; showPoint.x += halfPanelWidth; break; case JCS_2D8Direction.BOTTOM_RIGHT: showPoint.y += halfPanelHeight; showPoint.x -= halfPanelWidth; break; } this.mPanelRectTransform.localPosition = showPoint; if (mFitPushScreen) { FitPushScreen(); } }
/// <summary> /// NGUI method to switch panel/scene. /// </summary> /// <param name="towardDirection"> direction to switch scene. </param> private void NGUISwitchScene(JCS_2D8Direction towardDirection) { // get the Screen Width and Screen Height float screenWidth = JCS_Camera.main.CamRectSize.x; float screenHeight = JCS_Camera.main.CamRectSize.y; // make a copy of old position Vector3 newScenePosition = this.transform.position; // apply new position and set to its // position according to the direction // programmer pass in. switch (towardDirection) { case JCS_2D8Direction.CENTER: // do nothing return; // 4 sides case JCS_2D8Direction.TOP: newScenePosition.y += screenHeight; break; case JCS_2D8Direction.BOTTOM: newScenePosition.y -= screenHeight; break; case JCS_2D8Direction.RIGHT: newScenePosition.x += screenWidth; break; case JCS_2D8Direction.LEFT: newScenePosition.x -= screenWidth; break; // 4 corners case JCS_2D8Direction.TOP_LEFT: newScenePosition.y += screenHeight; newScenePosition.x -= screenWidth; break; case JCS_2D8Direction.TOP_RIGHT: newScenePosition.y += screenHeight; newScenePosition.x += screenWidth; break; case JCS_2D8Direction.BOTTOM_RIGHT: newScenePosition.y -= screenHeight; newScenePosition.x += screenWidth; break; case JCS_2D8Direction.BOTTOM_LEFT: newScenePosition.y -= screenHeight; newScenePosition.x -= screenWidth; break; } // set this position to new position // so the camera will follow this object! this.transform.position = newScenePosition; }