mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-17 17:34:34 +08:00
add getters/setters for entity templates
This commit is contained in:
parent
a50a1f79fa
commit
b91b012add
@ -4,6 +4,8 @@
|
|||||||
using DCFApixels.DragonECS.Unity;
|
using DCFApixels.DragonECS.Unity;
|
||||||
using DCFApixels.DragonECS.Unity.Internal;
|
using DCFApixels.DragonECS.Unity.Internal;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
@ -23,50 +25,58 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
[SerializeReference]
|
[SerializeReference]
|
||||||
[ReferenceButton(true, typeof(IComponentTemplate))]
|
[ReferenceButton(true, typeof(IComponentTemplate))]
|
||||||
private IComponentTemplate[] _components;
|
private IComponentTemplate[] _componentTemplates;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
string IEntityTemplateInternal.ComponentsPropertyName
|
string IEntityTemplateInternal.ComponentsPropertyName
|
||||||
{
|
{
|
||||||
get { return nameof(_components); }
|
get { return nameof(_componentTemplates); }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
public ReadOnlySpan<IComponentTemplate> GetComponentTemplates()
|
||||||
|
{
|
||||||
|
return _componentTemplates;
|
||||||
|
}
|
||||||
|
public void SetComponentTemplates(IEnumerable<IComponentTemplate> componentTemplates)
|
||||||
|
{
|
||||||
|
_componentTemplates = componentTemplates.ToArray();
|
||||||
|
}
|
||||||
public override void Apply(short worldID, int entityID)
|
public override void Apply(short worldID, int entityID)
|
||||||
{
|
{
|
||||||
foreach (var item in _components)
|
foreach (var item in _componentTemplates)
|
||||||
{
|
{
|
||||||
item.Apply(worldID, entityID);
|
item.Apply(worldID, entityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
_components = Array.Empty<IComponentTemplate>();
|
_componentTemplates = Array.Empty<IComponentTemplate>();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region UnityEvents
|
#region UnityEvents
|
||||||
private void OnValidate()
|
private void OnValidate()
|
||||||
{
|
{
|
||||||
if (_components == null) { return; }
|
if (_componentTemplates == null) { return; }
|
||||||
foreach (var item in _components)
|
foreach (var item in _componentTemplates)
|
||||||
{
|
{
|
||||||
item?.OnValidate(gameObject);
|
item?.OnValidate(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void OnDrawGizmos()
|
private void OnDrawGizmos()
|
||||||
{
|
{
|
||||||
if (_components == null) { return; }
|
if (_componentTemplates == null) { return; }
|
||||||
foreach (var item in _components)
|
foreach (var item in _componentTemplates)
|
||||||
{
|
{
|
||||||
item?.OnGizmos(transform, IComponentTemplate.GizmosMode.Always);
|
item?.OnGizmos(transform, IComponentTemplate.GizmosMode.Always);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void OnDrawGizmosSelected()
|
private void OnDrawGizmosSelected()
|
||||||
{
|
{
|
||||||
if (_components == null) { return; }
|
if (_componentTemplates == null) { return; }
|
||||||
foreach (var item in _components)
|
foreach (var item in _componentTemplates)
|
||||||
{
|
{
|
||||||
item?.OnGizmos(transform, IComponentTemplate.GizmosMode.Selected);
|
item?.OnGizmos(transform, IComponentTemplate.GizmosMode.Selected);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
using DCFApixels.DragonECS.Unity;
|
using DCFApixels.DragonECS.Unity;
|
||||||
using DCFApixels.DragonECS.Unity.Internal;
|
using DCFApixels.DragonECS.Unity.Internal;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
@ -24,38 +26,54 @@ namespace DCFApixels.DragonECS
|
|||||||
private ScriptableEntityTemplateBase[] _templates;
|
private ScriptableEntityTemplateBase[] _templates;
|
||||||
[SerializeReference]
|
[SerializeReference]
|
||||||
[ReferenceButton(true, typeof(IComponentTemplate))]
|
[ReferenceButton(true, typeof(IComponentTemplate))]
|
||||||
private IComponentTemplate[] _components;
|
private IComponentTemplate[] _componentTemplates;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
string IEntityTemplateInternal.ComponentsPropertyName
|
string IEntityTemplateInternal.ComponentsPropertyName
|
||||||
{
|
{
|
||||||
get { return nameof(_components); }
|
get { return nameof(_componentTemplates); }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
public ReadOnlySpan<ScriptableEntityTemplateBase> GetTemplates()
|
||||||
|
{
|
||||||
|
return _templates;
|
||||||
|
}
|
||||||
|
public void SetTemplates(IEnumerable<ScriptableEntityTemplateBase> templates)
|
||||||
|
{
|
||||||
|
_templates = templates.ToArray();
|
||||||
|
}
|
||||||
|
public ReadOnlySpan<IComponentTemplate> GetComponentTemplates()
|
||||||
|
{
|
||||||
|
return _componentTemplates;
|
||||||
|
}
|
||||||
|
public void SetComponentTemplates(IEnumerable<IComponentTemplate> componentTemplates)
|
||||||
|
{
|
||||||
|
_componentTemplates = componentTemplates.ToArray();
|
||||||
|
}
|
||||||
public override void Apply(short worldID, int entityID)
|
public override void Apply(short worldID, int entityID)
|
||||||
{
|
{
|
||||||
foreach (var template in _templates)
|
foreach (var template in _templates)
|
||||||
{
|
{
|
||||||
template.Apply(worldID, entityID);
|
template.Apply(worldID, entityID);
|
||||||
}
|
}
|
||||||
foreach (var item in _components)
|
foreach (var item in _componentTemplates)
|
||||||
{
|
{
|
||||||
item.Apply(worldID, entityID);
|
item.Apply(worldID, entityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
_components = Array.Empty<IComponentTemplate>();
|
_componentTemplates = Array.Empty<IComponentTemplate>();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region UnityEvents
|
#region UnityEvents
|
||||||
private void OnValidate()
|
private void OnValidate()
|
||||||
{
|
{
|
||||||
if (_components == null) { return; }
|
if (_componentTemplates == null) { return; }
|
||||||
foreach (var item in _components)
|
foreach (var item in _componentTemplates)
|
||||||
{
|
{
|
||||||
item?.OnValidate(this);
|
item?.OnValidate(this);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user