|
@@ -5,50 +5,85 @@ using TMPro;
|
|
|
|
|
|
|
|
public class PortalsCountDownUI : MonoBehaviour
|
|
public class PortalsCountDownUI : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
|
|
+ public CameraController cameraController;
|
|
|
|
|
+
|
|
|
public Vector3 portalPos; //传送门位置
|
|
public Vector3 portalPos; //传送门位置
|
|
|
public TextMeshProUGUI[] text; //倒计时数字
|
|
public TextMeshProUGUI[] text; //倒计时数字
|
|
|
public GameObject[] effect; //UI指示器
|
|
public GameObject[] effect; //UI指示器
|
|
|
|
|
+ public GameObject[] countDown; //text和effect的父物体
|
|
|
public Vector2 parentRect; //父物体Rect Transform的长宽的一半
|
|
public Vector2 parentRect; //父物体Rect Transform的长宽的一半
|
|
|
public float hypotenuse; //父物体Rect Transform斜边的长度
|
|
public float hypotenuse; //父物体Rect Transform斜边的长度
|
|
|
public float myRect; //自己的边长的一半
|
|
public float myRect; //自己的边长的一半
|
|
|
-
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
private void Start()
|
|
|
{
|
|
{
|
|
|
hypotenuse = parentRect.magnitude;
|
|
hypotenuse = parentRect.magnitude;
|
|
|
|
|
+ cameraController = GameObject.Find("View").GetComponent<CameraController>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
private void Update()
|
|
|
{
|
|
{
|
|
|
- Vector3 pos = PlayersInput.instance[0].transform.position;
|
|
|
|
|
|
|
+ if (cameraController.isSplit)
|
|
|
|
|
+ {
|
|
|
|
|
+ Camera camera0 = cameraController.player0Camera;
|
|
|
|
|
+ Camera camera1 = cameraController.player1Camera;
|
|
|
|
|
+ refreshPortalUIPos(
|
|
|
|
|
+ camera0, 0,
|
|
|
|
|
+ new Vector2(25 + (camera0.rect.x - 0.5f) * parentRect.x * 2 + myRect,
|
|
|
|
|
+ - parentRect.y + myRect),
|
|
|
|
|
+ new Vector2(-25 + camera0.rect.x * parentRect.x * 2 - myRect,
|
|
|
|
|
+ parentRect.y - myRect));
|
|
|
|
|
+ refreshPortalUIPos(
|
|
|
|
|
+ camera1, 1,
|
|
|
|
|
+ new Vector2(25 + (camera1.rect.x - 0.5f) * parentRect.x * 2 + myRect,
|
|
|
|
|
+ - parentRect.y + myRect),
|
|
|
|
|
+ new Vector2(-25 + camera1.rect.x * parentRect.x * 2 - myRect,
|
|
|
|
|
+ parentRect.y - myRect));
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ refreshPortalUIPos(cameraController.mainCamera, 0,
|
|
|
|
|
+ - parentRect + new Vector2(myRect, myRect),
|
|
|
|
|
+ parentRect - new Vector2(myRect, myRect));
|
|
|
|
|
+ if (countDown[1].activeSelf)
|
|
|
|
|
+ {
|
|
|
|
|
+ countDown[1].SetActive(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //刷新指示箭头显示
|
|
|
|
|
+ void refreshPortalUIPos(Camera camera,int id,Vector2 RectClampMin,Vector2 RectClampMax)
|
|
|
|
|
+ {
|
|
|
|
|
+ //计算指示箭头的方向
|
|
|
|
|
+ Vector3 pos = camera.transform.position;
|
|
|
float angle = Mathf.Atan2(portalPos.y - pos.y, portalPos.x - pos.x) * Mathf.Rad2Deg - 90;
|
|
float angle = Mathf.Atan2(portalPos.y - pos.y, portalPos.x - pos.x) * Mathf.Rad2Deg - 90;
|
|
|
- effect[0].transform.rotation = Quaternion.Euler(Vector3.forward * angle);
|
|
|
|
|
- effect[1].transform.rotation = Quaternion.Euler(Vector3.forward * angle);
|
|
|
|
|
|
|
+ effect[id].transform.rotation = Quaternion.Euler(Vector3.forward * angle);
|
|
|
|
|
|
|
|
- //计算指示箭头的位置
|
|
|
|
|
- Vector3 target = new Vector3(portalPos.x - pos.x, portalPos.y - pos.y, 0);
|
|
|
|
|
- Vector3 viewportPoint = Camera.main.WorldToViewportPoint(portalPos);
|
|
|
|
|
- if (viewportPoint.x >= 0 && viewportPoint.y >= 0 && viewportPoint.x <= 1 && viewportPoint.y <= 1
|
|
|
|
|
- && viewportPoint.z > Camera.main.nearClipPlane)
|
|
|
|
|
|
|
+ //判断传送门是否在屏幕内
|
|
|
|
|
+ Vector3 viewportPoint = camera.WorldToViewportPoint(portalPos);
|
|
|
|
|
+ if (viewportPoint.x >= 0 && viewportPoint.y >= 0
|
|
|
|
|
+ && viewportPoint.x <= camera.rect.width && viewportPoint.y <= 1
|
|
|
|
|
+ && viewportPoint.z > camera.nearClipPlane)
|
|
|
{
|
|
{
|
|
|
- if (effect[0].transform.parent.gameObject.activeSelf)
|
|
|
|
|
|
|
+ if (countDown[id].activeSelf)
|
|
|
{
|
|
{
|
|
|
- effect[0].transform.parent.gameObject.SetActive(false);
|
|
|
|
|
- effect[1].transform.parent.gameObject.SetActive(false);
|
|
|
|
|
|
|
+ countDown[id].SetActive(false);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- if (!effect[0].transform.parent.gameObject.activeSelf)
|
|
|
|
|
|
|
+ if (!countDown[id].activeSelf)
|
|
|
{
|
|
{
|
|
|
- effect[0].transform.parent.gameObject.SetActive(true);
|
|
|
|
|
- effect[1].transform.parent.gameObject.SetActive(true);
|
|
|
|
|
|
|
+ countDown[id].SetActive(true);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //计算指示箭头的位置
|
|
|
|
|
+ Vector3 target = new Vector3(portalPos.x - pos.x, portalPos.y - pos.y, 0);
|
|
|
target = target.normalized * hypotenuse;
|
|
target = target.normalized * hypotenuse;
|
|
|
- target.x = Mathf.Clamp(target.x, -parentRect.x + myRect, parentRect.x - myRect);
|
|
|
|
|
- target.y = Mathf.Clamp(target.y, -parentRect.y + myRect, parentRect.y - myRect);
|
|
|
|
|
- effect[0].transform.parent.localPosition = target;
|
|
|
|
|
- effect[1].transform.parent.transform.localPosition = target;
|
|
|
|
|
|
|
+ target.x = Mathf.Clamp(target.x, RectClampMin.x, RectClampMax.x);
|
|
|
|
|
+ target.y = Mathf.Clamp(target.y, RectClampMin.y, RectClampMax.y);
|
|
|
|
|
+ countDown[id].transform.localPosition = target;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|