mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
add seralizable EcsPipelineTemplate
This commit is contained in:
parent
f29e9dfdca
commit
34e1e20af6
@ -50,21 +50,21 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Add
|
#region Add
|
||||||
public Builder Add(IEcsProcess system, int? sortingOrder = null)
|
public Builder Add(IEcsProcess system, int? sortOrder = null)
|
||||||
{
|
{
|
||||||
return AddInternal(system, string.Empty, sortingOrder, false);
|
return AddInternal(system, string.Empty, sortOrder, false);
|
||||||
}
|
}
|
||||||
public Builder Add(IEcsProcess system, string layerName, int? sortingOrder = null)
|
public Builder Add(IEcsProcess system, string layerName, int? sortOrder = null)
|
||||||
{
|
{
|
||||||
return AddInternal(system, layerName, sortingOrder, false);
|
return AddInternal(system, layerName, sortOrder, false);
|
||||||
}
|
}
|
||||||
public Builder AddUnique(IEcsProcess system, int? sortingOrder = null)
|
public Builder AddUnique(IEcsProcess system, int? sortOrder = null)
|
||||||
{
|
{
|
||||||
return AddInternal(system, string.Empty, sortingOrder, true);
|
return AddInternal(system, string.Empty, sortOrder, true);
|
||||||
}
|
}
|
||||||
public Builder AddUnique(IEcsProcess system, string layerName, int? sortingOrder = null)
|
public Builder AddUnique(IEcsProcess system, string layerName, int? sortOrder = null)
|
||||||
{
|
{
|
||||||
return AddInternal(system, layerName, sortingOrder, true);
|
return AddInternal(system, layerName, sortOrder, true);
|
||||||
}
|
}
|
||||||
private Builder AddInternal(IEcsProcess system, string layerName, int? settedSortOrder, bool isUnique)
|
private Builder AddInternal(IEcsProcess system, string layerName, int? settedSortOrder, bool isUnique)
|
||||||
{
|
{
|
||||||
@ -427,14 +427,13 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
return InsertAfter(targetLayer, movingLayers);
|
return InsertAfter(targetLayer, movingLayers);
|
||||||
}
|
}
|
||||||
|
public void MergeWith(IReadOnlyList<string> other)
|
||||||
public void MergeWith(LayerList other)
|
|
||||||
{
|
{
|
||||||
HashSet<string> seen = new HashSet<string>();
|
HashSet<string> seen = new HashSet<string>();
|
||||||
List<string> result = new List<string>();
|
List<string> result = new List<string>();
|
||||||
|
|
||||||
List<string> listA = _layers;
|
List<string> listA = _layers;
|
||||||
List<string> listB = other._layers;
|
IReadOnlyList<string> listB = other;
|
||||||
|
|
||||||
foreach (string item in listA)
|
foreach (string item in listA)
|
||||||
{
|
{
|
||||||
@ -472,6 +471,10 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
_layers = result;
|
_layers = result;
|
||||||
}
|
}
|
||||||
|
public void MergeWith(LayerList other)
|
||||||
|
{
|
||||||
|
MergeWith(other._layers);
|
||||||
|
}
|
||||||
|
|
||||||
public bool Contains(string layer) { return _layers.Contains(layer); }
|
public bool Contains(string layer) { return _layers.Contains(layer); }
|
||||||
|
|
||||||
|
40
src/Serializable/EcsPipelineTemplate.cs
Normal file
40
src/Serializable/EcsPipelineTemplate.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS.Serializable
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
[DataContract]
|
||||||
|
public class EcsPipelineTemplate : IEcsModule
|
||||||
|
{
|
||||||
|
[DataMember] public string[] layers;
|
||||||
|
[DataMember] public SystemRecord[] systems;
|
||||||
|
public void Import(EcsPipeline.Builder b)
|
||||||
|
{
|
||||||
|
b.Layers.MergeWith(layers);
|
||||||
|
foreach (var s in systems)
|
||||||
|
{
|
||||||
|
int? sortOrder = s.isCustomSortOrder ? s.sortOrder : default(int?);
|
||||||
|
if (s.isUnique)
|
||||||
|
{
|
||||||
|
b.AddUnique(s.system, s.layer, sortOrder);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
b.Add(s.system, s.layer, sortOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
[DataContract]
|
||||||
|
public struct SystemRecord
|
||||||
|
{
|
||||||
|
[DataMember] public IEcsProcess system;
|
||||||
|
[DataMember] public string layer;
|
||||||
|
[DataMember] public int sortOrder;
|
||||||
|
[DataMember] public bool isCustomSortOrder;
|
||||||
|
[DataMember] public bool isUnique;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user