Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/WaterEffectsManager.cs
2026-02-21 16:45:37 +08:00

192 lines
5.0 KiB
C#

using System;
using System.Collections.Generic;
using BitStrap;
using UltimateWater;
using UnityEngine;
public class WaterEffectsManager : MonoBehaviour
{
public enum SplashSize
{
VERY_SMALL = 0,
SMALL = 1,
MEDIUM = 2,
LARGE = 3
}
public List<ParticleSystem> splashParticlePrefabs = new List<ParticleSystem>();
public List<ParticleSystem> swimParticlePrefabs = new List<ParticleSystem>();
[Space(10f)]
public float splashWakeY = 1f;
public ParticleSystem splashWakePrefab;
public ParticleSystem splashWakeLoopedPrefab;
private ParticleSystem particleOutOfWater;
[ReadOnly]
public ParticleSystem splashWakeLooped;
public List<ParticleSystem> splashWakePool = new List<ParticleSystem>();
[ReadOnly]
public int currentSplashWake;
[ReadOnly]
public float randomFishSplashTimer;
public Vector2 randomFishSplashDelay = new Vector2(3f, 5f);
public void Initialize()
{
particleOutOfWater = UnityEngine.Object.Instantiate(GetSplashParticlePrefab(SplashSize.SMALL));
particleOutOfWater.transform.parent = base.transform;
particleOutOfWater.transform.eulerAngles = new Vector3(-90f, 0f, 0f);
splashWakeLooped = UnityEngine.Object.Instantiate(splashWakeLoopedPrefab);
splashWakeLooped.transform.parent = base.transform;
splashWakeLooped.transform.eulerAngles = new Vector3(-90f, 0f, 0f);
splashWakeLooped.Stop();
for (int i = 0; i < 5; i++)
{
ParticleSystem particleSystem = UnityEngine.Object.Instantiate(splashWakePrefab);
particleSystem.transform.parent = base.transform;
particleSystem.Stop();
splashWakePool.Add(particleSystem);
}
}
private void Update()
{
if (randomFishSplashTimer > 0f)
{
randomFishSplashTimer -= Time.deltaTime;
}
}
public void MakeRandomFishSplash(Fish fish, float distance)
{
if (fish == null)
{
return;
}
fish.WaterSplash(false, true, false, 180f);
fish.WaterSplash(false, true, false, 180f);
fish.WaterSplash(false, true, false, 180f);
LeanTween.delayedCall(0.15f, (Action)delegate
{
if ((bool)fish)
{
fish.WaterSplash(false, true, false, 140f);
}
});
LeanTween.delayedCall(0.3f, (Action)delegate
{
if ((bool)fish)
{
fish.WaterSplash(false, true, false, 140f);
}
});
if (distance > 20f)
{
LeanTween.delayedCall(0.3f, (Action)delegate
{
if ((bool)fish)
{
SplashWakeEffect(new Vector3(fish.transform.position.x, 1f, fish.transform.position.z), 7f);
}
});
}
if (fish.transform.position.y >= -1f)
{
if (UnityEngine.Random.value < 0.3f)
{
PlaySplashParticle(SplashSize.SMALL, new Vector3(fish.transform.position.x, 0.2f, fish.transform.position.z), new Vector3(-90f, 0f, 0f));
}
if (UnityEngine.Random.value < 0.3f)
{
AudioController.Play("SplashFish_01", base.transform.position, base.transform, 0.3f);
}
}
randomFishSplashTimer = UnityEngine.Random.Range(randomFishSplashDelay.x, randomFishSplashDelay.y);
}
public ParticleSystem GetSplashParticlePrefab(SplashSize splashSize)
{
return splashParticlePrefabs[(int)splashSize];
}
public void PlaySplashParticle(SplashSize splashSize, Vector3 pos, Vector3 rot, Transform parent = null)
{
ParticleSystem particleSystem = UnityEngine.Object.Instantiate(GetSplashParticlePrefab(splashSize));
particleSystem.transform.parent = parent;
particleSystem.transform.position = pos;
particleSystem.transform.eulerAngles = rot;
InitParticleDisplacement(particleSystem);
particleSystem.gameObject.AddComponent<DestroyParticleOnFinish>();
particleSystem.Play(true);
SplashWakeEffect(pos, 7f);
}
public ParticleSystem GetSwimParticlePrefab(SplashSize splashSize)
{
return swimParticlePrefabs[(int)splashSize];
}
public void PlayParticleOutOfWater(Vector3 pos)
{
particleOutOfWater.transform.position = pos;
particleOutOfWater.Play(true);
}
public void InitParticleDisplacement(ParticleSystem particleSystem)
{
if ((bool)particleSystem.GetComponentInChildren<WaterParticleDisplacement>()._System)
{
particleSystem.GetComponentInChildren<WaterParticleDisplacement>().Initialize(GameController.Instance.water);
}
}
[Button]
public void TestSplashWakeEffect()
{
SplashWakeEffect(GameController.Instance.fishingPlayer.currentHands.bait.transform.position, UnityEngine.Random.Range(0.2f, 2f));
}
public void SplashWakeEffect(Vector3 pos, float size)
{
ParticleSystem particleSystem = splashWakePool[currentSplashWake];
particleSystem.Stop(true);
pos.y = splashWakeY;
particleSystem.transform.position = pos;
particleSystem.transform.eulerAngles = new Vector3(-90f, 0f, 0f);
particleSystem.startSize = size;
particleSystem.Play(true);
currentSplashWake++;
if (currentSplashWake >= splashWakePool.Count)
{
currentSplashWake = 0;
}
}
public void SplashWakeLoopeEffect(bool play, Vector3 pos, float size)
{
if (play)
{
pos.y = splashWakeY;
splashWakeLooped.transform.position = pos;
if (!splashWakeLooped.isPlaying)
{
splashWakeLooped.startSize = size;
splashWakeLooped.Play(true);
}
}
else
{
splashWakeLooped.Stop();
}
}
}