2025-03-14 17:02:34 +08:00
|
|
|
|
#if DISABLE_DEBUG
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
using DCFApixels.DragonECS.RunnersCore;
|
2024-11-01 13:50:48 +08:00
|
|
|
|
using DCFApixels.DragonECS.Unity.Internal;
|
2024-06-30 01:12:21 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2024-06-26 01:35:57 +08:00
|
|
|
|
using UnityEngine;
|
2024-10-18 17:22:02 +08:00
|
|
|
|
using static DCFApixels.DragonECS.Unity.PipelineTemplateUtility;
|
2024-06-26 01:35:57 +08:00
|
|
|
|
|
2024-10-18 17:22:02 +08:00
|
|
|
|
namespace DCFApixels.DragonECS.Unity
|
2024-06-26 01:35:57 +08:00
|
|
|
|
{
|
2024-10-18 17:22:02 +08:00
|
|
|
|
public interface IPipelineTemplate
|
2024-06-26 01:35:57 +08:00
|
|
|
|
{
|
2024-10-18 17:22:02 +08:00
|
|
|
|
ReadOnlySpan<string> Layers { get; }
|
|
|
|
|
ReadOnlySpan<Record> Records { get; }
|
|
|
|
|
bool Validate();
|
|
|
|
|
}
|
|
|
|
|
public static class PipelineTemplateUtility
|
|
|
|
|
{
|
|
|
|
|
internal static readonly string[] DefaultLayers = new string[]
|
2024-06-30 01:12:21 +08:00
|
|
|
|
{
|
|
|
|
|
EcsConsts.PRE_BEGIN_LAYER,
|
|
|
|
|
EcsConsts.BEGIN_LAYER,
|
|
|
|
|
EcsConsts.BASIC_LAYER,
|
|
|
|
|
EcsConsts.END_LAYER,
|
|
|
|
|
EcsConsts.POST_END_LAYER,
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-18 17:22:02 +08:00
|
|
|
|
internal static bool ValidateLayers(ref string[] layers)
|
2024-06-30 01:12:21 +08:00
|
|
|
|
{
|
2024-09-14 18:33:54 +08:00
|
|
|
|
bool result = false;
|
2024-06-30 01:12:21 +08:00
|
|
|
|
Dictionary<string, int> builtinLayerIndexes = new Dictionary<string, int>();
|
2024-10-18 17:22:02 +08:00
|
|
|
|
foreach (var item in DefaultLayers)
|
2024-06-30 01:12:21 +08:00
|
|
|
|
{
|
|
|
|
|
builtinLayerIndexes.Add(item, -1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-18 17:22:02 +08:00
|
|
|
|
List<string> newLayers = layers.Distinct().ToList();
|
2024-06-30 01:12:21 +08:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < newLayers.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var layer = newLayers[i];
|
|
|
|
|
if (builtinLayerIndexes.ContainsKey(layer))
|
|
|
|
|
{
|
|
|
|
|
builtinLayerIndexes[layer] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int lastNewLayersCount = newLayers.Count;
|
|
|
|
|
foreach (var pair in builtinLayerIndexes)
|
|
|
|
|
{
|
2024-09-10 19:13:31 +08:00
|
|
|
|
if (pair.Value < 0)
|
2024-06-30 01:12:21 +08:00
|
|
|
|
{
|
|
|
|
|
newLayers.Add(pair.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int i = lastNewLayersCount; i < newLayers.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
builtinLayerIndexes[newLayers[i]] = i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
foreach (var pair in builtinLayerIndexes.OrderBy(o => o.Value))
|
|
|
|
|
{
|
2024-10-18 17:22:02 +08:00
|
|
|
|
if (newLayers[pair.Value] != DefaultLayers[i])
|
2024-09-14 18:33:54 +08:00
|
|
|
|
{
|
2024-10-18 17:22:02 +08:00
|
|
|
|
newLayers[pair.Value] = DefaultLayers[i];
|
2024-09-14 18:33:54 +08:00
|
|
|
|
result = true;
|
|
|
|
|
}
|
2024-06-30 01:12:21 +08:00
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-18 17:22:02 +08:00
|
|
|
|
layers = newLayers.ToArray();
|
2024-09-14 18:33:54 +08:00
|
|
|
|
return result;
|
2024-06-30 01:12:21 +08:00
|
|
|
|
}
|
2024-10-18 17:22:02 +08:00
|
|
|
|
internal static bool ValidateRecords(ref Record[] records)
|
2024-06-30 01:12:21 +08:00
|
|
|
|
{
|
2024-09-14 18:33:54 +08:00
|
|
|
|
return false;
|
2024-06-30 01:12:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-18 17:22:02 +08:00
|
|
|
|
public static EcsPipelineTemplate GenerateSerializableTemplate(this IPipelineTemplate self)
|
|
|
|
|
{
|
|
|
|
|
EcsPipelineTemplate result = new EcsPipelineTemplate();
|
|
|
|
|
result.layers = new string[self.Layers.Length];
|
|
|
|
|
for (int i = 0; i < self.Layers.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
result.layers[i] = self.Layers[i];
|
|
|
|
|
}
|
|
|
|
|
result.records = new EcsPipelineTemplate.Record[self.Records.Length];
|
|
|
|
|
for (int i = 0; i < result.records.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var s = self.Records[i];
|
|
|
|
|
result.records[i] = new EcsPipelineTemplate.Record(s.target, s.parameters);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 01:12:21 +08:00
|
|
|
|
[Serializable]
|
2024-09-08 21:36:24 +08:00
|
|
|
|
public struct Record
|
2024-06-26 01:35:57 +08:00
|
|
|
|
{
|
|
|
|
|
[SerializeReference]
|
2024-09-14 23:30:11 +08:00
|
|
|
|
[ReferenceButton(true, typeof(IEcsModule), typeof(IEcsProcess))]
|
2024-11-01 13:50:48 +08:00
|
|
|
|
[ReferenceButtonWithOut(typeof(IEcsRunner))]
|
2024-09-16 19:31:01 +08:00
|
|
|
|
[ArrayElement]
|
|
|
|
|
public object target;// нельзя менять поярдок полей, иначе это поломает отрисовку в инспекторе изза применения property.Next(bool);
|
2024-09-08 21:36:24 +08:00
|
|
|
|
public AddParams parameters;
|
2024-11-01 17:17:52 +08:00
|
|
|
|
[CustomToggle(Name = "Enable", IsLeft = true, IsInverted = true)]
|
|
|
|
|
public bool disabled;
|
|
|
|
|
public Record(object target, AddParams parameters, bool disabled)
|
2024-06-26 01:35:57 +08:00
|
|
|
|
{
|
2024-09-08 21:36:24 +08:00
|
|
|
|
this.target = target;
|
|
|
|
|
this.parameters = parameters;
|
2024-11-01 17:17:52 +08:00
|
|
|
|
this.disabled = disabled;
|
2024-06-26 01:35:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-18 17:22:02 +08:00
|
|
|
|
}
|