summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Effect/UnitCamera.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-09-16 09:52:33 +0800
committerchai <chaifix@163.com>2021-09-16 09:52:33 +0800
commit8b65edb43be0945203633b33d7a62c81ab3f05ce (patch)
treebb5186baf27e58ca96389843907f9906380fd8e0 /Assets/Scripts/Unit/Effect/UnitCamera.cs
parent28b89971f0d3fd246443450c87f33996716facb3 (diff)
+unit effect
Diffstat (limited to 'Assets/Scripts/Unit/Effect/UnitCamera.cs')
-rw-r--r--Assets/Scripts/Unit/Effect/UnitCamera.cs34
1 files changed, 34 insertions, 0 deletions
diff --git a/Assets/Scripts/Unit/Effect/UnitCamera.cs b/Assets/Scripts/Unit/Effect/UnitCamera.cs
new file mode 100644
index 00000000..01194512
--- /dev/null
+++ b/Assets/Scripts/Unit/Effect/UnitCamera.cs
@@ -0,0 +1,34 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+// 专门用来渲染player character的相机,用来做特效
+[RequireComponent(typeof(Camera))]
+public class UnitCamera : MonoBehaviour
+{
+ PCController pc { get { return UnitManager.Instance.pc; } }
+
+ Camera m_Camera;
+
+ private void OnEnable()
+ {
+ m_Camera = GetComponent<Camera>();
+ }
+
+ private void OnPreRender()
+ {
+ if (pc == null)
+ return;
+ if (m_Camera == null)
+ return;
+
+ Vector3 pos = transform.position;
+ transform.position = new Vector3(pc.center.x, pc.center.y, pos.z);
+
+ float dz = Mathf.Abs(pos.z - pc.center.z);
+ float fov = 2 * Mathf.Atan2(pc.unitDetail.snapshotBound / 2, dz) * Mathf.Rad2Deg;
+
+ m_Camera.fieldOfView = fov;
+ }
+
+}