LAPTOP-OM1V99U2\永远de小亡灵 пре 1 година
родитељ
комит
24f83e12bf

+ 41 - 1
ActionTowerDefense/Assets/Scenes/SampleScene.unity

@@ -16439,7 +16439,47 @@ MonoBehaviour:
   lineInCamera: {fileID: 3490440115155743560}
   isSplit: 0
   rapidMpReplySpeed: 20
-  minDis: 2
+  minDis: 0
+  targetRotation: {x: 0, y: 0, z: 0, w: 0}
+  targetViewport0:
+    serializedVersion: 2
+    x: 0
+    y: 0
+    width: 0
+    height: 0
+  targetViewport1:
+    serializedVersion: 2
+    x: 0
+    y: 0
+    width: 0
+    height: 0
+  time: 0
+  isChangingViewport: 0
+  cameraRect:
+    Up:
+      serializedVersion: 2
+      x: 0
+      y: 0.5
+      width: 1
+      height: 0.5
+    Down:
+      serializedVersion: 2
+      x: 0
+      y: 0
+      width: 1
+      height: 0.5
+    Left:
+      serializedVersion: 2
+      x: 0
+      y: 0
+      width: 0.5
+      height: 1
+    Right:
+      serializedVersion: 2
+      x: 0.5
+      y: 0
+      width: 0.5
+      height: 1
 --- !u!4 &1055802830
 Transform:
   m_ObjectHideFlags: 0

+ 72 - 3
ActionTowerDefense/Assets/Scripts/CameraController.cs

@@ -1,6 +1,15 @@
+using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+[Serializable]
+public struct CameraRect
+{
+    public Rect Up;
+    public Rect Down;
+    public Rect Left;
+    public Rect Right;
+}
 
 public class CameraController : MonoBehaviour
 {
@@ -41,6 +50,19 @@ public class CameraController : MonoBehaviour
     public float minDis;
     private int once;
 
+    [HideInInspector]
+    public Quaternion targetRotation;
+    [HideInInspector]
+    public Rect targetViewport0;
+    [HideInInspector]
+    public Rect targetViewport1;
+
+    [HideInInspector]
+    public float time;
+    [HideInInspector]
+    public bool isChangingViewport;
+    public CameraRect cameraRect;
+
     private void Start()
     {
         ratio = maxView / (splitDistance - minDistance);
@@ -54,7 +76,15 @@ public class CameraController : MonoBehaviour
         PlayerController player0 = PlayersInput.instance[0];
         PlayerController player1 = PlayersInput.instance[1];
 
-        if(player0!= null && player0!=player1)
+        if (isChangingViewport)
+        {
+            time += Time.deltaTime;
+            ChangeViewport();
+        }
+
+
+
+        if (player0!= null && player0!=player1)
         {
 
             Vector3 player0Pos = player0.transform.position;
@@ -94,12 +124,28 @@ public class CameraController : MonoBehaviour
                     {
                         CameraSplit(true);
                     }
-                    else
+                }
+                else if (distanceY > splitDistance / 2)
+                {
+                    if (isSplit)
                     {
+                        if (player0Camera.rect.y == 0)
+                        {
+                            if (player0Pos.x < player1Pos.x)
+                            {
+                                if (player0Pos.y < player1Pos.y)
+                                {
+                                    targetRotation = Quaternion.Euler(new Vector3(0, 0,
+                                        lineInCamera.transform.rotation.z + 90));
+                                    //targetViewport0 = new Rect()
+                                    isChangingViewport = true;
 
+                                }
+                            }
+                        }
                     }
                 }
-  
+
             }
             else if (distanceX > splitDistance)
             {
@@ -202,6 +248,29 @@ public class CameraController : MonoBehaviour
         }
 
     }
+
+
+    public void ChangeViewport()
+    {
+        lineInCamera.transform.rotation = Quaternion.Lerp(lineInCamera.transform.rotation,
+            targetRotation, time);
+        Rect rect = player0Camera.rect;
+        player0Camera.rect = new Rect(Mathf.Lerp(rect.x, targetViewport0.x, time),
+            Mathf.Lerp(rect.y, targetViewport0.y, time),
+            Mathf.Lerp(rect.width, targetViewport0.width, time),
+            Mathf.Lerp(rect.height, targetViewport0.height, time));
+        player1Camera.rect = new Rect(Mathf.Lerp(rect.x, targetViewport1.x, time),
+            Mathf.Lerp(rect.y, targetViewport1.y, time),
+            Mathf.Lerp(rect.width, targetViewport1.width, time),
+            Mathf.Lerp(rect.height, targetViewport1.height, time));
+        if (time >= 1)
+        {
+            lineInCamera.transform.rotation = targetRotation;
+            player0Camera.rect = targetViewport0;
+            player1Camera.rect = targetViewport1;
+            isChangingViewport = false;
+        }
+    }
     public void CameraSplit(bool flag)
     {
         if (flag)