123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- using Adon.Game.Helper;
- using Cinemachine;
- using Cinemachine.PostFX;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- //using UnityEngine.Rendering.PostProcessing;
- namespace AdonGameKit
- {
- public class CameraManagerAdon : MonoBehaviour
- {
- public Camera m_MainCamera;
- public Camera m_CharacterCamera;
- public Transform m_Hero;
- public Transform m_Timeline_CM_Respawn;//出生相机Timeline对象
- public CinemachineFreeLook m_CM_ThirdPerson;//第三人称相机
- public CinemachineVirtualCamera m_CM_TopDown;//俯视相机
- public CinemachineVirtualCamera m_CM_Win;//胜利相机
- public CinemachineVirtualCameraBase m_CM_Active;//当前活跃相机
- public CinemachineTargetGroup m_CinemachineTargetGroup;
- public GameObject LockTarget;
- public float m_Angle;
- public float m_Sight;
- public bool IsCensorCameraAngle;
- //static private CameraManagerAdon m_Instance;
- //static public CameraManagerAdon Instance
- //{
- // get
- // {
- // return m_Instance;
- // }
- //}
- private void Awake()
- {
- m_MainCamera = Camera.main;
- m_Timeline_CM_Respawn = transform.Find("CMStateDrivenCamera/Timeline_CM_Respawn");
- m_CM_ThirdPerson = transform.Find("CMStateDrivenCamera/CM_ThirdPerson").GetComponent<CinemachineFreeLook>();
- m_CM_TopDown = transform.Find("CMStateDrivenCamera/CM_TopDown").GetComponent<CinemachineVirtualCamera>();
- m_CM_Win = transform.Find("CMStateDrivenCamera/CM_Win").GetComponent<CinemachineVirtualCamera>();
- m_CM_Active = m_CM_ThirdPerson;
- m_CinemachineTargetGroup = transform.Find("TargetGroup").GetComponent<CinemachineTargetGroup>();
- m_Hero = m_CinemachineTargetGroup.m_Targets[0].target;
- }
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- /////更新锁定相机
- /////根据相机与玩家方向,计算与锁定目标对角度,大于指定角度则旋转相机到差值
- //Vector3 dir = m_MainCamera.transform.position - m_Hero.transform.position;//相机与玩家方向
- ////计算怪角度偏移
- //float HitAngle = PlayerHelperAdon.Angle_360(dir, LockTarget.transform.position);
- //Debug.Log("相机与目标角度"+ HitAngle);
- //if (HitAngle > 270)
- //{
- // CM_ThirdPerson.m_XAxis.Value = HitAngle - 270;
- //}
- }
-
- ///// <summary>
- ///// 设置锁定目标
- ///// </summary>
- ///// <param name="_LockTarget"></param>
- //public void SetLockTarget(GameObject _LockTarget)
- //{
- // LockTarget = _LockTarget;
- // m_CinemachineTargetGroup.m_Targets[1].target = LockTarget.transform;
- // m_CinemachineTargetGroup.m_Targets[1].weight = 1;
- //}
- ///// <summary>
- ///// 释放目标
- ///// </summary>
- //public void ReleaseTarget()
- //{
- // LockTarget = null;
- // m_CinemachineTargetGroup.m_Targets[1].target = null;
- // m_CinemachineTargetGroup.m_Targets[1].weight = 0;
- //}
- /// <summary>
- /// 播放极限闪避效果
- /// </summary>
- /// <param name="_color"></param>
- public void PlyeExterme()
- {
- //m_MainCamera.GetComponent<AmplifyColorEffect>().enabled = true;
- }
- public void StopExterme()
- {
- //m_MainCamera.GetComponent<AmplifyColorEffect>().enabled = false;
- }
- /// <summary>
- /// 出生镜头切换到游戏镜头
- /// </summary>
- public void RespawnToPlay()
- {
- m_Timeline_CM_Respawn.gameObject.SetActive(false);
- //SwitchToCM_ThirdPerson();
- SwitchToCM_TopDown();
- }
- /// <summary>
- /// 切换到第三人称相机
- /// </summary>
- public void SwitchToCM_ThirdPerson()
- {
- m_CM_TopDown.gameObject.SetActive(false);
- m_CM_ThirdPerson.gameObject.SetActive(true);
- m_CM_Active = m_CM_ThirdPerson;
- }
- /// <summary>
- /// 切换到俯视相机
- /// </summary>
- public void SwitchToCM_TopDown()
- {
- m_CM_ThirdPerson.gameObject.SetActive(false);
- m_CM_TopDown.gameObject.SetActive(true);
- m_CM_Active = m_CM_TopDown;
- }
- /// <summary>
- /// 切换到胜利相机
- /// </summary>
- public void SwitchToCM_Win()
- {
- m_CM_ThirdPerson.gameObject.SetActive(false);
- m_CM_TopDown.gameObject.SetActive(false);
- m_CM_Win.gameObject.SetActive(true);
- //m_CM_Win.m_XAxis.Value = m_CM_Win.m_XAxis.Value + m_Hero.eulerAngles.y;
- m_CM_Active = m_CM_Win;
- }
- public void SwitchCameraState()
- {
- if(m_CM_Active == m_CM_TopDown)
- {
- SwitchToCM_ThirdPerson();
- }
- else if (m_CM_Active == m_CM_ThirdPerson)
- {
- SwitchToCM_TopDown();
- }
- }
- //void OnGUI()
- //{
- // //默认CullingMask=-1,即渲染任何层
- // if (GUI.Button(new Rect(10.0f, 10.0f, 200.0f, 45.0f), "CullingMask=-1"))
- // {
- // m_MainCamera.cullingMask = -1;
- // }
- // //不渲染任何层
- // if (GUI.Button(new Rect(10.0f, 60.0f, 200.0f, 45.0f), "CullingMask=0"))
- // {
- // m_MainCamera.cullingMask = 0;
- // }
- // //仅渲染第0层
- // if (GUI.Button(new Rect(10.0f, 110.0f, 200.0f, 45.0f), "CullingMask=1<<0"))
- // {
- // m_MainCamera.cullingMask = 1 << 0;
- // }
- // //仅渲染第8层
- // if (GUI.Button(new Rect(10.0f, 160.0f, 200.0f, 45.0f), "CullingMask=1<<8"))
- // {
- // m_MainCamera.cullingMask = 1 << 8;
- // }
- // //渲染第8层与第0层
- // if (GUI.Button(new Rect(10.0f, 210.0f, 200.0f, 45.0f), "CullingMask=0&&8"))
- // {
- // //注:不可大意写成camera.cullingMask = 1 << 8+1;或
- // //camera.cullingMask = 1+1<<8 ;因为根据运算符优先次序其分别等价于
- // //camera.cullingMask = 1 << (8+1)和camera.cullingMask = (1+1)<<8
- // m_MainCamera.cullingMask = (1 << 8) + 1;
- // }
- //}
- #if UNITY_EDITOR
- /// <summary>
- /// 绘制视野配置
- /// </summary>
- private void OnDrawGizmosSelected()
- {
- Vector3 forward = transform.forward;
- UnityEditor.Handles.color = new Color(1.0f, 0.0f, 0.0f, 0.1f);
- Vector3 rotatedForward = Quaternion.Euler(0, -m_Angle * 0.5f, 0) * transform.forward;
- UnityEditor.Handles.DrawSolidArc(transform.position, Vector3.up, rotatedForward, m_Angle, m_Sight);
- }
- #endif
- }
- }
|