87 lines
1.7 KiB
C#
87 lines
1.7 KiB
C#
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class FishPartAnimParent : MonoBehaviour
|
|
{
|
|
public float speed = 1f;
|
|
|
|
public float speedFast = 2f;
|
|
|
|
[ReadOnly]
|
|
public float speedCurrent = 1f;
|
|
|
|
[ReadOnly]
|
|
public float currentMultiplier = 1f;
|
|
|
|
public float duration = 0.3f;
|
|
|
|
public float durationShakeFactor = 0.3f;
|
|
|
|
public float fastDuration;
|
|
|
|
public float fastMultiplier = 1.5f;
|
|
|
|
public float swimSpeed = 0.9f;
|
|
|
|
public float swimMultiplier = 0.5f;
|
|
|
|
[ReadOnly]
|
|
public bool isFastAnim;
|
|
|
|
[ReadOnly]
|
|
public float currentDuration = 0.3f;
|
|
|
|
[ReadOnly]
|
|
public float timer;
|
|
|
|
[ReadOnly]
|
|
public float direction = 1f;
|
|
|
|
private void Start()
|
|
{
|
|
currentDuration = duration;
|
|
swimSpeed = 1.1f;
|
|
swimMultiplier = 1.7f;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (duration == 0f || currentDuration == 0f || Time.timeScale == 0f)
|
|
{
|
|
return;
|
|
}
|
|
timer += direction * Time.deltaTime * speedCurrent;
|
|
if ((timer > currentDuration && direction > 0f) || (timer < 0f && direction < 0f))
|
|
{
|
|
float num = ((!isFastAnim) ? duration : fastDuration);
|
|
if (!isFastAnim)
|
|
{
|
|
num += Random.Range((0f - num) * durationShakeFactor, num * durationShakeFactor);
|
|
}
|
|
currentDuration = num;
|
|
timer = Mathf.Clamp(timer, 0f, currentDuration);
|
|
direction *= -1f;
|
|
}
|
|
}
|
|
|
|
public void SetFastAnim(bool turnOn)
|
|
{
|
|
LeanTween.value((!turnOn) ? 1f : 0f, (!turnOn) ? 0f : 1f, 0.2f).setOnUpdate(delegate(float val)
|
|
{
|
|
speedCurrent = Mathf.Lerp(1f, speedFast, val);
|
|
currentMultiplier = Mathf.Lerp(1f, fastMultiplier, val);
|
|
});
|
|
}
|
|
|
|
public void SetSwimAnim(bool swimAnim)
|
|
{
|
|
speedCurrent = ((!swimAnim) ? speed : swimSpeed);
|
|
currentMultiplier = ((!swimAnim) ? 1f : swimMultiplier);
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
timer = currentDuration * 0.5f;
|
|
}
|
|
}
|