250 lines
6.0 KiB
C#
250 lines
6.0 KiB
C#
using RootMotion.FinalIK;
|
|
using UnityEngine;
|
|
|
|
public class FishStats : MonoBehaviour
|
|
{
|
|
public enum FishType
|
|
{
|
|
Spokojnego_żeru = 0,
|
|
Drapieżnik = 1
|
|
}
|
|
|
|
public enum FishDeepType
|
|
{
|
|
Ogólny = 0,
|
|
Denny = 1,
|
|
Powierzchowny = 2
|
|
}
|
|
|
|
public GameManager.FishSpecies fishSpecies;
|
|
|
|
public string fishNameKey = "";
|
|
|
|
[Range(0f, 100f)]
|
|
public float currentFeed = 100f;
|
|
|
|
public float hungryFactor = 0.1f;
|
|
|
|
public float currentTimeLife;
|
|
|
|
public float maxTimeLife = 1000f;
|
|
|
|
[HideInInspector]
|
|
public float resetTimeLife;
|
|
|
|
public bool randomTimeLifeOnStart = true;
|
|
|
|
public float current_weight = 0.1f;
|
|
|
|
public float maxWeight = 12f;
|
|
|
|
public float minWeight = 0.1f;
|
|
|
|
[Range(0f, 1f)]
|
|
public float current_strenght = 1f;
|
|
|
|
public float minScale = 0.1f;
|
|
|
|
public float maxScale = 2f;
|
|
|
|
public AnimationCurve weightScaleCurve;
|
|
|
|
public FishType fishType;
|
|
|
|
public FishDeepType fishDeepType;
|
|
|
|
[HideInInspector]
|
|
public FishSystem fishSystem;
|
|
|
|
public bool isRenderRange = true;
|
|
|
|
public bool isDebugText;
|
|
|
|
public TextMesh debugText;
|
|
|
|
public GameObject[] typeSubModel;
|
|
|
|
[HideInInspector]
|
|
public Animator fishAnimator;
|
|
|
|
[HideInInspector]
|
|
public FishObjectConfig fishObjectConfig;
|
|
|
|
[HideInInspector]
|
|
public Renderer m_Renderer;
|
|
|
|
private int indexOfModel;
|
|
|
|
private FishMovement fishMovement;
|
|
|
|
private CCDIK currentCCDIK;
|
|
|
|
private void Start()
|
|
{
|
|
fishSystem = Object.FindObjectOfType<FishSystem>();
|
|
fishMovement = GetComponent<FishMovement>();
|
|
SwitchModels(indexOfModel, firstSetup: true);
|
|
if (randomTimeLifeOnStart)
|
|
{
|
|
currentTimeLife = Random.Range(0f, maxTimeLife * 0.4f);
|
|
currentFeed = Random.Range(40, 100);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if ((bool)ScriptsHandler.Instance)
|
|
{
|
|
Camera camera = ((!ScriptsHandler.Instance.playerManager.freeCamera.gameObject.activeSelf) ? ScriptsHandler.Instance.m_PlayerMain.currentCameraView : ScriptsHandler.Instance.playerManager.freeCamera.camera);
|
|
if ((bool)camera && isRenderRange)
|
|
{
|
|
if (Vector3.Distance(base.transform.position, camera.transform.position) > 20f && fishMovement.stage == FishMovement.Stage.freeMove)
|
|
{
|
|
if (m_Renderer.enabled)
|
|
{
|
|
m_Renderer.enabled = false;
|
|
fishAnimator.StopPlayback();
|
|
}
|
|
}
|
|
else if (!m_Renderer.enabled)
|
|
{
|
|
m_Renderer.enabled = true;
|
|
fishAnimator.StartPlayback();
|
|
fishAnimator.Rebind();
|
|
}
|
|
}
|
|
CheckIsCorrectTerrainPosition();
|
|
}
|
|
if (m_Renderer != null && !m_Renderer.isVisible && fishMovement.stage == FishMovement.Stage.freeMove)
|
|
{
|
|
currentTimeLife = Mathf.MoveTowards(currentTimeLife, maxTimeLife, Time.deltaTime);
|
|
if (currentTimeLife == maxTimeLife || currentFeed <= 0f || (resetTimeLife > 0f && currentTimeLife >= resetTimeLife))
|
|
{
|
|
currentTimeLife = 0f;
|
|
currentFeed = 100f;
|
|
SwitchModels(0);
|
|
}
|
|
}
|
|
float num = currentTimeLife / maxTimeLife;
|
|
float num2 = weightScaleCurve.Evaluate(num);
|
|
float num3 = minScale + (maxScale - minScale) * num2;
|
|
base.transform.localScale = new Vector3(num3, num3, num3);
|
|
current_weight = maxWeight * num;
|
|
if (typeSubModel.Length != 0)
|
|
{
|
|
float num4 = maxTimeLife / (float)typeSubModel.Length;
|
|
int newIndex = (int)(currentTimeLife / num4);
|
|
SwitchModels(newIndex);
|
|
}
|
|
if (isDebugText)
|
|
{
|
|
if (debugText != null && Camera.main != null)
|
|
{
|
|
if (debugText.gameObject.activeSelf)
|
|
{
|
|
debugText.text = current_weight.ToString("F2") + "kg weight\n";
|
|
TextMesh textMesh = debugText;
|
|
textMesh.text = textMesh.text + currentFeed.ToString("F1") + "% full";
|
|
debugText.transform.LookAt(debugText.transform.position + Camera.main.transform.rotation * Vector3.forward, Camera.main.transform.rotation * Vector3.up);
|
|
}
|
|
else
|
|
{
|
|
debugText.gameObject.SetActive(value: true);
|
|
}
|
|
}
|
|
}
|
|
else if (debugText.gameObject.activeSelf)
|
|
{
|
|
debugText.gameObject.SetActive(value: false);
|
|
}
|
|
void CheckIsCorrectTerrainPosition()
|
|
{
|
|
if (fishMovement.stage == FishMovement.Stage.hooked)
|
|
{
|
|
Vector3 vector = ProbeDeep();
|
|
if (vector.z > 0f && vector.x == 0f)
|
|
{
|
|
ScriptsHandler.Instance.m_PlayerMain.CutFish();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private Vector3 ProbeDeep()
|
|
{
|
|
int mask = LayerMask.GetMask("Terrain");
|
|
Vector3 zero = Vector3.zero;
|
|
if (Physics.Raycast(base.transform.position, -Vector3.up, out var hitInfo, float.PositiveInfinity, mask))
|
|
{
|
|
zero.x = hitInfo.distance;
|
|
}
|
|
int mask2 = LayerMask.GetMask("WaterObject");
|
|
if (Physics.Raycast(base.transform.position, Vector3.up, out var hitInfo2, float.PositiveInfinity, mask2))
|
|
{
|
|
zero.y = hitInfo2.distance;
|
|
zero.z = hitInfo2.point.y;
|
|
}
|
|
return zero;
|
|
}
|
|
|
|
private void SwitchModels(int newIndex, bool firstSetup = false)
|
|
{
|
|
if (typeSubModel.Length > newIndex && (indexOfModel != newIndex || firstSetup))
|
|
{
|
|
typeSubModel[indexOfModel].SetActive(value: false);
|
|
typeSubModel[newIndex].SetActive(value: true);
|
|
m_Renderer = typeSubModel[newIndex].GetComponentInChildren<Renderer>();
|
|
fishAnimator = typeSubModel[newIndex].GetComponent<Animator>();
|
|
fishObjectConfig = typeSubModel[newIndex].GetComponent<FishObjectConfig>();
|
|
fishObjectConfig.rigibody = GetComponent<Rigidbody>();
|
|
indexOfModel = newIndex;
|
|
if ((bool)typeSubModel[newIndex].GetComponent<CCDIK>())
|
|
{
|
|
currentCCDIK = typeSubModel[newIndex].GetComponent<CCDIK>();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setCCDIKSystem(bool enabled = true)
|
|
{
|
|
if (!currentCCDIK)
|
|
{
|
|
return;
|
|
}
|
|
if (enabled)
|
|
{
|
|
if (!(currentCCDIK.solver.target.transform.parent == null))
|
|
{
|
|
currentCCDIK.solver.target.transform.SetParent(null);
|
|
currentCCDIK.solver.IKPositionWeight = 0.3f;
|
|
}
|
|
}
|
|
else if (!(currentCCDIK.solver.target.transform.parent != null))
|
|
{
|
|
currentCCDIK.solver.target.transform.SetParent(base.transform);
|
|
currentCCDIK.solver.IKPositionWeight = 0f;
|
|
}
|
|
}
|
|
|
|
public void AddFishToFishSystem()
|
|
{
|
|
if (!(fishSystem == null))
|
|
{
|
|
fishSystem.AddInwaterFishObject(this);
|
|
}
|
|
}
|
|
|
|
public void DeleteFishfromFishSystem()
|
|
{
|
|
if (!(fishSystem == null))
|
|
{
|
|
fishSystem.DeleteInwaterFishObject(this);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
DeleteFishfromFishSystem();
|
|
}
|
|
}
|