LAPTOP-OM1V99U2\永远de小亡灵 1 год назад
Родитель
Сommit
d05891c3fd
1 измененных файлов с 64 добавлено и 50 удалено
  1. 64 50
      ActionTowerDefense/Assets/Scripts/CameraController.cs

+ 64 - 50
ActionTowerDefense/Assets/Scripts/CameraController.cs

@@ -62,6 +62,7 @@ public class CameraController : MonoBehaviour
     public bool isChangingViewport;
     public CameraRect cameraRect;
 
+    public float XYRatio = 2.5f;
     private void Start()
     {
         ratio = maxView / (splitDistance - mergeDistance);
@@ -78,7 +79,7 @@ public class CameraController : MonoBehaviour
         //·ÖÆÁ±ä»¯¹ý³Ì
         if (isChangingViewport)
         {
-            time += Time.deltaTime;
+            time += Time.deltaTime * 3;
             ChangeViewport();
         }
 
@@ -120,25 +121,25 @@ public class CameraController : MonoBehaviour
             {
                 if (isSplit)
                 {
-                    if (distanceY < mergeDistance / 2)
+                    if (distanceY < mergeDistance / XYRatio)
                     {
                         CameraSplit(true);
                     }
-                    else if (distanceY > splitDistance / 2)
+                    else if (distanceY > splitDistance / XYRatio)
                     {
-                        if (player0Camera.rect.y == 0)
+                        if (player0Camera.rect.y == 0 && player1Camera.rect.y == 0)
                         {
                             if (player0Pos.y < player1Pos.y)
                             {
                                 if (player0Pos.x < player1Pos.x)
                                 {
                                     targetRotation = Quaternion.Euler(new Vector3(0, 0,
-                                        lineInCamera.transform.rotation.z + 90));
+                                        lineInCamera.transform.rotation.eulerAngles.z + 90));
                                 }
                                 else
                                 {
                                     targetRotation = Quaternion.Euler(new Vector3(0, 0,
-                                        lineInCamera.transform.rotation.z - 90));
+                                        lineInCamera.transform.rotation.eulerAngles.z - 90));
                                 }
 
                                 targetViewport0 = cameraRect.Down;
@@ -151,17 +152,18 @@ public class CameraController : MonoBehaviour
                                 if (player0Pos.x < player1Pos.x)
                                 {
                                     targetRotation = Quaternion.Euler(new Vector3(0, 0,
-                                        lineInCamera.transform.rotation.z - 90));
+                                        lineInCamera.transform.rotation.eulerAngles.z - 90));
                                 }
                                 else
                                 {
                                     targetRotation = Quaternion.Euler(new Vector3(0, 0,
-                                        lineInCamera.transform.rotation.z + 90));
+                                        lineInCamera.transform.rotation.eulerAngles.z + 90));
                                 }
                                 targetViewport0 = cameraRect.Up;
                                 targetViewport1 = cameraRect.Down;
                             }
                             isChangingViewport = true;
+                            time = 0;
                         }
                     }
                     else
