91 lines
2.8 KiB
C#
91 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Sirenix.Utilities;
|
|
using UFS2.ScriptableObjects;
|
|
using UnityEngine;
|
|
|
|
public class FishArea : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class FishInArea
|
|
{
|
|
public FishData fishData;
|
|
|
|
[Range(0f, 1f)]
|
|
public float spawnWeight;
|
|
}
|
|
|
|
[SerializeField]
|
|
private Collider[] area;
|
|
|
|
[SerializeField]
|
|
private LevelFishData levelFishData;
|
|
|
|
[SerializeField]
|
|
private List<FishInArea> fishInAreaList;
|
|
|
|
[SerializeField]
|
|
private float pointSpacingOverride = -1f;
|
|
|
|
public Collider[] Area => area;
|
|
|
|
public List<FishInArea> FishInAreaList => fishInAreaList;
|
|
|
|
public float PointSpacingOverride => pointSpacingOverride;
|
|
|
|
public void Validate()
|
|
{
|
|
area = GetComponentsInChildren<Collider>();
|
|
if (area.Length == 0)
|
|
{
|
|
Debug.LogError("[FishArea] No colliders found in the hierarchy of '" + base.gameObject.name + "'. Make sure to add at least one collider.");
|
|
}
|
|
area.ForEach(delegate(Collider element)
|
|
{
|
|
element.isTrigger = true;
|
|
});
|
|
if (levelFishData == null)
|
|
{
|
|
Debug.LogError("[FishArea] Missing LevelFishData in '" + base.gameObject.name + "'. Assign a LevelFishData asset.");
|
|
return;
|
|
}
|
|
if (fishInAreaList.Count == 0)
|
|
{
|
|
Debug.LogWarning("[FishArea] fishInAreaList is empty in '" + base.gameObject.name + "'. Automatically populating it with all fish from LevelFishData with default spawn weight 1.");
|
|
foreach (LevelFishData.FishDataHelper item in levelFishData.FishesSetting)
|
|
{
|
|
fishInAreaList.Add(new FishInArea
|
|
{
|
|
fishData = item.FishData,
|
|
spawnWeight = 1f
|
|
});
|
|
}
|
|
}
|
|
foreach (LevelFishData.FishDataHelper fs in levelFishData.FishesSetting)
|
|
{
|
|
if (!fishInAreaList.Exists((FishInArea f) => f.fishData == fs.FishData))
|
|
{
|
|
Debug.LogError("[FishArea] Fish '" + fs.FishData.name + "' exists in LevelFishData but is missing from the fishInAreaList in '" + base.gameObject.name + "'. Ensure all fish are included.");
|
|
}
|
|
}
|
|
foreach (FishInArea fish in fishInAreaList)
|
|
{
|
|
if (!levelFishData.FishesSetting.Exists((LevelFishData.FishDataHelper f) => f.FishData == fish.fishData))
|
|
{
|
|
Debug.LogError("[FishArea] Fish '" + fish.fishData.name + "' is in fishInAreaList but does not exist in LevelFishData of '" + base.gameObject.name + "'. Remove it or update LevelFishData.");
|
|
}
|
|
}
|
|
foreach (FishInArea fishInArea in fishInAreaList)
|
|
{
|
|
if (fishInArea.spawnWeight < 0f || fishInArea.spawnWeight > 1f)
|
|
{
|
|
Debug.LogError($"[FishArea] Fish '{fishInArea.fishData.name}' in '{base.gameObject.name}' has an invalid spawn weight ({fishInArea.spawnWeight}). It must be between 0 and 1.");
|
|
}
|
|
}
|
|
if (fishInAreaList.TrueForAll((FishInArea f) => f.spawnWeight == 0f))
|
|
{
|
|
Debug.LogError("[FishArea] All fish in '" + base.gameObject.name + "' have a spawn weight of 0. At least one fish should have a non-zero weight.");
|
|
}
|
|
}
|
|
}
|