Files
2026-02-21 16:45:37 +08:00

184 lines
4.0 KiB
C#

using UnityEngine;
public class Attractor : MonoBehaviour
{
public LayerMask fishLayer = -1;
public GameObject model;
public Transform grabPosition;
public float shakeAngle = 5f;
public string attractorSound = "Attractor_Sound_01";
public string voiceSound = "Attractor_Voice_01";
public float distance = 20f;
public float radius = 3f;
private AudioObject attractorAudioObject;
private AudioObject voiceAudioObject;
[HideInInspector]
public bool useAttractor;
[HideInInspector]
public FishingPlayer fishingPlayer;
private LTDescr shakeTween;
private LTDescr auraTween;
private LTDescr anomalyTween;
private CameraFilterPack_Vision_AuraDistortion auraDistortion;
private CameraFilterPack_3D_Anomaly anomaly;
private CameraFilterPack_Color_Contrast contrast;
private void Start()
{
}
public void InitShake()
{
if (shakeTween == null)
{
shakeTween = LeanTween.rotateAroundLocal(base.gameObject, Vector3.up, shakeAngle, 0.05f).setEase(LeanTweenType.easeShake).setLoopClamp()
.setRepeat(-1);
shakeTween.pause();
attractorAudioObject = AudioController.Play(attractorSound, base.transform);
voiceAudioObject = AudioController.Play(voiceSound, base.transform);
if ((bool)attractorAudioObject)
{
attractorAudioObject.Pause();
}
if ((bool)voiceAudioObject)
{
voiceAudioObject.Pause();
}
}
}
public void MakeUpdate()
{
if (shakeTween == null)
{
InitShake();
return;
}
if (auraDistortion == null)
{
auraDistortion = fishingPlayer.ufpsWeaponCamera.GetComponent<CameraFilterPack_Vision_AuraDistortion>();
}
if (anomaly == null)
{
anomaly = fishingPlayer.ufpsWeaponCamera.GetComponent<CameraFilterPack_3D_Anomaly>();
}
if (contrast == null)
{
contrast = fishingPlayer.ufpsWeaponCamera.GetComponent<CameraFilterPack_Color_Contrast>();
}
if (useAttractor)
{
if (shakeTween.direction == 0f)
{
shakeTween.resume();
anomaly.enabled = true;
auraDistortion.enabled = true;
contrast.enabled = true;
auraDistortion.Twist = 0.1f;
if ((bool)attractorAudioObject)
{
attractorAudioObject.Unpause(2f);
}
if ((bool)voiceAudioObject)
{
voiceAudioObject.Unpause(2f);
}
}
auraDistortion.Twist += 0.02f * Time.deltaTime;
if (auraDistortion.Twist > 0.16f)
{
auraDistortion.Twist = 0.16f;
}
anomaly.Intensity += 0.1f * Time.deltaTime;
if (anomaly.Intensity > 0.2f)
{
anomaly.Intensity = 0.2f;
}
contrast.Contrast += 0.05f * Time.deltaTime;
if (contrast.Contrast > 1.1f)
{
contrast.Contrast = 1.1f;
}
return;
}
if (shakeTween.direction != 0f)
{
shakeTween.pause();
if ((bool)attractorAudioObject)
{
attractorAudioObject.Pause(2f);
}
if ((bool)voiceAudioObject)
{
voiceAudioObject.Pause(2f);
}
}
auraDistortion.Twist -= 0.1f * Time.deltaTime;
if (auraDistortion.Twist <= 0f)
{
auraDistortion.Twist = 0f;
auraDistortion.enabled = false;
}
anomaly.Intensity -= 0.3f * Time.deltaTime;
if (anomaly.Intensity <= 0f)
{
anomaly.Intensity = 0f;
anomaly.enabled = false;
}
contrast.Contrast -= 0.1f * Time.deltaTime;
if (contrast.Contrast <= 1f)
{
contrast.Contrast = 1f;
contrast.enabled = false;
}
}
private void LateUpdate()
{
if (base.transform.localEulerAngles.y > shakeAngle && base.transform.localEulerAngles.y < 180f)
{
base.transform.localEulerAngles = new Vector3(0f, shakeAngle, 0f);
}
else if (base.transform.localEulerAngles.y < 360f - shakeAngle && base.transform.localEulerAngles.y > 180f)
{
base.transform.localEulerAngles = new Vector3(0f, 360f - shakeAngle, 0f);
}
}
public void HideAttractor()
{
shakeTween.pause();
if ((bool)attractorAudioObject)
{
attractorAudioObject.Pause(0.3f);
}
if ((bool)voiceAudioObject)
{
voiceAudioObject.Pause(0.3f);
}
auraDistortion.Twist = 0f;
auraDistortion.enabled = false;
anomaly.Intensity = 0f;
anomaly.enabled = false;
contrast.Contrast = 1f;
contrast.enabled = false;
}
}