95 lines
2.1 KiB
C#
95 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using Obvious.Soap;
|
|
using UFS3.Management;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.HighDefinition;
|
|
|
|
public class FishSystemManager : SceneSingleton<FishSystemManager>
|
|
{
|
|
public FishController fishControllerPrefab;
|
|
|
|
public FishOnMapPreset FishPreset;
|
|
|
|
public ScriptableListGameObject distanceSourceObjects;
|
|
|
|
public LayerMask terrainMask;
|
|
|
|
public LayerMask objectMask;
|
|
|
|
public float fishDensity;
|
|
|
|
[SerializeField]
|
|
private float cullDistance = 70f;
|
|
|
|
[SerializeField]
|
|
private int _zonePerFrame = 3;
|
|
|
|
[SerializeField]
|
|
private WaterSurface _WaterSurface;
|
|
|
|
private List<FishZoneObject> zoneObjects;
|
|
|
|
private Camera mainCamera;
|
|
|
|
private Stopwatch stopwatch;
|
|
|
|
private int _currentZoneID;
|
|
|
|
public void RegenerateWaypoints()
|
|
{
|
|
FishZoneObject[] componentsInChildren = GetComponentsInChildren<FishZoneObject>();
|
|
foreach (FishZoneObject fishZoneObject in componentsInChildren)
|
|
{
|
|
fishZoneObject.maxFishes = Mathf.RoundToInt(fishDensity * fishZoneObject.radius);
|
|
fishZoneObject.fishSystemManager = this;
|
|
fishZoneObject.fishPreset = FishPreset;
|
|
fishZoneObject.terrainMask = terrainMask;
|
|
fishZoneObject.objectMask = objectMask;
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
zoneObjects = GetComponentsInChildren<FishZoneObject>().ToList();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (zoneObjects.Count == 0 || distanceSourceObjects.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
int num = _zonePerFrame;
|
|
while (num > 0)
|
|
{
|
|
FishZoneObject zoneObject = zoneObjects[_currentZoneID];
|
|
CalculateZoneObjectCullDistance(zoneObject);
|
|
num--;
|
|
_currentZoneID++;
|
|
if (_currentZoneID >= zoneObjects.Count)
|
|
{
|
|
_currentZoneID = 0;
|
|
}
|
|
}
|
|
foreach (FishZoneObject zoneObject2 in zoneObjects)
|
|
{
|
|
_ = zoneObject2.gameObject.activeSelf;
|
|
}
|
|
}
|
|
|
|
private void CalculateZoneObjectCullDistance(FishZoneObject zoneObject)
|
|
{
|
|
foreach (GameObject distanceSourceObject in distanceSourceObjects)
|
|
{
|
|
bool flag = Vector3.Distance(distanceSourceObject.transform.position, zoneObject.transform.position) - zoneObject.radius > cullDistance;
|
|
zoneObject.Cull(flag);
|
|
if (!flag)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|