165 lines
4.6 KiB
C#
165 lines
4.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Lean.Pool;
|
|
using UFS2.ScriptableObjects;
|
|
using UnityEngine;
|
|
|
|
public class FishFeedingZone : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class FishPopulation
|
|
{
|
|
public GameManager.FishSpecies FishSpecies;
|
|
|
|
public int AmountPopulationZone = 1;
|
|
|
|
public Vector2 weightRange;
|
|
}
|
|
|
|
[Serializable]
|
|
public class FishEntityPopulation
|
|
{
|
|
public FishData FishData;
|
|
|
|
public int AmountPopulationZone = 1;
|
|
|
|
public Vector2 WeightRange;
|
|
}
|
|
|
|
public bool fishTakeTesting;
|
|
|
|
public int Inedex;
|
|
|
|
public int InedexOfGroup;
|
|
|
|
public float rangeZone = 5f;
|
|
|
|
public FishPopulation[] fishPopulation;
|
|
|
|
public List<FishEntityPopulation> FishEntitesPopulation;
|
|
|
|
public List<FFish> fisheshInFeedingZone;
|
|
|
|
public FFishSystem fFishSystem;
|
|
|
|
private void ImportFishEntityPopulation()
|
|
{
|
|
FishEntitesPopulation = new List<FishEntityPopulation>();
|
|
FishPopulation[] array = this.fishPopulation;
|
|
foreach (FishPopulation fishPopulation in array)
|
|
{
|
|
FishEntityPopulation item = new FishEntityPopulation
|
|
{
|
|
AmountPopulationZone = fishPopulation.AmountPopulationZone,
|
|
WeightRange = fishPopulation.weightRange
|
|
};
|
|
FishEntitesPopulation.Add(item);
|
|
}
|
|
}
|
|
|
|
private FFish CreateFish(int id, float weight)
|
|
{
|
|
return LeanPool.Spawn(GameManager.Instance.gameFish[(int)fishPopulation[id].FishSpecies].GetFishModel(weight), FScriptsHandler.Instance.transform).GetComponent<FFish>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
fFishSystem = Singleton<FFishSystem>.Instance;
|
|
fisheshInFeedingZone = new List<FFish>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
}
|
|
|
|
public IEnumerator GenerateOneFish(Vector3 startPos, FWaterDisplacement hookObject)
|
|
{
|
|
yield return null;
|
|
if (fishPopulation.Length != 0)
|
|
{
|
|
int num = UnityEngine.Random.Range(0, fishPopulation.Length);
|
|
float num2 = RandWeight(new Vector2(fishPopulation[num].weightRange.x, fishPopulation[num].weightRange.y));
|
|
FFish fFish = CreateFish(num, num2);
|
|
fFish.fFishSystem = fFishSystem;
|
|
fFish.fishWeight = num2;
|
|
fFish.fishSpecies = fishPopulation[num].FishSpecies;
|
|
fFish.transform.localScale = GameManager.Instance.gameFish[(int)fishPopulation[num].FishSpecies].GetFishScale(num2);
|
|
fFish.transform.position = startPos;
|
|
fFish.currentFeedingZone = this;
|
|
fisheshInFeedingZone.Add(fFish);
|
|
fFish.EnableFish();
|
|
fFishSystem.inwaterFishObjectsSpawner.Add(fFish);
|
|
if ((bool)hookObject)
|
|
{
|
|
hookObject.fishListCreated.Add(fFish);
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerator GenerateFishPopulationOnStart()
|
|
{
|
|
yield return null;
|
|
for (int i = 0; i < fishPopulation.Length; i++)
|
|
{
|
|
for (int j = 0; j < fishPopulation[i].AmountPopulationZone; j++)
|
|
{
|
|
Vector3 position = base.transform.position + UnityEngine.Random.insideUnitSphere * rangeZone;
|
|
position.y = base.transform.position.y - 0.2f;
|
|
float num = RandWeight(new Vector2(fishPopulation[i].weightRange.x, fishPopulation[i].weightRange.y));
|
|
FFish fFish = CreateFish(i, num);
|
|
fFish.fFishSystem = fFishSystem;
|
|
fFish.fishWeight = num;
|
|
fFish.fishSpecies = fishPopulation[i].FishSpecies;
|
|
fFish.transform.localScale = GameManager.Instance.gameFish[(int)fishPopulation[i].FishSpecies].GetFishScale(num);
|
|
fFish.transform.position = position;
|
|
fFish.currentFeedingZone = this;
|
|
fisheshInFeedingZone.Add(fFish);
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void checkAndUpdateFishPopulation()
|
|
{
|
|
for (int i = 0; i < fisheshInFeedingZone.Count; i++)
|
|
{
|
|
if (fisheshInFeedingZone[i] == null)
|
|
{
|
|
int num = UnityEngine.Random.Range(0, fishPopulation.Length - 1);
|
|
if (fishPopulation[num].AmountPopulationZone > fisheshInFeedingZone.Count)
|
|
{
|
|
break;
|
|
}
|
|
Vector3 position = base.transform.position + UnityEngine.Random.insideUnitSphere * 1f;
|
|
position.y = base.transform.position.y - 0.2f;
|
|
float num2 = RandWeight(new Vector2(fishPopulation[num].weightRange.x, fishPopulation[num].weightRange.y));
|
|
FFish fFish = CreateFish(num, num2);
|
|
fFish.fFishSystem = fFishSystem;
|
|
fFish.fishWeight = num2;
|
|
fFish.fishSpecies = fishPopulation[num].FishSpecies;
|
|
fFish.transform.localScale = GameManager.Instance.gameFish[(int)fishPopulation[num].FishSpecies].GetFishScale(num2);
|
|
fFish.transform.position = position;
|
|
fFish.currentFeedingZone = this;
|
|
fisheshInFeedingZone[i] = fFish;
|
|
Debug.Log("Replace fish " + fFish.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
private float RandWeight(Vector2 range)
|
|
{
|
|
float result = range.x;
|
|
for (int i = 0; (float)i < 10f; i++)
|
|
{
|
|
result = UnityEngine.Random.Range(range.x, range.y);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private void OnDrawGizmosSelected()
|
|
{
|
|
Gizmos.DrawWireSphere(base.transform.position, rangeZone);
|
|
}
|
|
}
|