|
|
@@ -32,7 +32,6 @@ public class CameraController : MonoBehaviour
|
|
|
public float maxView = 20;
|
|
|
[HideInInspector]
|
|
|
public float view;
|
|
|
- public float minDistance = 20;
|
|
|
public float splitDistance = 30;
|
|
|
public float mergeDistance = 16;
|
|
|
public float distanceX;
|
|
|
@@ -65,7 +64,7 @@ public class CameraController : MonoBehaviour
|
|
|
|
|
|
private void Start()
|
|
|
{
|
|
|
- ratio = maxView / (splitDistance - minDistance);
|
|
|
+ ratio = maxView / (splitDistance - mergeDistance);
|
|
|
}
|
|
|
private void Update()
|
|
|
{
|
|
|
@@ -76,6 +75,7 @@ public class CameraController : MonoBehaviour
|
|
|
PlayerController player0 = PlayersInput.instance[0];
|
|
|
PlayerController player1 = PlayersInput.instance[1];
|
|
|
|
|
|
+ //分屏变化过程
|
|
|
if (isChangingViewport)
|
|
|
{
|
|
|
time += Time.deltaTime;
|
|
|
@@ -115,53 +115,148 @@ public class CameraController : MonoBehaviour
|
|
|
player1.NormalReplyMp();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //根据玩家距离分屏/合屏
|
|
|
if (distanceX < mergeDistance)
|
|
|
{
|
|
|
- if(distanceY < mergeDistance/2)
|
|
|
+ if (isSplit)
|
|
|
{
|
|
|
- if (isSplit)
|
|
|
+ if (distanceY < mergeDistance / 2)
|
|
|
{
|
|
|
CameraSplit(true);
|
|
|
}
|
|
|
- }
|
|
|
- else if (distanceY > splitDistance / 2)
|
|
|
- {
|
|
|
- if (isSplit)
|
|
|
+ else if (distanceY > splitDistance / 2)
|
|
|
{
|
|
|
if (player0Camera.rect.y == 0)
|
|
|
{
|
|
|
- if (player0Pos.x < player1Pos.x)
|
|
|
+ if (player0Pos.y < player1Pos.y)
|
|
|
{
|
|
|
- if (player0Pos.y < player1Pos.y)
|
|
|
+ if (player0Pos.x < player1Pos.x)
|
|
|
{
|
|
|
targetRotation = Quaternion.Euler(new Vector3(0, 0,
|
|
|
lineInCamera.transform.rotation.z + 90));
|
|
|
- //targetViewport0 = new Rect()
|
|
|
- isChangingViewport = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ targetRotation = Quaternion.Euler(new Vector3(0, 0,
|
|
|
+ lineInCamera.transform.rotation.z - 90));
|
|
|
+ }
|
|
|
+
|
|
|
+ targetViewport0 = cameraRect.Down;
|
|
|
+ targetViewport1 = cameraRect.Up;
|
|
|
+
|
|
|
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (player0Pos.x < player1Pos.x)
|
|
|
+ {
|
|
|
+ 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.Up;
|
|
|
+ targetViewport1 = cameraRect.Down;
|
|
|
}
|
|
|
+ isChangingViewport = true;
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ view = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (distanceY < mergeDistance / 2)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (distanceY > splitDistance / 2)
|
|
|
+ {
|
|
|
+ lineInCamera.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
|
|
|
+ if (player0Pos.y < player1Pos.y)
|
|
|
+ {
|
|
|
+ player0Camera.rect = cameraRect.Down;
|
|
|
+ player1Camera.rect = cameraRect.Up;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ player0Camera.rect = cameraRect.Up;
|
|
|
+ player1Camera.rect = cameraRect.Down;
|
|
|
+ }
|
|
|
+ CameraSplit(false);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ view = Mathf.Clamp((distanceY - mergeDistance/2)* ratio, 0, maxView);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else if (distanceX > splitDistance)
|
|
|
{
|
|
|
- if (!isSplit)
|
|
|
+ if (isSplit)
|
|
|
{
|
|
|
- CameraSplit(false);
|
|
|
+ if(player0Camera.rect.x == 0)
|
|
|
+ {
|
|
|
+ if (player0Pos.x < player1Pos.x)
|
|
|
+ {
|
|
|
+ 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.Left;
|
|
|
+ targetViewport1 = cameraRect.Right;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ isChangingViewport = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lineInCamera.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
|
|
|
if (player0Pos.x < player1Pos.x)
|
|
|
{
|
|
|
- player0Camera.rect = new Rect(0, 0, 0.5f, 1);
|
|
|
- player1Camera.rect = new Rect(0.5f, 0, 0.5f, 1);
|
|
|
+ player0Camera.rect = cameraRect.Left;
|
|
|
+ player1Camera.rect = cameraRect.Right;
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- player0Camera.rect = new Rect(0.5f, 0, 0.5f, 1);
|
|
|
- player1Camera.rect = new Rect(0, 0, 0.5f, 1);
|
|
|
+ player0Camera.rect = cameraRect.Right;
|
|
|
+ player1Camera.rect = cameraRect.Left;
|
|
|
}
|
|
|
+ CameraSplit(false);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -173,15 +268,56 @@ public class CameraController : MonoBehaviour
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- view = Mathf.Clamp((distanceX - minDistance) * ratio, 0, maxView);
|
|
|
+ if (distanceY < mergeDistance / 2)
|
|
|
+ {
|
|
|
+ view = Mathf.Clamp((distanceX - mergeDistance)* ratio, 0, maxView);
|
|
|
+ }
|
|
|
+ else if (distanceY > splitDistance / 2)
|
|
|
+ {
|
|
|
+ lineInCamera.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
|
|
|
+ if (player0Pos.y < player1Pos.y)
|
|
|
+ {
|
|
|
+ player0Camera.rect = cameraRect.Down;
|
|
|
+ player1Camera.rect = cameraRect.Up;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ player0Camera.rect = cameraRect.Up;
|
|
|
+ player1Camera.rect = cameraRect.Down;
|
|
|
+ }
|
|
|
+ CameraSplit(false);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(distanceX >= distanceY * 2)
|
|
|
+ {
|
|
|
+ view = Mathf.Clamp((distanceX - mergeDistance)* ratio, 0, maxView);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ view = Mathf.Clamp((distanceY - mergeDistance)* ratio, 0, maxView);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (isSplit)
|
|
|
{
|
|
|
- lineInCamera.transform.localScale = new Vector3(
|
|
|
- Mathf.Clamp((distanceX - mergeDistance) * 0.01f, 0, lineMaxScale), 20, 1);
|
|
|
+ if(player0Camera.rect.x == 0)
|
|
|
+ {
|
|
|
+ lineInCamera.transform.localScale = new Vector3(
|
|
|
+ Mathf.Clamp((distanceY - mergeDistance/2) * 0.01f, 0, lineMaxScale), 20, 1);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lineInCamera.transform.localScale = new Vector3(
|
|
|
+ Mathf.Clamp((distanceX - mergeDistance) * 0.01f, 0, lineMaxScale), 20, 1);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|