mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
add simplified aspect builder syntax
This commit is contained in:
parent
6147518858
commit
03598f97d8
@ -46,6 +46,19 @@ namespace DCFApixels.DragonECS
|
|||||||
private EcsWorld _world;
|
private EcsWorld _world;
|
||||||
private EcsMask.Builder _maskBuilder;
|
private EcsMask.Builder _maskBuilder;
|
||||||
|
|
||||||
|
public IncludeMarker Inc
|
||||||
|
{
|
||||||
|
get { return new IncludeMarker(this); }
|
||||||
|
}
|
||||||
|
public ExcludeMarker Exc
|
||||||
|
{
|
||||||
|
get { return new ExcludeMarker(this); }
|
||||||
|
}
|
||||||
|
public OptionalMarker Opt
|
||||||
|
{
|
||||||
|
get { return new OptionalMarker(this); }
|
||||||
|
}
|
||||||
|
|
||||||
public EcsWorld World => _world;
|
public EcsWorld World => _world;
|
||||||
|
|
||||||
private Builder(EcsWorld world)
|
private Builder(EcsWorld world)
|
||||||
@ -406,4 +419,43 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
public readonly ref struct IncludeMarker
|
||||||
|
{
|
||||||
|
private readonly EcsAspect.Builder _builder;
|
||||||
|
public IncludeMarker(EcsAspect.Builder builder)
|
||||||
|
{
|
||||||
|
_builder = builder;
|
||||||
|
}
|
||||||
|
public T GetInstance<T>()
|
||||||
|
where T : IEcsPoolImplementation, new()
|
||||||
|
{
|
||||||
|
return _builder.IncludePool<T>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public readonly ref struct ExcludeMarker
|
||||||
|
{
|
||||||
|
private readonly EcsAspect.Builder _builder;
|
||||||
|
public ExcludeMarker(EcsAspect.Builder builder)
|
||||||
|
{
|
||||||
|
_builder = builder;
|
||||||
|
}
|
||||||
|
public T GetInstance<T>()
|
||||||
|
where T : IEcsPoolImplementation, new()
|
||||||
|
{
|
||||||
|
return _builder.ExcludePool<T>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public readonly ref struct OptionalMarker
|
||||||
|
{
|
||||||
|
private readonly EcsAspect.Builder _builder;
|
||||||
|
public OptionalMarker(EcsAspect.Builder builder)
|
||||||
|
{
|
||||||
|
_builder = builder;
|
||||||
|
}
|
||||||
|
public T GetInstance<T>()
|
||||||
|
where T : IEcsPoolImplementation, new()
|
||||||
|
{
|
||||||
|
return _builder.OptionalPool<T>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,6 +248,12 @@ namespace DCFApixels.DragonECS
|
|||||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() { throw new NotImplementedException(); }
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() { throw new NotImplementedException(); }
|
||||||
IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); }
|
IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region MarkersConverter
|
||||||
|
public static implicit operator EcsPool<T>(IncludeMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||||
|
public static implicit operator EcsPool<T>(ExcludeMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||||
|
public static implicit operator EcsPool<T>(OptionalMarker a) { return a.GetInstance<EcsPool<T>>(); }
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
/// <summary>Standard component</summary>
|
/// <summary>Standard component</summary>
|
||||||
public interface IEcsComponent { }
|
public interface IEcsComponent { }
|
||||||
|
@ -229,6 +229,12 @@ namespace DCFApixels.DragonECS
|
|||||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => throw new NotImplementedException();
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => throw new NotImplementedException();
|
||||||
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
|
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region MarkersConverter
|
||||||
|
public static implicit operator EcsTagPool<T>(IncludeMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||||
|
public static implicit operator EcsTagPool<T>(ExcludeMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||||
|
public static implicit operator EcsTagPool<T>(OptionalMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Component without data</summary>
|
/// <summary>Component without data</summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user