void PressToEdge(SlideToEdge Edge, RectTransform currentObject) { //So if we are an edge stage then we should start setting fields float xPos = 0; float yPos = 0; float canvasScale = GetComponentInParent <Canvas>().scaleFactor; RectTransform Mask = Mask_BottomLeft; bool isHorizontal = false; Debug.Log("EDGE IS! : " + Edge.ToString()); //This is for the Y Pos switch (Edge) { case SlideToEdge.Top: case SlideToEdge.TopLeft: case SlideToEdge.TopRight: //yPos = CTR.y + 240 * canvasScale + Mask_BottomLeft.position.y; //StartCoroutine(Align(xPos, yPos, Mask, CurrentMap_TopRight, isHorizontal)); yPos = CTR.y + 240 * canvasScale + Mask_BottomLeft.position.y; //+ Mask_BottomLeft.position.y; StartCoroutine(Align(xPos, yPos, Mask_BottomLeft, CurrentMap_BottomLeft, false)); break; case SlideToEdge.Bottom: case SlideToEdge.BottomLeft: case SlideToEdge.BottomRight: yPos = CBL.y + 240 * canvasScale + Mask_BottomLeft.position.y; StartCoroutine(Align(xPos, yPos, Mask, CurrentMap_TopRight, isHorizontal)); break; case SlideToEdge.Left: case SlideToEdge.Right: case SlideToEdge.NONE: default: CheckPosition(currentObject); //if it doesn't fulfil the requirements and won't move vertically break; } isHorizontal = true; //This is for the X Position switch (Edge) { case SlideToEdge.TopRight: case SlideToEdge.Right: case SlideToEdge.BottomRight: xPos = CTR.x + Mask_BottomLeft.position.x; StartCoroutine(Align(xPos, yPos, Mask, CurrentMap_TopRight, isHorizontal)); break; case SlideToEdge.TopLeft: case SlideToEdge.Left: case SlideToEdge.BottomLeft: xPos = CBL.x + Mask_BottomLeft.position.x; StartCoroutine(Align(xPos, yPos, Mask, CurrentMap_BottomLeft, isHorizontal)); break; case SlideToEdge.Top: case SlideToEdge.Bottom: case SlideToEdge.NONE: default: CheckPosition(currentObject); //if it doesn't fulfil the requirements and won't move Horizontally break; } }
//Set the Left/Bottom and Right/Top boundaries public void SetBounds(RectTransform BottomLeft, RectTransform TopRight, RectTransform currentObject, SlideToEdge Edge) { //StopAllCoroutines(); //Okay so first if the item selected uses the same BOUNDS if (CurrentMap_BottomLeft == BottomLeft && CurrentMap_TopRight == TopRight) { //if it uses the same bounds then we need should check if we're an EDGE stage if (Edge == SlideToEdge.NONE) { //IF we are NOT an edge Type //Then we should check on screen and place ourselves onto it StopCoroutine(MoveScrollPanel()); //StopAllCoroutines(); CheckPosition(currentObject); } else { //IF we ARE an edge type //Then we should attempt to press to edge based on the edge StopAllCoroutines(); PressToEdge(Edge, currentObject); } return; } else { StopAllCoroutines(); float DistanceToNewLeft = CurrentMap_BottomLeft.position.x - BottomLeft.position.x; float DistanceToNewBottom = CurrentMap_BottomLeft.position.y - BottomLeft.position.y; float DistanceToNewRight = CurrentMap_TopRight.position.x - TopRight.position.x; float DistanceToNewTop = CurrentMap_TopRight.position.y - TopRight.position.y; CBL += new Vector3(DistanceToNewLeft, DistanceToNewBottom); CTR += new Vector3(DistanceToNewRight, DistanceToNewTop); /* * Debug.Log("%$@@ SETTING DISTANCES"); * Debug.Log("%$@@ Horizontal | Left : " + DistanceToNewLeft + " | Right : " + DistanceToNewRight); * Debug.Log("%$@@ Horizontal | CBL.x : " + CBL.x + " | CTR.x : " + CTR.x); * Debug.Log("%$@@ Vertical | Bottom : " + DistanceToNewBottom + " | Top : " + DistanceToNewTop); * Debug.Log("%$@@ Horizontal | CBL.y : " + CBL.y + " | CTR.y : " + CTR.y); * * * Debug.Log("%$@@ BOttomLefts | " + Mask_BottomLeft.position.y + " | " + (BottomLeft.position.y) + " | " + CurrentMap_BottomLeft.position.y); * Debug.Log("%$@@ TopRights| " + Mask_TopRight.position.y + " | " + (TopRight.position.y) + " | " + CurrentMap_TopRight.position.y); */ CurrentMap_BottomLeft = BottomLeft; CurrentMap_TopRight = TopRight; if (SlideSpeed.x <= 0 || SlideSpeed.y <= 0) { Debug.LogWarning("SLIDESPEED ERROR:\nX : " + SlideSpeed.x + "\nY : " + SlideSpeed.y); } //float xPos = 0; //float yPos = 0; if (checkLeft()) { //Debug.Log("We need to slide this flush against the left"); float xPos = CBL.x + Mask_BottomLeft.position.x; float yPos = 0; StartCoroutine(Align(xPos, yPos, Mask_BottomLeft, CurrentMap_BottomLeft, true)); //LeftAlign(); } else if (checkRight()) { //Debug.Log("We need to slide this flush against the Right"); float xPos = CTR.x + Mask_BottomLeft.position.x; float yPos = 0; StartCoroutine(Align(xPos, yPos, Mask_TopRight, CurrentMap_TopRight, true)); } if (checkTop()) { //Debug.Log("We need to slide this flush against the Top"); float canvasScale = 1; if (GetComponentInParent <Canvas>() != null) { canvasScale = GetComponentInParent <Canvas>().scaleFactor; } float xPos = 0; float yPos = CTR.y + 240 * canvasScale + Mask_BottomLeft.position.y; //+ Mask_BottomLeft.position.y; Debug.Log("%$@@yPos CTR: " + CTR.y); StartCoroutine(Align(xPos, yPos, Mask_BottomLeft, CurrentMap_BottomLeft, false)); //StartCoroutine(Align(xPos, yPos, Mask_TopRight, CurrentMap_TopRight, false)); //TopAlign(); } else if (checkBot()) { //Debug.Log("We need to slide this flush against the Bottom"); float canvasScale = 1; if (GetComponentInParent <Canvas>() != null) { canvasScale = GetComponentInParent <Canvas>().scaleFactor; } float xPos = 0; float yPos = CBL.y + 240 * canvasScale + Mask_BottomLeft.position.y; Debug.Log("%$@@yPos CBL: " + CBL.y); StartCoroutine(Align(xPos, yPos, Mask_TopRight, CurrentMap_TopRight, false)); //StartCoroutine(Align(xPos, yPos, Mask_BottomLeft, CurrentMap_BottomLeft, false)); //BottomAlign(); } } #region Bool Checks //if the Mask's Left side is Less than the Current map's Right Side //Then we need to slide it so it becomes flush with the left side bool checkLeft() { return(Mask_BottomLeft.position.x < CurrentMap_BottomLeft.position.x); } //If the Mask's right side is Greater than the //Then we need to slide it so it becomes flush with the right side bool checkRight() { return(Mask_TopRight.position.x > CurrentMap_TopRight.position.x); } //Then we need to slide it so it becomes flush with the Top of the mask bool checkTop() { return(Mask_TopRight.position.y > CurrentMap_TopRight.position.y); } bool checkBot() { return(Mask_BottomLeft.position.y < CurrentMap_BottomLeft.position.y); } #endregion }