197 lines
4.2 KiB
C#
197 lines
4.2 KiB
C#
using LuxWater;
|
|
using UnityEngine;
|
|
using UnityEngine.AzureSky;
|
|
|
|
public class UnderwaterCamera : MonoBehaviour
|
|
{
|
|
public enum ViewType
|
|
{
|
|
FloatView = 0,
|
|
BaitView = 1
|
|
}
|
|
|
|
public bool AllowRotation = true;
|
|
|
|
public bool clickToRotate;
|
|
|
|
public Transform target;
|
|
|
|
public float distance = 5f;
|
|
|
|
public float xSpeed = 120f;
|
|
|
|
public float ySpeed = 120f;
|
|
|
|
public float yMinLimit = -20f;
|
|
|
|
public float yMaxLimit = 80f;
|
|
|
|
public float distanceMin = 0.5f;
|
|
|
|
public float distanceMax = 15f;
|
|
|
|
public float XInit;
|
|
|
|
public float YInit = 60f;
|
|
|
|
private ViewType viewType = ViewType.BaitView;
|
|
|
|
[SerializeField]
|
|
private LayerMask underwaterLayersMask;
|
|
|
|
[SerializeField]
|
|
private LayerMask topwaterLayersMask;
|
|
|
|
[HideInInspector]
|
|
public FRod currentRod;
|
|
|
|
private LuxWater_WaterVolume waterUnderWaterVolume;
|
|
|
|
private AzureFogScattering fog;
|
|
|
|
private Camera mCamera;
|
|
|
|
private FWaterDisplacement fWaterDisplacement;
|
|
|
|
private float x;
|
|
|
|
private float y;
|
|
|
|
public static bool rightclicked;
|
|
|
|
private bool isCameraCollide;
|
|
|
|
private AudioSource ownAudio;
|
|
|
|
[HideInInspector]
|
|
public int i;
|
|
|
|
public void Start()
|
|
{
|
|
x = XInit;
|
|
y = YInit;
|
|
i = 0;
|
|
mCamera = GetComponent<Camera>();
|
|
ownAudio = GetComponent<AudioSource>();
|
|
waterUnderWaterVolume = Object.FindObjectOfType<LuxWater_WaterVolume>();
|
|
waterUnderWaterVolume.enabled = true;
|
|
EnableDisableAllAudioOnScene(val: false);
|
|
fog = mCamera.GetComponent<AzureFogScattering>();
|
|
fog.enabled = false;
|
|
if (viewType == ViewType.BaitView)
|
|
{
|
|
target = currentRod.LureHookWaterDisplacement.transform;
|
|
fWaterDisplacement = currentRod.LureHookWaterDisplacement;
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (AllowRotation)
|
|
{
|
|
rightclicked = Input.GetMouseButton(1);
|
|
}
|
|
if (i == 0)
|
|
{
|
|
x += Input.GetAxis("Mouse X") * xSpeed * distance * 0.02f;
|
|
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
|
|
y = ClampAngle(y, yMinLimit, yMaxLimit);
|
|
Quaternion quaternion = Quaternion.Euler(y, x, 0f);
|
|
distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * 5f, distanceMin, distanceMax);
|
|
Vector3 vector = new Vector3(0f, 0f, 0f - distance);
|
|
Vector3 position = quaternion * vector + target.position;
|
|
base.transform.rotation = quaternion;
|
|
base.transform.position = position;
|
|
i = 1;
|
|
}
|
|
else if ((bool)target)
|
|
{
|
|
x += Input.GetAxis("Mouse X") * xSpeed * distance * 0.02f;
|
|
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
|
|
y = ClampAngle(y, yMinLimit, yMaxLimit);
|
|
Quaternion quaternion2 = Quaternion.Euler(y, x, 0f);
|
|
distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * 5f, distanceMin, distanceMax);
|
|
Vector3 vector2 = new Vector3(0f, 0f, 0f - distance);
|
|
Vector3 position2 = quaternion2 * vector2 + target.position;
|
|
base.transform.rotation = quaternion2;
|
|
base.transform.position = position2;
|
|
}
|
|
_ = base.transform.position - target.position;
|
|
if (isCameraCollide)
|
|
{
|
|
distance = Mathf.MoveTowards(distance, distanceMin, Time.deltaTime * 10f);
|
|
}
|
|
if (!fWaterDisplacement)
|
|
{
|
|
return;
|
|
}
|
|
if (base.transform.position.y < fWaterDisplacement.waterHeightPosition)
|
|
{
|
|
if (!ownAudio.enabled)
|
|
{
|
|
if (!ownAudio.enabled)
|
|
{
|
|
EnableDisableAllAudioOnScene(val: false);
|
|
}
|
|
ownAudio.enabled = true;
|
|
mCamera.cullingMask = underwaterLayersMask;
|
|
fog.enabled = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (ownAudio.enabled)
|
|
{
|
|
EnableDisableAllAudioOnScene(val: true);
|
|
}
|
|
ownAudio.enabled = false;
|
|
mCamera.cullingMask = topwaterLayersMask;
|
|
fog.enabled = true;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
{
|
|
isCameraCollide = true;
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
isCameraCollide = false;
|
|
}
|
|
|
|
public static float ClampAngle(float angle, float min, float max)
|
|
{
|
|
if (angle < -360f)
|
|
{
|
|
angle += 360f;
|
|
}
|
|
if (angle > 360f)
|
|
{
|
|
angle -= 360f;
|
|
}
|
|
return Mathf.Clamp(angle, min, max);
|
|
}
|
|
|
|
private void EnableDisableAllAudioOnScene(bool val)
|
|
{
|
|
AudioSource[] array = Object.FindObjectsOfType<AudioSource>();
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
if (ownAudio != array[i])
|
|
{
|
|
array[i].enabled = val;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if ((bool)waterUnderWaterVolume)
|
|
{
|
|
waterUnderWaterVolume.enabled = false;
|
|
}
|
|
EnableDisableAllAudioOnScene(val: true);
|
|
}
|
|
}
|