备份CatanBuilding瘦身独立工程
This commit is contained in:
168
Assets/Scripts/Aquarium/AquariumCameraManager.cs
Normal file
168
Assets/Scripts/Aquarium/AquariumCameraManager.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using cfg;
|
||||
using Cinemachine;
|
||||
using DG.Tweening;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AquariumCameraManager : MonoBehaviour
|
||||
{
|
||||
public CinemachineVirtualCamera cameraVirtual;
|
||||
public CinemachineVirtualCamera[] followFishCameras;
|
||||
CinemachineVirtualCamera followFishCamera;
|
||||
int showCameraIndex = 0;
|
||||
|
||||
public GameObject crossbowGo;
|
||||
public CinemachineVirtualCamera followArrowCamera;
|
||||
public Camera crossbowCamera;
|
||||
public Transform handRoot;
|
||||
public Vector2 cameraOffset = Vector2.zero;
|
||||
public float startPosZ = -2;
|
||||
public float moveTimeZ = 0.5f;
|
||||
|
||||
public float cameraToFishDis = 3;//鱼最长包围盒的倍率,用于控制箭飞行时相机距离鱼的距离,和把鱼拉回来时距离相机的距离
|
||||
public float zoomFishExtraDistance = 1.5f;
|
||||
CrossbowCameraMove crossbowCameraMove;
|
||||
AquariumCameraMove aquariumCameraMove;
|
||||
public RenderTexture rt;
|
||||
FishMovement followFish;
|
||||
private void Awake()
|
||||
{
|
||||
for (int i = 0; i < followFishCameras.Length; i++)
|
||||
{
|
||||
followFishCameras[i].gameObject.SetActive(false);
|
||||
}
|
||||
crossbowGo.SetActive(false);
|
||||
crossbowCamera.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public Vector2 SetRotationAngle()
|
||||
{
|
||||
float halfFOV = 30;
|
||||
float maxX = Mathf.Max(0, cameraOffset.y - halfFOV);
|
||||
|
||||
//float aspect = (float)Screen.height / Screen.width;
|
||||
//aspect = Mathf.Min(Mathf.Max(aspect, 1f), 2.2f);
|
||||
|
||||
//float halfFOVInRadians = halfFOV * Mathf.Deg2Rad;
|
||||
//float tanHalfFOV = Mathf.Tan(halfFOVInRadians);
|
||||
//float angle = cameraOffset.x - Mathf.Atan(tanHalfFOV / aspect) * Mathf.Rad2Deg;
|
||||
//float maxY = Mathf.Max(0, angle);
|
||||
|
||||
float maxY = ConvertTools.CalculateActualRotationAngle(cameraOffset.x);
|
||||
return new Vector2(maxX, maxY);
|
||||
}
|
||||
|
||||
public void PlayAquarium(FishingAquariumAct fishingAquariumAct)
|
||||
{
|
||||
aquariumCameraMove = gameObject.AddComponent<AquariumCameraMove>();
|
||||
Vector2 vector = SetRotationAngle();
|
||||
aquariumCameraMove.Init(vector, fishingAquariumAct);
|
||||
transform.position = new Vector3(0, 0, startPosZ);
|
||||
}
|
||||
|
||||
public void FollowFishCamera(FishMovement fish)
|
||||
{
|
||||
followFish = fish;
|
||||
if (fish == null)
|
||||
{
|
||||
StopFollowFishCamera();
|
||||
return;
|
||||
}
|
||||
NextCamera();
|
||||
followFishCamera.gameObject.SetActive(true);
|
||||
}
|
||||
void NextCamera()
|
||||
{
|
||||
if (followFishCamera != null)
|
||||
{
|
||||
followFishCamera.gameObject.SetActive(false);
|
||||
}
|
||||
showCameraIndex++;
|
||||
showCameraIndex %= followFishCameras.Length;
|
||||
followFishCamera = followFishCameras[showCameraIndex];
|
||||
}
|
||||
public void FollowFishCamera(FishEgg egg)
|
||||
{
|
||||
followFish = null;
|
||||
if (egg == null)
|
||||
{
|
||||
StopFollowFishCamera();
|
||||
return;
|
||||
}
|
||||
NextCamera();
|
||||
followFishCamera.gameObject.SetActive(true);
|
||||
Vector3 targetPos = egg.transform.position;
|
||||
float r = /*followFish.AvoidRadius * cameraToFishDis + */zoomFishExtraDistance;
|
||||
targetPos.z -= r;
|
||||
followFishCamera.transform.position = targetPos;
|
||||
}
|
||||
|
||||
public void StopFollowFishCamera()
|
||||
{
|
||||
for (int i = 0; i < followFishCameras.Length; i++)
|
||||
{
|
||||
followFishCameras[i].gameObject.SetActive(false);
|
||||
}
|
||||
followFish = null;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (followFish != null)
|
||||
{
|
||||
Vector3 targetPos = followFish.transform.position;
|
||||
float r = followFish.AvoidRadius * cameraToFishDis + zoomFishExtraDistance;
|
||||
targetPos.z -= r;
|
||||
followFishCamera.transform.position = targetPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void MoveCamera()
|
||||
{
|
||||
transform.DOMoveZ(0, moveTimeZ).SetDelay(0.66f);
|
||||
}
|
||||
|
||||
public void PlayCrossbow(FishMovement guide)
|
||||
{
|
||||
crossbowGo.SetActive(true);
|
||||
crossbowCamera.gameObject.SetActive(true);
|
||||
crossbowCamera.targetTexture = rt;
|
||||
crossbowCameraMove = gameObject.AddComponent<CrossbowCameraMove>();
|
||||
Vector2 vector = SetRotationAngle();
|
||||
crossbowCameraMove.Init(this, handRoot, vector, guide);
|
||||
|
||||
}
|
||||
|
||||
public void Target()
|
||||
{
|
||||
crossbowCameraMove.Target();
|
||||
}
|
||||
|
||||
public void TriggerCrossbow(string value)
|
||||
{
|
||||
crossbowCameraMove.TriggerCrossbow(value);
|
||||
}
|
||||
|
||||
public void Shoot(float[] FxScale, Dictionary<string, GameObject> fx_hunt_prefab, bool isRob, float shootTime, FishMovement targetMovement)
|
||||
{
|
||||
crossbowCameraMove.Shoot(FxScale, fx_hunt_prefab, isRob, cameraToFishDis, shootTime, targetMovement);
|
||||
}
|
||||
|
||||
public float Capture(float fishToCameraDistance, float lineDrawMinTime, float lineDrawSpeed, FishMovement targetMovement)
|
||||
{
|
||||
return crossbowCameraMove.Capture(fishToCameraDistance, lineDrawMinTime, cameraToFishDis, lineDrawSpeed, targetMovement);
|
||||
}
|
||||
public void Captureed()
|
||||
{
|
||||
crossbowCameraMove.Captureed();
|
||||
}
|
||||
public void Escape(float arrowEscapeTime)
|
||||
{
|
||||
crossbowCameraMove.Escape(arrowEscapeTime);
|
||||
}
|
||||
public void HideCrossbow(bool isHide)
|
||||
{
|
||||
crossbowCameraMove.HideCrossbow(isHide);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user