|
|
@@ -3,17 +3,17 @@ 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 struct CameraRect
|
|
|
+//{
|
|
|
+// public Rect Up;
|
|
|
+// public Rect Down;
|
|
|
+// public Rect Left;
|
|
|
+// public Rect Right;
|
|
|
+//}
|
|
|
|
|
|
public class CameraController : MonoBehaviour
|
|
|
{
|
|
|
- public float offsetX = 5, offsetY = 3, offsetZ = -16;
|
|
|
+ public float offsetX = 2, offsetY = 2, offsetZ = -17, offsetYDown = -10;
|
|
|
public float lerpValue = 3.5f;
|
|
|
|
|
|
[HideInInspector]
|
|
|
@@ -33,38 +33,37 @@ public class CameraController : MonoBehaviour
|
|
|
[HideInInspector]
|
|
|
public float view;
|
|
|
public float splitDistance = 30;
|
|
|
- public float mergeDistance = 16;
|
|
|
+ public float mergeDistanceX = 16;
|
|
|
+ public float mergeDistanceY = 8;
|
|
|
+ [HideInInspector]
|
|
|
public float distanceX;
|
|
|
+ [HideInInspector]
|
|
|
public float distanceY;
|
|
|
[HideInInspector]
|
|
|
public float ratio;
|
|
|
-
|
|
|
+ public float ratioY = 1;
|
|
|
public float lineMaxScale = 0.5f;
|
|
|
|
|
|
public GameObject lineInCamera;
|
|
|
|
|
|
public bool isSplit;
|
|
|
+ public bool isSplitY;
|
|
|
|
|
|
public float minDis;
|
|
|
private int once;
|
|
|
|
|
|
- [HideInInspector]
|
|
|
- public Quaternion targetRotation;
|
|
|
- [HideInInspector]
|
|
|
- public Rect targetViewport0;
|
|
|
- [HideInInspector]
|
|
|
- public Rect targetViewport1;
|
|
|
+ //[HideInInspector]
|
|
|
+ //public Quaternion targetRotation;
|
|
|
+ //[HideInInspector]
|
|
|
+ //public Rect targetViewport0;
|
|
|
+ //[HideInInspector]
|
|
|
+ //public Rect targetViewport1;
|
|
|
|
|
|
- [HideInInspector]
|
|
|
- public float time;
|
|
|
- [HideInInspector]
|
|
|
- public bool isChangingViewport;
|
|
|
- public CameraRect cameraRect;
|
|
|
+ //public CameraRect cameraRect;
|
|
|
|
|
|
- public float XYRatio = 2.5f;
|
|
|
private void Start()
|
|
|
{
|
|
|
- ratio = maxView / (splitDistance - mergeDistance);
|
|
|
+ ratio = maxView / (splitDistance - mergeDistanceX);
|
|
|
}
|
|
|
private void Update()
|
|
|
{
|
|
|
@@ -75,13 +74,6 @@ public class CameraController : MonoBehaviour
|
|
|
PlayerController player0 = PlayersInput.instance[0];
|
|
|
PlayerController player1 = PlayersInput.instance[1];
|
|
|
|
|
|
- //分屏变化过程
|
|
|
- if (isChangingViewport)
|
|
|
- {
|
|
|
- time += Time.deltaTime * 3;
|
|
|
- ChangeViewport();
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
|
|
|
if (player0!= null && player0!=player1)
|
|
|
@@ -116,85 +108,26 @@ public class CameraController : MonoBehaviour
|
|
|
}
|
|
|
|
|
|
//根据玩家距离分屏/合屏
|
|
|
- if (distanceX < mergeDistance)
|
|
|
+ if (distanceX < mergeDistanceX)
|
|
|
{
|
|
|
if (isSplit)
|
|
|
{
|
|
|
- if (distanceY < mergeDistance / XYRatio)
|
|
|
- {
|
|
|
- CameraSplit(true);
|
|
|
- }
|
|
|
- else if (distanceY > splitDistance / XYRatio)
|
|
|
- {
|
|
|
- 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.eulerAngles.z + 90));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- targetRotation = Quaternion.Euler(new Vector3(0, 0,
|
|
|
- lineInCamera.transform.rotation.eulerAngles.z - 90));
|
|
|
- }
|
|
|
-
|
|
|
- targetViewport0 = cameraRect.Down;
|
|
|
- targetViewport1 = cameraRect.Up;
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (player0Pos.x < player1Pos.x)
|
|
|
- {
|
|
|
- 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.Up;
|
|
|
- targetViewport1 = cameraRect.Down;
|
|
|
- }
|
|
|
- isChangingViewport = true;
|
|
|
- time = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- view = 0;
|
|
|
- }
|
|
|
+ view = 0;
|
|
|
+ CameraSplit(true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (distanceY < mergeDistance / XYRatio)
|
|
|
+ if (distanceY > mergeDistanceY)
|
|
|
{
|
|
|
-
|
|
|
+ view = (distanceY - mergeDistanceY) * ratioY;
|
|
|
+ isSplitY = true;
|
|
|
}
|
|
|
- else if (distanceY > splitDistance / XYRatio)
|
|
|
+ else
|
|
|
{
|
|
|
- lineInCamera.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
|
|
|
- if (player0Pos.y < player1Pos.y)
|
|
|
+ if (isSplitY)
|
|
|
{
|
|
|
- player0Camera.rect = cameraRect.Down;
|
|
|
- player1Camera.rect = cameraRect.Up;
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- player0Camera.rect = cameraRect.Up;
|
|
|
- player1Camera.rect = cameraRect.Down;
|
|
|
+ isSplitY = false;
|
|
|
}
|
|
|
- CameraSplit(false);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- view = Mathf.Clamp((distanceY - mergeDistance/2)* ratio, 0, maxView);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -202,75 +135,8 @@ public class CameraController : MonoBehaviour
|
|
|
}
|
|
|
else if (distanceX > splitDistance)
|
|
|
{
|
|
|
- if (isSplit)
|
|
|
+ if (!isSplit)
|
|
|
{
|
|
|
-
|
|
|
- if(player0Camera.rect.x == 0 && player1Camera.rect.x == 0)
|
|
|
- {
|
|
|
- if (distanceY < mergeDistance / XYRatio)
|
|
|
- {
|
|
|
- if (player0Pos.x < player1Pos.x)
|
|
|
- {
|
|
|
- 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
|
|
|
- {
|
|
|
- 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;
|
|
|
- }
|
|
|
- isChangingViewport = true;
|
|
|
- time = 0;
|
|
|
- }
|
|
|
- else if (distanceY > splitDistance / XYRatio)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- view = 0;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- lineInCamera.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
|
|
|
- if (player0Pos.x < player1Pos.x)
|
|
|
- {
|
|
|
- player0Camera.rect = cameraRect.Left;
|
|
|
- player1Camera.rect = cameraRect.Right;
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- player0Camera.rect = cameraRect.Right;
|
|
|
- player1Camera.rect = cameraRect.Left;
|
|
|
- }
|
|
|
CameraSplit(false);
|
|
|
}
|
|
|
|
|
|
@@ -283,51 +149,30 @@ public class CameraController : MonoBehaviour
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (distanceY < mergeDistance / XYRatio)
|
|
|
+ float viewX = Mathf.Clamp((distanceX - mergeDistanceX) * ratio, 0, maxView);
|
|
|
+ float viewY = (distanceY - mergeDistanceY) * ratioY;
|
|
|
+ if(viewX > viewY)
|
|
|
{
|
|
|
- view = Mathf.Clamp((distanceX - mergeDistance)* ratio, 0, maxView);
|
|
|
- }
|
|
|
- else if (distanceY > splitDistance / XYRatio)
|
|
|
- {
|
|
|
- lineInCamera.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
|
|
|
- if (player0Pos.y < player1Pos.y)
|
|
|
+ view = viewX;
|
|
|
+ if (isSplitY)
|
|
|
{
|
|
|
- player0Camera.rect = cameraRect.Down;
|
|
|
- player1Camera.rect = cameraRect.Up;
|
|
|
-
|
|
|
+ isSplitY = false;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- player0Camera.rect = cameraRect.Up;
|
|
|
- player1Camera.rect = cameraRect.Down;
|
|
|
- }
|
|
|
- CameraSplit(false);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- view = Mathf.Clamp((Vector3.Distance(player0Pos, player1Pos) - mergeDistance)
|
|
|
- * ratio, 0, maxView);
|
|
|
-
|
|
|
+ view = viewY;
|
|
|
+ isSplitY = true;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (isSplit)
|
|
|
{
|
|
|
- if(player0Camera.rect.x == 0 && player1Camera.rect.x == 0)
|
|
|
- {
|
|
|
- lineInCamera.transform.localScale = new Vector3(
|
|
|
- Mathf.Clamp((distanceY - mergeDistance) * 0.01f, 0,
|
|
|
+ lineInCamera.transform.localScale = new Vector3(
|
|
|
+ Mathf.Clamp((distanceX - mergeDistanceX) * 0.01f, 0,
|
|
|
lineMaxScale), 20, 1);
|
|
|
- }
|
|
|
- if (player0Camera.rect.y == 0 && player1Camera.rect.y == 0)
|
|
|
- {
|
|
|
- lineInCamera.transform.localScale = new Vector3(
|
|
|
- Mathf.Clamp((distanceX - mergeDistance) * 0.01f, 0,
|
|
|
- lineMaxScale), 20, 1);
|
|
|
- }
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -385,41 +230,37 @@ public class CameraController : MonoBehaviour
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
+ if (isSplitY)
|
|
|
+ {
|
|
|
+ if(player0TargetPos.y > player1TargetPos.y)
|
|
|
+ {
|
|
|
+ player0Camera.transform.position = Vector3.Lerp(player0Camera.transform.position,
|
|
|
+ player0TargetPos + Vector3.up * offsetYDown, lerpValue * 2 * Time.deltaTime);
|
|
|
+ player1Camera.transform.position = Vector3.Lerp(player1Camera.transform.position,
|
|
|
+ player1TargetPos, lerpValue * 2 * Time.deltaTime);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ player0Camera.transform.position = Vector3.Lerp(player0Camera.transform.position,
|
|
|
+ player0TargetPos, lerpValue * 2 * Time.deltaTime);
|
|
|
+ player1Camera.transform.position = Vector3.Lerp(player1Camera.transform.position,
|
|
|
+ player1TargetPos + Vector3.up * offsetYDown, lerpValue * 2 * Time.deltaTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ player0Camera.transform.position = Vector3.Lerp(player0Camera.transform.position,
|
|
|
+ player0TargetPos, lerpValue * 2 * Time.deltaTime);
|
|
|
+ player1Camera.transform.position = Vector3.Lerp(player1Camera.transform.position,
|
|
|
+ player1TargetPos, lerpValue * 2 * Time.deltaTime);
|
|
|
+ }
|
|
|
|
|
|
- player0Camera.transform.position = Vector3.Lerp(player0Camera.transform.position,
|
|
|
- player0TargetPos, lerpValue * 2 * Time.deltaTime);
|
|
|
- player1Camera.transform.position = Vector3.Lerp(player1Camera.transform.position,
|
|
|
- player1TargetPos, lerpValue * 2 * Time.deltaTime);
|
|
|
mainCamera.transform.position = Vector3.Lerp(player0Camera.transform.position,
|
|
|
player1Camera.transform.position, 0.5f) + Vector3.back * view;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- 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;
|
|
|
- print(lineInCamera.transform.rotation);
|
|
|
- print(targetRotation);
|
|
|
- player0Camera.rect = targetViewport0;
|
|
|
- player1Camera.rect = targetViewport1;
|
|
|
- isChangingViewport = false;
|
|
|
- }
|
|
|
- }
|
|
|
public void CameraSplit(bool flag)
|
|
|
{
|
|
|
if (flag)
|
|
|
@@ -452,7 +293,7 @@ public class CameraController : MonoBehaviour
|
|
|
{
|
|
|
skewPos = player.transform.position + new Vector3(-offsetX, offsetY, offsetZ);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|