497 lines
12 KiB
C#
497 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class FishAnimSwim : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class FishAnimSwimPart
|
|
{
|
|
public Transform target;
|
|
|
|
[Space(10f)]
|
|
public bool updateTurnAroundRot = true;
|
|
|
|
public float turnAroundRot = 30f;
|
|
|
|
[Space(10f)]
|
|
public bool updateRotation = true;
|
|
|
|
public float swimFastRot = 15f;
|
|
|
|
public float offset;
|
|
|
|
[Space(10f)]
|
|
public bool updatePosition;
|
|
|
|
public bool updatePositionOnce;
|
|
|
|
[HideInInspector]
|
|
public bool positionUpdated;
|
|
|
|
public float swimFastPos;
|
|
|
|
public float offsetPos;
|
|
|
|
[Space(10f)]
|
|
public float timeOffset;
|
|
|
|
[ReadOnly]
|
|
public float timer;
|
|
|
|
[ReadOnly]
|
|
public float direction = 1f;
|
|
|
|
public Vector3 vectorZ;
|
|
|
|
public Vector3 posOffset;
|
|
|
|
public FishAnimSwimPart()
|
|
{
|
|
vectorZ = Vector3.forward;
|
|
posOffset = Vector3.zero;
|
|
}
|
|
}
|
|
|
|
public List<FishAnimSwimPart> animParts = new List<FishAnimSwimPart>();
|
|
|
|
public float currentAngle;
|
|
|
|
[ReadOnly]
|
|
private Vector3 tempRotation = Vector3.zero;
|
|
|
|
[ReadOnly]
|
|
private Vector3 tempPosition = Vector3.zero;
|
|
|
|
[ReadOnly]
|
|
public float rotationTimer;
|
|
|
|
[ReadOnly]
|
|
public bool isRotating;
|
|
|
|
public bool useXAxisForSwim;
|
|
|
|
public Vector2 speed = new Vector2(1f, 5f);
|
|
|
|
public float currentSpeed;
|
|
|
|
[ReadOnly]
|
|
public float currentWatchFishSpeed;
|
|
|
|
[ReadOnly]
|
|
public float fightSpeedTimer;
|
|
|
|
public float currentAnimForce = 1f;
|
|
|
|
public Vector2 speedAnimFactor = new Vector2(1f, 0.1f);
|
|
|
|
public Vector2 speedFightFactor = new Vector2(2f, 2f);
|
|
|
|
public Vector2 speedWatchFactor = new Vector2(0.01f, 0.01f);
|
|
|
|
public Vector2 speedWatchHandsFactor = new Vector2(0.01f, 0.01f);
|
|
|
|
private Vector2 speedNetFactor = new Vector2(1.3f, 0.35f);
|
|
|
|
public float speedTryingBaitFactor = 0.1f;
|
|
|
|
private float duration = 1f;
|
|
|
|
[ReadOnly]
|
|
public float currentDuration = 1f;
|
|
|
|
public AnimationCurve curve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
|
|
|
|
[Header("Up/Down Anim")]
|
|
private LTDescr upDownTween;
|
|
|
|
public Transform upDownTransform;
|
|
|
|
public Vector3 upDownAxisRotation = Vector3.forward;
|
|
|
|
public float upDownMaxRotation = 10f;
|
|
|
|
public float upDownMaxSpeed = 0.2f;
|
|
|
|
public float upDownMoveMultiplier;
|
|
|
|
public float upDownCurrentStrength;
|
|
|
|
[HideInInspector]
|
|
public Fish fish;
|
|
|
|
[ReadOnly]
|
|
public bool isTurnedOn;
|
|
|
|
[ReadOnly]
|
|
public float prevValueMultiplier;
|
|
|
|
private void Start()
|
|
{
|
|
speedFightFactor.x = speedAnimFactor.x * 1.7f;
|
|
speedFightFactor.y = speedAnimFactor.y * 5f;
|
|
if (upDownTransform == null && animParts.Count > 0 && (bool)animParts[0].target)
|
|
{
|
|
upDownTransform = animParts[0].target.parent;
|
|
}
|
|
Reset();
|
|
}
|
|
|
|
public void CalculateFigthSpeed()
|
|
{
|
|
fightSpeedTimer -= Time.deltaTime;
|
|
if (!(fightSpeedTimer <= 0f))
|
|
{
|
|
return;
|
|
}
|
|
if (UnityEngine.Random.value < 0.1f)
|
|
{
|
|
FightSquirm();
|
|
upDownCurrentStrength = 2f;
|
|
return;
|
|
}
|
|
fightSpeedTimer = UnityEngine.Random.Range(1f, 5f);
|
|
float num = 1f;
|
|
num = ((!(currentAnimForce > 0.5f)) ? UnityEngine.Random.Range(0.6f, 1f) : UnityEngine.Random.Range(0f, 0.4f));
|
|
num *= Mathf.Lerp(0.5f, 1f, fish.DurabilityCurrentRatio);
|
|
LeanTween.value(currentAnimForce, num, 0.5f).setOnUpdate(delegate(float value)
|
|
{
|
|
currentSpeed = Mathf.Lerp(speed.y * 0.6f, speed.y * 1.2f, value);
|
|
currentAnimForce = value;
|
|
});
|
|
upDownCurrentStrength = currentAnimForce * UnityEngine.Random.Range(0.8f, 1.2f);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Time.timeScale == 0f && (bool)fish)
|
|
{
|
|
return;
|
|
}
|
|
if ((bool)fish)
|
|
{
|
|
if (!fish.isFighting || !fish.isJerked || fish.isWatchingFish || fish.isInNetArea || fish.isTryingBait)
|
|
{
|
|
if (upDownTween != null)
|
|
{
|
|
StopUpDownAnim();
|
|
}
|
|
}
|
|
else if (fish.isFighting && upDownTween != null)
|
|
{
|
|
}
|
|
}
|
|
if (!fish)
|
|
{
|
|
currentSpeed = speed.x;
|
|
}
|
|
else if (fish.isTryingBait || fish.isNearBait)
|
|
{
|
|
currentSpeed = speed.x;
|
|
}
|
|
else if (fish.isFighting && !fish.isWatchingFish && !fish.isInNetArea)
|
|
{
|
|
CalculateFigthSpeed();
|
|
}
|
|
else if (!fish.enabled)
|
|
{
|
|
currentSpeed = speed.y;
|
|
}
|
|
else
|
|
{
|
|
currentSpeed = Mathf.Lerp(speed.x, speed.y, fish.currentSpeed / fish.fishSpeed.y);
|
|
}
|
|
FishAnimSwimPart fishAnimSwimPart = null;
|
|
currentDuration = 1f;
|
|
bool flag = isRotating;
|
|
isRotating = Mathf.Abs(currentAngle) > 5f;
|
|
if (!fish || fish.isFighting)
|
|
{
|
|
}
|
|
if ((bool)fish && (fish.isWatchingFish || fish.isInNetArea || fish.isTryingBait || fish.isJumping || fish.isReleasing))
|
|
{
|
|
isRotating = false;
|
|
}
|
|
else if ((bool)fish && fish.isFighting)
|
|
{
|
|
isRotating = false;
|
|
}
|
|
if (isRotating && (bool)fish)
|
|
{
|
|
if (!flag)
|
|
{
|
|
rotationTimer = ((!fish.isFighting) ? 0.1f : 0.2f);
|
|
}
|
|
if (rotationTimer > 0f)
|
|
{
|
|
rotationTimer -= Time.deltaTime;
|
|
}
|
|
}
|
|
if ((bool)GameController.Instance && !GameController.Instance.useFishRotationDuringFight)
|
|
{
|
|
rotationTimer = 0f;
|
|
}
|
|
for (int i = 0; i < animParts.Count; i++)
|
|
{
|
|
if (animParts[i].target == null)
|
|
{
|
|
continue;
|
|
}
|
|
if (!fish || !fish.isWatchingFish || i == animParts.Count - 1)
|
|
{
|
|
}
|
|
fishAnimSwimPart = animParts[i];
|
|
tempRotation = fishAnimSwimPart.target.localEulerAngles;
|
|
tempPosition = fishAnimSwimPart.target.localPosition;
|
|
if (fishAnimSwimPart.positionUpdated && fishAnimSwimPart.updatePositionOnce)
|
|
{
|
|
fishAnimSwimPart.updatePosition = false;
|
|
}
|
|
else if (fishAnimSwimPart.updatePositionOnce && !fishAnimSwimPart.positionUpdated)
|
|
{
|
|
fishAnimSwimPart.updatePosition = true;
|
|
fishAnimSwimPart.positionUpdated = true;
|
|
}
|
|
if (isRotating && rotationTimer <= 0f)
|
|
{
|
|
if (fishAnimSwimPart.updateTurnAroundRot)
|
|
{
|
|
tempRotation.y = fishAnimSwimPart.offset + fishAnimSwimPart.turnAroundRot * Mathf.Clamp((0f - currentAngle) / 180f, -1f, 1f);
|
|
fishAnimSwimPart.target.localEulerAngles = tempRotation;
|
|
}
|
|
continue;
|
|
}
|
|
fishAnimSwimPart.timer += fishAnimSwimPart.direction * Time.unscaledDeltaTime * currentSpeed;
|
|
if ((fishAnimSwimPart.timer > currentDuration && fishAnimSwimPart.direction > 0f) || (fishAnimSwimPart.timer < 0f && fishAnimSwimPart.direction < 0f))
|
|
{
|
|
fishAnimSwimPart.timer = Utilities.PingPongValue(fishAnimSwimPart.timer, 0f, currentDuration);
|
|
fishAnimSwimPart.direction *= -1f;
|
|
}
|
|
float t = curve.Evaluate(fishAnimSwimPart.timer / currentDuration);
|
|
float num = 0f;
|
|
if (fishAnimSwimPart.updateRotation)
|
|
{
|
|
num = Mathf.Lerp(0f - fishAnimSwimPart.swimFastRot, fishAnimSwimPart.swimFastRot, t);
|
|
}
|
|
if (fishAnimSwimPart.updatePosition)
|
|
{
|
|
num = Mathf.Lerp(0f - fishAnimSwimPart.swimFastPos, fishAnimSwimPart.swimFastPos, t);
|
|
}
|
|
if (!fish)
|
|
{
|
|
if (base.gameObject.HasTag("BAIT"))
|
|
{
|
|
if ((bool)GameController.Instance && GameController.Instance.fishingPlayer.underwaterCamera.isTurnedOn)
|
|
{
|
|
prevValueMultiplier = speedWatchFactor.x;
|
|
}
|
|
else
|
|
{
|
|
prevValueMultiplier = speedWatchFactor.y;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
prevValueMultiplier = Mathf.Lerp(speedAnimFactor.y, speedAnimFactor.x, 0.4f);
|
|
}
|
|
}
|
|
else if (fish.isWatchingFish && fish.watchStyle == Fish.WatchStyle.HOOK_LIGHT)
|
|
{
|
|
prevValueMultiplier = Mathf.Lerp(speedWatchFactor.y, speedWatchFactor.x, currentWatchFishSpeed);
|
|
}
|
|
else if (fish.isWatchingFish)
|
|
{
|
|
prevValueMultiplier = Mathf.Lerp(speedWatchHandsFactor.y, speedWatchHandsFactor.x, currentWatchFishSpeed);
|
|
}
|
|
else if (fish.isInNetArea)
|
|
{
|
|
prevValueMultiplier = Mathf.Lerp(speedNetFactor.y * 0.2f, speedNetFactor.x * 0.2f, currentWatchFishSpeed);
|
|
}
|
|
else if (fish.isOnGround)
|
|
{
|
|
prevValueMultiplier = Mathf.Lerp(speedNetFactor.y * 0.2f, speedNetFactor.x * 0.2f, currentWatchFishSpeed);
|
|
}
|
|
else if (fish.isTryingBait)
|
|
{
|
|
prevValueMultiplier = Mathf.MoveTowards(prevValueMultiplier, 0.04f, Time.deltaTime * 0.5f);
|
|
}
|
|
else if (fish.isNearBait)
|
|
{
|
|
prevValueMultiplier = Mathf.MoveTowards(prevValueMultiplier, 0.1f, Time.deltaTime * 0.1f);
|
|
}
|
|
else if (fish.isFighting)
|
|
{
|
|
prevValueMultiplier = Mathf.Lerp(speedFightFactor.y, speedFightFactor.x, currentAnimForce);
|
|
}
|
|
else
|
|
{
|
|
prevValueMultiplier = Mathf.Lerp(speedAnimFactor.y, speedAnimFactor.x, 1f - currentSpeed / speed.y);
|
|
}
|
|
num *= prevValueMultiplier;
|
|
if ((bool)fish && fish.isWatchingFish && fish.watchStyle == Fish.WatchStyle.HANDS && i >= animParts.Count - 2)
|
|
{
|
|
num *= 10f;
|
|
}
|
|
if (fishAnimSwimPart.updateRotation)
|
|
{
|
|
if (useXAxisForSwim)
|
|
{
|
|
tempRotation.x = fishAnimSwimPart.offset + num;
|
|
}
|
|
else
|
|
{
|
|
tempRotation.y = fishAnimSwimPart.offset + num;
|
|
}
|
|
fishAnimSwimPart.target.localEulerAngles = tempRotation;
|
|
}
|
|
if (fishAnimSwimPart.updatePosition)
|
|
{
|
|
tempPosition = fishAnimSwimPart.posOffset + fishAnimSwimPart.vectorZ * (fishAnimSwimPart.offsetPos + num);
|
|
fishAnimSwimPart.target.localPosition = tempPosition;
|
|
}
|
|
}
|
|
if (animParts.Count > 8 && animParts[0].direction > 0f && animParts[8].direction > 0f)
|
|
{
|
|
float num2 = animParts[0].timer - animParts[8].timer;
|
|
}
|
|
}
|
|
|
|
public void SetRotationAngle(float angle)
|
|
{
|
|
currentAngle = angle;
|
|
}
|
|
|
|
public void FightSquirm()
|
|
{
|
|
fightSpeedTimer = UnityEngine.Random.Range(1.5f, 2.5f);
|
|
LeanTween.value(currentAnimForce, 1f, 0.2f).setOnUpdate(delegate(float value)
|
|
{
|
|
currentAnimForce = value;
|
|
});
|
|
currentSpeed = speed.y * 1.5f;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
SetRotationAngle(0f);
|
|
ResetEditor();
|
|
}
|
|
|
|
public void TurnOn(bool turnOn)
|
|
{
|
|
if (base.enabled != turnOn)
|
|
{
|
|
base.enabled = turnOn;
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void ResetEditor()
|
|
{
|
|
FishAnimSwimPart fishAnimSwimPart = null;
|
|
for (int i = 0; i < animParts.Count; i++)
|
|
{
|
|
if (animParts[i].target == null)
|
|
{
|
|
continue;
|
|
}
|
|
fishAnimSwimPart = animParts[i];
|
|
if (i == 0)
|
|
{
|
|
fishAnimSwimPart.timer = fishAnimSwimPart.timeOffset;
|
|
fishAnimSwimPart.direction = 1f;
|
|
}
|
|
else
|
|
{
|
|
fishAnimSwimPart.timer = animParts[i - 1].timer + (0f - fishAnimSwimPart.timeOffset) * animParts[i - 1].direction;
|
|
fishAnimSwimPart.direction = animParts[i - 1].direction;
|
|
if (fishAnimSwimPart.timer < 0f || fishAnimSwimPart.timer > 1f)
|
|
{
|
|
fishAnimSwimPart.timer = Utilities.PingPongValue(fishAnimSwimPart.timer, 0f, 1f);
|
|
fishAnimSwimPart.direction *= -1f;
|
|
}
|
|
}
|
|
if (fishAnimSwimPart.updateRotation)
|
|
{
|
|
tempRotation = fishAnimSwimPart.target.localEulerAngles;
|
|
tempRotation.y = fishAnimSwimPart.offset;
|
|
fishAnimSwimPart.target.localEulerAngles = tempRotation;
|
|
}
|
|
if (fishAnimSwimPart.updatePosition)
|
|
{
|
|
tempPosition = fishAnimSwimPart.target.localPosition;
|
|
tempPosition.z = fishAnimSwimPart.offsetPos;
|
|
fishAnimSwimPart.target.localPosition = tempPosition;
|
|
}
|
|
}
|
|
if (animParts.Count > 8 && animParts[0].direction > 0f && animParts[8].direction > 0f)
|
|
{
|
|
float num = animParts[0].timer - animParts[8].timer;
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void SetTurnAroundEditor()
|
|
{
|
|
FishAnimSwimPart fishAnimSwimPart = null;
|
|
for (int i = 0; i < animParts.Count; i++)
|
|
{
|
|
if (!(animParts[i].target == null))
|
|
{
|
|
fishAnimSwimPart = animParts[i];
|
|
if (fishAnimSwimPart.updateRotation)
|
|
{
|
|
tempRotation = fishAnimSwimPart.target.localEulerAngles;
|
|
tempRotation.y = fishAnimSwimPart.offset + fishAnimSwimPart.turnAroundRot;
|
|
fishAnimSwimPart.target.localEulerAngles = tempRotation;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void StartUpDownAnim()
|
|
{
|
|
if (upDownTween != null)
|
|
{
|
|
LeanTween.cancel(upDownTween.id);
|
|
upDownTween = null;
|
|
}
|
|
Debug.Log("StartUpDownAnim");
|
|
upDownTween = LeanTween.value(0f - upDownMaxRotation, upDownMaxRotation, upDownMaxSpeed).setLoopPingPong().setEaseInOutQuad()
|
|
.setOnUpdate(delegate(float value)
|
|
{
|
|
value *= upDownCurrentStrength;
|
|
upDownTransform.localEulerAngles = new Vector3((upDownAxisRotation.x == 0f) ? upDownTransform.localEulerAngles.x : value, (upDownAxisRotation.y == 0f) ? upDownTransform.localEulerAngles.y : value, (upDownAxisRotation.z == 0f) ? upDownTransform.localEulerAngles.z : value);
|
|
upDownTransform.localPosition = new Vector3(upDownTransform.localPosition.x, (0f - value) * upDownMoveMultiplier, upDownTransform.localPosition.z);
|
|
})
|
|
.setOnComplete((Action)delegate
|
|
{
|
|
});
|
|
}
|
|
|
|
[Button]
|
|
public void StopUpDownAnim()
|
|
{
|
|
Debug.Log("StopUpDownAnim");
|
|
upDownTransform.localEulerAngles = new Vector3(upDownTransform.localEulerAngles.x, upDownTransform.localEulerAngles.y, 0f);
|
|
upDownTransform.localPosition = new Vector3(upDownTransform.localPosition.x, 0f, upDownTransform.localPosition.z);
|
|
if (upDownTween != null)
|
|
{
|
|
LeanTween.cancel(upDownTween.id);
|
|
upDownTween = null;
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void MakeSound()
|
|
{
|
|
AudioController.Play("Fish_UnderwaterSquirm_01", base.transform);
|
|
}
|
|
|
|
public void FishTryingFeeder(bool turnOn)
|
|
{
|
|
}
|
|
}
|