add IsUnique property to IComponentTemplate

This commit is contained in:
Mikhail 2024-09-09 14:19:35 +08:00
parent c0c06153a1
commit b1ec482266
5 changed files with 12 additions and 39 deletions

View File

@ -57,20 +57,24 @@ namespace DCFApixels.DragonECS.Unity.Editors
private void OnAddComponent(object obj)
{
Type componentType = obj.GetType();
IComponentTemplate cmptmp = (IComponentTemplate)obj;
if (this.target is ITemplateInternal target)
{
SerializedProperty componentsProp = serializedObject.FindProperty(target.ComponentsPropertyName);
for (int i = 0; i < componentsProp.arraySize; i++)
if (cmptmp.IsUnique)
{
if (componentsProp.GetArrayElementAtIndex(i).managedReferenceValue.GetType() == componentType)
for (int i = 0, iMax = componentsProp.arraySize; i < iMax; i++)
{
return;
if (componentsProp.GetArrayElementAtIndex(i).managedReferenceValue.GetType() == componentType)
{
return;
}
}
}
int index = componentsProp.arraySize;
componentsProp.InsertArrayElementAtIndex(index);
componentsProp.GetArrayElementAtIndex(index).managedReferenceValue = ((IComponentTemplate)obj).Clone();
componentsProp.GetArrayElementAtIndex(index).managedReferenceValue = cmptmp.Clone();
serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(this.target);

View File

@ -1,10 +1,7 @@
namespace DCFApixels.DragonECS
{
public interface ITemplate : ITemplateNode
{
//void Add(ITemplateNode template);
//void Remove(ITemplateNode template);
}
public interface ITemplate : ITemplateNode { }
public static class ITemplateNodeExtensions
{
public static entlong NewEntityWithGameObject(this EcsWorld world, ITemplateNode template, string name = "Entity", GameObjectIcon icon = GameObjectIcon.NONE)
@ -14,23 +11,6 @@
return e;
}
}
//[Serializable]
//public class EntityTemplateInheritanceMatrix
//{
// [SerializeReference]
// private ITemplateNode[] _components;
//
// #region Methods
// public void Apply(int worldID, int entityID)
// {
// foreach (var item in _components)
// {
// item.Apply(worldID, entityID);
// }
// }
// #endregion
//}
}
namespace DCFApixels.DragonECS.Unity.Internal
@ -38,6 +18,5 @@ namespace DCFApixels.DragonECS.Unity.Internal
internal interface ITemplateInternal : ITemplate
{
string ComponentsPropertyName { get; }
//EntityTemplateInheritanceMatrix InheritanceMatrix { get; }
}
}

View File

@ -12,6 +12,7 @@ namespace DCFApixels.DragonECS
{
#region Properties
Type Type { get; }
bool IsUnique { get; }
#endregion
#region Methods
@ -39,6 +40,7 @@ namespace DCFApixels.DragonECS
public virtual MetaGroup Group { get { return MetaGroup.Empty; } }
public virtual MetaDescription Description { get { return MetaDescription.Empty; } }
public virtual IReadOnlyList<string> Tags { get { return Array.Empty<string>(); } }
public virtual bool IsUnique { get { return true; } }
#endregion
#region Methods

View File

@ -19,18 +19,12 @@ namespace DCFApixels.DragonECS
{
[SerializeReference]
private IComponentTemplate[] _components;
//[SerializeField]
//private EntityTemplateInheritanceMatrix _inheritanceMatrix;
#region Properties
string ITemplateInternal.ComponentsPropertyName
{
get { return nameof(_components); }
}
//EntityTemplateInheritanceMatrix ITemplateInternal.InheritanceMatrix
//{
// get { return _inheritanceMatrix; }
//}
#endregion
#region Methods

View File

@ -18,18 +18,12 @@ namespace DCFApixels.DragonECS
{
[SerializeReference]
private IComponentTemplate[] _components;
//[SerializeField]
//private EntityTemplateInheritanceMatrix _inheritanceMatrix;
#region Properties
string ITemplateInternal.ComponentsPropertyName
{
get { return nameof(_components); }
}
//EntityTemplateInheritanceMatrix ITemplateInternal.InheritanceMatrix
//{
// get { return _inheritanceMatrix; }
//}
#endregion
#region Methods