|
@@ -1,6 +1,15 @@
|
|
|
|
|
+using System;
|
|
|
using System.Collections;
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
|
|
|
+[Serializable]
|
|
|
|
|
+public struct CameraRect
|
|
|
|
|
+{
|
|
|
|
|
+ public Rect Up;
|
|
|
|
|
+ public Rect Down;
|
|
|
|
|
+ public Rect Left;
|
|
|
|
|
+ public Rect Right;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
public class CameraController : MonoBehaviour
|
|
public class CameraController : MonoBehaviour
|
|
|
{
|
|
{
|
|
@@ -41,6 +50,19 @@ public class CameraController : MonoBehaviour
|
|
|
public float minDis;
|
|
public float minDis;
|
|
|
private int once;
|
|
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()
|
|
private void Start()
|
|
|
{
|
|
{
|
|
|
ratio = maxView / (splitDistance - minDistance);
|
|
ratio = maxView / (splitDistance - minDistance);
|
|
@@ -54,7 +76,15 @@ public class CameraController : MonoBehaviour
|
|
|
PlayerController player0 = PlayersInput.instance[0];
|
|
PlayerController player0 = PlayersInput.instance[0];
|
|
|
PlayerController player1 = PlayersInput.instance[1];
|
|
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;
|
|
Vector3 player0Pos = player0.transform.position;
|
|
@@ -94,12 +124,28 @@ public class CameraController : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
CameraSplit(true);
|
|
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)
|
|
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)
|
|
public void CameraSplit(bool flag)
|
|
|
{
|
|
{
|
|
|
if (flag)
|
|
if (flag)
|