@@ -171,11 +173,11 @@ public class CameraController : MonoBehaviour
                 }
                 else
                 {
-                    if (distanceY < mergeDistance / 2)
+                    if (distanceY < mergeDistance / XYRatio)
                     {
                         
                     }
-                    else if (distanceY > splitDistance / 2)
+                    else if (distanceY > splitDistance / XYRatio)
                     {
                         lineInCamera.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
                         if (player0Pos.y < player1Pos.y)
@@ -203,42 +205,56 @@ public class CameraController : MonoBehaviour
             {
                 if (isSplit)
                 {
-                    if(player0Camera.rect.x == 0)
+
+                    if(player0Camera.rect.x == 0 && player1Camera.rect.x == 0)
                     {
-                        if (player0Pos.x < player1Pos.x)
+                        if (distanceY < mergeDistance / XYRatio)
                         {
-                            if (player0Pos.y < player1Pos.y)
+                            if (player0Pos.x < player1Pos.x)
                             {
-                                targetRotation = Quaternion.Euler(new Vector3(0, 0,
-                                    lineInCamera.transform.rotation.z - 90));
+                                if (player0Pos.y < player1Pos.y)
+                                {
+                                    targetRotation = Quaternion.Euler(new Vector3(0, 0,
+                                        lineInCamera.transform.rotation.eulerAngles.z + 90));
+                                }
+                                else
+                                {
+                                    targetRotation = Quaternion.Euler(new Vector3(0, 0,
+                                        lineInCamera.transform.rotation.eulerAngles.z - 90));
+                                }
+
+                                targetViewport0 = cameraRect.Left;
+                                targetViewport1 = cameraRect.Right;
+
+
                             }
                             else
                             {
-                                targetRotation = Quaternion.Euler(new Vector3(0, 0,
-                                    lineInCamera.transform.rotation.z + 90));
+                                if (player0Pos.y < player1Pos.y)
+                                {
+                                    targetRotation = Quaternion.Euler(new Vector3(0, 0,
+                                        lineInCamera.transform.rotation.eulerAngles.z - 90));
+                                }
+                                else
+                                {
+                                    targetRotation = Quaternion.Euler(new Vector3(0, 0,
+                                        lineInCamera.transform.rotation.eulerAngles.z + 90));
+                                }
+                                targetViewport0 = cameraRect.Right;
+                                targetViewport1 = cameraRect.Left;
                             }
-
-                            targetViewport0 = cameraRect.Left;
-                            targetViewport1 = cameraRect.Right;
-
+                            isChangingViewport = true;
+                            time = 0;
+                        }
+                        else if (distanceY > splitDistance / XYRatio)
+                        {
 
                         }
                         else
                         {
-                            if (player0Pos.y < player1Pos.y)
-                            {
-                                targetRotation = Quaternion.Euler(new Vector3(0, 0,
-                                    lineInCamera.transform.rotation.z + 90));
-                            }
-                            else
-                            {
-                                targetRotation = Quaternion.Euler(new Vector3(0, 0,
-                                    lineInCamera.transform.rotation.z - 90));
-                            }
-                            targetViewport0 = cameraRect.Right;
-                            targetViewport1 = cameraRect.Left;
+                            view = 0;
                         }
-                        isChangingViewport = true;
+                        
                     }
 
                 }
@@ -268,11 +284,11 @@ public class CameraController : MonoBehaviour
                 }
                 else
                 {
-                    if (distanceY < mergeDistance / 2)
+                    if (distanceY < mergeDistance / XYRatio)
                     {
                         view = Mathf.Clamp((distanceX - mergeDistance)* ratio, 0, maxView);
                     }
-                    else if (distanceY > splitDistance / 2)
+                    else if (distanceY > splitDistance / XYRatio)
                     {
                         lineInCamera.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
                         if (player0Pos.y < player1Pos.y)
@@ -290,15 +306,9 @@ public class CameraController : MonoBehaviour
                     }
                     else
                     {
-                        if(distanceX >= distanceY * 2)
-                        {
-                            view = Mathf.Clamp((distanceX - mergeDistance)* ratio, 0, maxView);
-                        }
-                        else
-                        {
-                            view = Mathf.Clamp((distanceY - mergeDistance)* ratio, 0, maxView);
-                        }
-                        
+                        view = Mathf.Clamp((Vector3.Distance(player0Pos, player1Pos) - mergeDistance)
+                                * ratio, 0, maxView);
+
                     }
                     
                 }
@@ -307,17 +317,19 @@ public class CameraController : MonoBehaviour
 
             if (isSplit)
             {
-                if(player0Camera.rect.x == 0)
+                if(player0Camera.rect.x == 0 && player1Camera.rect.x == 0)
                 {
                     lineInCamera.transform.localScale = new Vector3(
-                        Mathf.Clamp((distanceY - mergeDistance/2) * 0.01f, 0, lineMaxScale), 20, 1);
+                        Mathf.Clamp((distanceY - mergeDistance) * 0.01f, 0,
+                            lineMaxScale), 20, 1);
                 }
-                else
+                if (player0Camera.rect.y == 0 && player1Camera.rect.y == 0)
                 {
                     lineInCamera.transform.localScale = new Vector3(
-                        Mathf.Clamp((distanceX - mergeDistance) * 0.01f, 0, lineMaxScale), 20, 1);
+                        Mathf.Clamp((distanceX - mergeDistance) * 0.01f, 0,
+                            lineMaxScale), 20, 1);
                 }
-                
+
             }
         }
     }
@@ -402,6 +414,8 @@ public class CameraController : MonoBehaviour
         if (time >= 1)
         {
             lineInCamera.transform.rotation = targetRotation;
+            print(lineInCamera.transform.rotation);
+            print(targetRotation);
             player0Camera.rect = targetViewport0;
             player1Camera.rect = targetViewport1;
             isChangingViewport = false;