mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
add IsUnique property to IComponentTemplate
This commit is contained in:
parent
c0c06153a1
commit
b1ec482266
@ -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)
|
||||
{
|
||||
for (int i = 0, iMax = componentsProp.arraySize; i < iMax; i++)
|
||||
{
|
||||
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);
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user