diff options
Diffstat (limited to 'Assets/Scripts/Camera')
-rw-r--r-- | Assets/Scripts/Camera/CameraUtility.cs | 49 | ||||
-rw-r--r-- | Assets/Scripts/Camera/CameraUtility.cs.meta | 11 | ||||
-rw-r--r-- | Assets/Scripts/Camera/MainCamera.cs | 154 | ||||
-rw-r--r-- | Assets/Scripts/Camera/MainCamera.cs.meta | 11 | ||||
-rw-r--r-- | Assets/Scripts/Camera/MainCameraDebug.cs | 10 | ||||
-rw-r--r-- | Assets/Scripts/Camera/MainCameraDebug.cs.meta | 11 |
6 files changed, 0 insertions, 246 deletions
diff --git a/Assets/Scripts/Camera/CameraUtility.cs b/Assets/Scripts/Camera/CameraUtility.cs deleted file mode 100644 index 1f6c10e6..00000000 --- a/Assets/Scripts/Camera/CameraUtility.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public static class CameraExtend
-{
-
- public static Vector3 WorldToCameraSpace(this Camera camera, Vector3 worldPos)
- {
- Vector4 camPos = camera.worldToCameraMatrix * worldPos.ToVector4();
- return camPos.ToVector3();
- }
-
- public static Vector3 CameraToViewportSpace(this Camera camera, Vector3 camPos)
- {
- Matrix4x4 proj = GL.GetGPUProjectionMatrix(camera.projectionMatrix, false);
- Vector4 clipPos = proj * camPos.ToVector4();
- Vector3 ndcPos = (clipPos / clipPos.w);
- Vector3 viewPos = (ndcPos + Vector3.one) / 2f;
- return viewPos;
- }
-
- public static Vector3 CameraToScreenSpace(this Camera camera, Vector3 camPos)
- {
- Vector3 viewPos = camera.CameraToViewportSpace(camPos);
- Vector3 screenPos = new Vector3(
- viewPos.x * camera.pixelWidth,
- viewPos.y * camera.pixelHeight,
- viewPos.z
- );
- return screenPos;
- }
-
-}
-
-public class CameraUtility : MonoBehaviour
-{
- // Start is called before the first frame update
- void Start()
- {
-
- }
-
- // Update is called once per frame
- void Update()
- {
-
- }
-}
diff --git a/Assets/Scripts/Camera/CameraUtility.cs.meta b/Assets/Scripts/Camera/CameraUtility.cs.meta deleted file mode 100644 index bd11b826..00000000 --- a/Assets/Scripts/Camera/CameraUtility.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6797331b02de5684ab22aeafac41d2c5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Camera/MainCamera.cs b/Assets/Scripts/Camera/MainCamera.cs deleted file mode 100644 index 4d65fa18..00000000 --- a/Assets/Scripts/Camera/MainCamera.cs +++ /dev/null @@ -1,154 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -// 主相机 -[ExecuteAlways] -[RequireComponent(typeof(Camera))] -public class MainCamera : SingletonMB<MainCamera> -{ - #region inspector - [Serializable] - public struct Region - { - [SerializeField] public float l; - [SerializeField] public float r; - [SerializeField] public float t; - [SerializeField] public float b; - } - - public new Camera camera { get; private set; } - - public Vector3 offset = Vector3.zero; - - [SerializeField] private float z; - - [SerializeField] private Region region; - - [SerializeField] private float moveSpeed; - - [SerializeField] private AnimationCurve speedCurve; - - [SerializeField] private float threshold; - #endregion - - private CustomRenderingPipeline m_CustomRenderingPipeline; - public CustomRenderingPipeline customRenderingPipeline
- { - get - { - if (m_CustomRenderingPipeline == null)
- m_CustomRenderingPipeline = this.gameObject.GetOrAddComponent<CustomRenderingPipeline>(); - return m_CustomRenderingPipeline; - } - } - - private Vector2 position2D - { - get - { - return transform.position; - } - set - { - transform.position = new Vector3(value.x, value.y, transform.position.z); - } - } - - private Vector3 position - { - get - { - return transform.position; - } - set - { - transform.position = value; - } - } - - protected override void Awake() - { - base.Awake(); - camera = gameObject.GetComponent<Camera>(); - } - - private void Start() - { - Vector3 pos = transform.position; - pos.z = this.z; - transform.position = pos; - - Quaternion rot = Quaternion.LookRotation(Vector3.forward); - transform.rotation = rot; - } - - void FollowPlayerCharacter() - { - if (UnitManager.Instance == null || UnitManager.Instance.pc == null) - return; - - Region region = this.region; - - //if (!UnitManager.Instance.pc.isTowardRight) - //{ - // region.l = -this.region.r; - // region.r = -this.region.l; - //} - - Vector3 camPos = position; - - Vector3 worldPos = UnitManager.Instance.pc.transform.position + offset; - - Vector2 viewPos = ((Vector2)camera.WorldToViewportPoint(worldPos)) * 2 - Vector2.one; - - Vector3 dir = (worldPos - camPos).normalized; - float dest = (worldPos - camPos).magnitude; - float curve = speedCurve.Evaluate((threshold - Mathf.Clamp(dest, 0f, threshold)) / threshold); - Vector3 move = curve * dir * moveSpeed * Time.deltaTime; - - if (IsInRegion(viewPos, region)) - { - if(!IsInCenter(viewPos)) - { - position2D = camPos + move; - if((worldPos - position).magnitude <= 0.1f) - { - position2D = worldPos; - } - } - return; - } - position2D = camPos + move; - if ((worldPos - position).magnitude <= 0.1f) - { - position2D = worldPos; - } - } - - bool IsInRegion(Vector2 p, Region region) - { - return p.x > region.l - && p.x < region.r - && p.y > region.b - && p.y < region.t; - } - - bool IsInCenter(Vector2 p) - { - return p.x == (region.l + region.r) / 2 && p.y == (region.t + region.b) / 2; - } - - void Update() - { - FollowPlayerCharacter(); - } - - public void OnGUI() - { - if(MainCameraDebug.OnGUIHandlers != null) - MainCameraDebug.OnGUIHandlers.Invoke(); - } - -}
\ No newline at end of file diff --git a/Assets/Scripts/Camera/MainCamera.cs.meta b/Assets/Scripts/Camera/MainCamera.cs.meta deleted file mode 100644 index 1ad6678e..00000000 --- a/Assets/Scripts/Camera/MainCamera.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 68da209687f0dcc49967a423b26c204c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Camera/MainCameraDebug.cs b/Assets/Scripts/Camera/MainCameraDebug.cs deleted file mode 100644 index 7a8382ee..00000000 --- a/Assets/Scripts/Camera/MainCameraDebug.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class MainCameraDebug -{ - public static Action OnGUIHandlers; - -} diff --git a/Assets/Scripts/Camera/MainCameraDebug.cs.meta b/Assets/Scripts/Camera/MainCameraDebug.cs.meta deleted file mode 100644 index 71e9cdb8..00000000 --- a/Assets/Scripts/Camera/MainCameraDebug.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 31f8e21379e822447b55a74c799469f6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: |