com.alicizax.unity.framework/Runtime/ABase/GameObjectPool/Data/PoolConfigScriptableObject.cs

75 lines
1.9 KiB
C#
Raw Normal View History

2026-04-30 17:18:17 +08:00
using System;
2026-03-26 10:49:41 +08:00
using System.Collections.Generic;
using UnityEngine;
namespace AlicizaX
{
[CreateAssetMenu(fileName = "PoolConfig", menuName = "GameplaySystem/PoolConfig", order = 10)]
2026-04-30 17:18:17 +08:00
public sealed class PoolConfigScriptableObject : ScriptableObject
2026-03-26 10:49:41 +08:00
{
2026-04-17 21:01:20 +08:00
public List<PoolEntry> entries = new List<PoolEntry>();
2026-04-30 17:18:17 +08:00
internal PoolCompiledCatalog BuildCatalog()
2026-04-17 21:01:20 +08:00
{
Normalize();
2026-04-30 17:18:17 +08:00
if (entries == null || entries.Count == 0)
{
return PoolCompiledCatalog.Empty();
}
int validCount = 0;
for (int i = 0; i < entries.Count; i++)
{
PoolEntry entry = entries[i];
if (entry != null && !string.IsNullOrEmpty(entry.assetPath))
{
validCount++;
}
}
if (validCount == 0)
{
return PoolCompiledCatalog.Empty();
}
var normalizedEntries = new PoolEntry[validCount];
int writeIndex = 0;
2026-04-17 21:01:20 +08:00
for (int i = 0; i < entries.Count; i++)
{
PoolEntry entry = entries[i];
2026-04-30 17:18:17 +08:00
if (entry == null || string.IsNullOrEmpty(entry.assetPath))
2026-04-17 21:01:20 +08:00
{
continue;
}
2026-04-30 17:18:17 +08:00
normalizedEntries[writeIndex++] = entry;
2026-04-17 21:01:20 +08:00
}
2026-04-30 17:18:17 +08:00
Array.Sort(normalizedEntries, PoolEntry.CompareByPriority);
return PoolCompiledCatalog.Build(normalizedEntries);
2026-04-17 21:01:20 +08:00
}
2026-03-26 10:49:41 +08:00
public void Normalize()
{
2026-04-17 21:01:20 +08:00
if (entries == null)
2026-03-26 10:49:41 +08:00
{
2026-04-17 21:01:20 +08:00
entries = new List<PoolEntry>();
2026-04-30 17:18:17 +08:00
return;
2026-03-26 10:49:41 +08:00
}
2026-04-17 21:01:20 +08:00
for (int i = 0; i < entries.Count; i++)
2026-03-26 10:49:41 +08:00
{
2026-04-17 21:01:20 +08:00
entries[i]?.Normalize();
2026-03-26 10:49:41 +08:00
}
}
#if UNITY_EDITOR
private void OnValidate()
{
Normalize();
}
#endif
}
}