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

210 lines
4.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using BitStrap;
using UnityEngine;
public class FishAnimationController : MonoBehaviour
{
public enum AnimType
{
SWIM = 0,
PULL = 1,
WATCH = 2,
TRYING_BAIT = 3,
NONE = 4
}
[ReadOnly]
public AnimType currentAnimType = AnimType.NONE;
public FishAnimSwim fishAnimSwim;
public FishAnimSwim fishAnimPull;
public List<FishPartAnimParent> fishWatchAnims = new List<FishPartAnimParent>();
public FishPartAnim mouth;
public List<FishPartAnim> fishWatchAnimParts = new List<FishPartAnim>();
[ReadOnly]
public float squirmTimer;
[HideInInspector]
public Fish fish;
[HideInInspector]
public Animator animator;
private void Awake()
{
}
public void Initialize()
{
fish = GetComponent<Fish>();
animator = fish.modelRig.GetComponent<Animator>();
if ((bool)fishAnimSwim)
{
fishAnimSwim.fish = fish;
}
if ((bool)fishAnimPull)
{
fishAnimPull.fish = fish;
}
currentAnimType = AnimType.NONE;
ChangeAnimation(AnimType.SWIM);
}
public void ChangeAnimation(AnimType animType)
{
if (currentAnimType != animType)
{
if ((bool)fishAnimSwim)
{
fishAnimSwim.TurnOn(true);
}
if ((bool)fishAnimPull)
{
fishAnimPull.TurnOn(false);
}
if (fishWatchAnims.Count > 0)
{
fishWatchAnims[0].enabled = false;
}
fish.isTryingBait = animType == AnimType.TRYING_BAIT;
StartWatchFish(animType == AnimType.WATCH);
if ((bool)mouth)
{
mouth.enabled = animType == AnimType.WATCH || animType == AnimType.TRYING_BAIT;
}
else
{
Debug.LogError("No mouth in fish :" + base.name);
}
currentAnimType = animType;
}
}
public void SwimAnimationUpdate()
{
if (fish == null)
{
Initialize();
}
if (fish.isWatchingFish || fish.isInNetArea)
{
squirmTimer -= Time.deltaTime;
if (squirmTimer <= 0f)
{
float num = Random.Range(0.2f, 0.3f);
if (fish.isWatchingFish)
{
squirmTimer = Random.Range(3f, 10f);
num *= fish.Strength;
}
else
{
squirmTimer = Random.Range(7f, 12f);
num *= 10f;
}
StartCoroutine(fish.animController.Squirm(num));
}
}
else if (fish.bt.enabled && (bool)fishAnimSwim)
{
float angle180Range = Utilities.GetAngle180Range(fish.targetLookRotation.y);
angle180Range = Mathf.Clamp(angle180Range, 0f - fish.fishMaxAngle, fish.fishMaxAngle);
angle180Range = ((!fish.isFighting) ? Mathf.MoveTowards(fish.currentLookRotation.y, angle180Range, 160f * Time.deltaTime) : Mathf.MoveTowards(fish.currentLookRotation.y, angle180Range, 250f * Time.deltaTime));
if (Mathf.Abs(angle180Range) < 0.5f)
{
angle180Range = 0f;
}
fish.currentLookRotation.y = angle180Range;
fishAnimSwim.SetRotationAngle(angle180Range * 4f);
}
}
public IEnumerator Squirm(float strength)
{
float leanTime = 1f;
LeanTween.value(0f, 1f, leanTime).setOnUpdate(delegate(float val)
{
if (fish.isWatchingFish)
{
fishAnimSwim.currentWatchFishSpeed = val;
}
else if (fish.isInNetArea)
{
fishAnimSwim.currentWatchFishSpeed = val;
}
else if (!fish.isFighting)
{
}
});
AudioController.Play("SplashFish_01", Mathf.Lerp(0.5f, 1f, Mathf.InverseLerp(0.1f, 5f, fish.Length)));
yield return new WaitForSeconds(leanTime);
if (fish.isWatchingFish && fish.fishingPlayer.currentWatchStyle != Fish.WatchStyle.HANDS)
{
fish.fishingPlayer.WaterSplash(strength * 1f, 1f);
}
else if (!fish.isInNetArea)
{
}
if (fish.isInNetArea && !fish.isWatchingFish)
{
fish.particleSwim.Play();
}
yield return new WaitForSeconds(strength * 1f);
LeanTween.value(1f, 0f, leanTime).setOnUpdate(delegate(float val)
{
if (fish.isWatchingFish)
{
fishAnimSwim.currentWatchFishSpeed = val;
}
else if (fish.isInNetArea)
{
fishAnimSwim.currentWatchFishSpeed = val;
}
else if (!fish.isFighting)
{
}
});
fish.particleSwim.Stop();
}
[Button]
public void ToggleMouth()
{
OpenMouth(Random.Range(0, 2) > 0);
}
public void OpenMouth(bool open)
{
if (!(mouth == null))
{
mouth.SetStartValue(open);
}
}
public void StartWatchFish(bool animate)
{
if (mouth == null)
{
return;
}
OpenMouth(false);
mouth.Reset();
mouth.enabled = animate;
foreach (FishPartAnim fishWatchAnimPart in fishWatchAnimParts)
{
if (fishWatchAnimPart != null)
{
fishWatchAnimPart.enabled = animate && fish.watchStyle == Fish.WatchStyle.HANDS;
fishWatchAnimPart.enabled = false;
}
}
fishAnimSwim.currentWatchFishSpeed = 0f;
}
}