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)
|
private void OnAddComponent(object obj)
|
||||||
{
|
{
|
||||||
Type componentType = obj.GetType();
|
Type componentType = obj.GetType();
|
||||||
|
IComponentTemplate cmptmp = (IComponentTemplate)obj;
|
||||||
if (this.target is ITemplateInternal target)
|
if (this.target is ITemplateInternal target)
|
||||||
{
|
{
|
||||||
SerializedProperty componentsProp = serializedObject.FindProperty(target.ComponentsPropertyName);
|
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;
|
int index = componentsProp.arraySize;
|
||||||
componentsProp.InsertArrayElementAtIndex(index);
|
componentsProp.InsertArrayElementAtIndex(index);
|
||||||
componentsProp.GetArrayElementAtIndex(index).managedReferenceValue = ((IComponentTemplate)obj).Clone();
|
componentsProp.GetArrayElementAtIndex(index).managedReferenceValue = cmptmp.Clone();
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
EditorUtility.SetDirty(this.target);
|
EditorUtility.SetDirty(this.target);
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public interface ITemplate : ITemplateNode
|
public interface ITemplate : ITemplateNode { }
|
||||||
{
|
|
||||||
//void Add(ITemplateNode template);
|
|
||||||
//void Remove(ITemplateNode template);
|
|
||||||
}
|
|
||||||
public static class ITemplateNodeExtensions
|
public static class ITemplateNodeExtensions
|
||||||
{
|
{
|
||||||
public static entlong NewEntityWithGameObject(this EcsWorld world, ITemplateNode template, string name = "Entity", GameObjectIcon icon = GameObjectIcon.NONE)
|
public static entlong NewEntityWithGameObject(this EcsWorld world, ITemplateNode template, string name = "Entity", GameObjectIcon icon = GameObjectIcon.NONE)
|
||||||
@ -14,23 +11,6 @@
|
|||||||
return e;
|
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
|
namespace DCFApixels.DragonECS.Unity.Internal
|
||||||
@ -38,6 +18,5 @@ namespace DCFApixels.DragonECS.Unity.Internal
|
|||||||
internal interface ITemplateInternal : ITemplate
|
internal interface ITemplateInternal : ITemplate
|
||||||
{
|
{
|
||||||
string ComponentsPropertyName { get; }
|
string ComponentsPropertyName { get; }
|
||||||
//EntityTemplateInheritanceMatrix InheritanceMatrix { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,6 +12,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
Type Type { get; }
|
Type Type { get; }
|
||||||
|
bool IsUnique { get; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
@ -39,6 +40,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public virtual MetaGroup Group { get { return MetaGroup.Empty; } }
|
public virtual MetaGroup Group { get { return MetaGroup.Empty; } }
|
||||||
public virtual MetaDescription Description { get { return MetaDescription.Empty; } }
|
public virtual MetaDescription Description { get { return MetaDescription.Empty; } }
|
||||||
public virtual IReadOnlyList<string> Tags { get { return Array.Empty<string>(); } }
|
public virtual IReadOnlyList<string> Tags { get { return Array.Empty<string>(); } }
|
||||||
|
public virtual bool IsUnique { get { return true; } }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
@ -19,18 +19,12 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
[SerializeReference]
|
[SerializeReference]
|
||||||
private IComponentTemplate[] _components;
|
private IComponentTemplate[] _components;
|
||||||
//[SerializeField]
|
|
||||||
//private EntityTemplateInheritanceMatrix _inheritanceMatrix;
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
string ITemplateInternal.ComponentsPropertyName
|
string ITemplateInternal.ComponentsPropertyName
|
||||||
{
|
{
|
||||||
get { return nameof(_components); }
|
get { return nameof(_components); }
|
||||||
}
|
}
|
||||||
//EntityTemplateInheritanceMatrix ITemplateInternal.InheritanceMatrix
|
|
||||||
//{
|
|
||||||
// get { return _inheritanceMatrix; }
|
|
||||||
//}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
@ -18,18 +18,12 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
[SerializeReference]
|
[SerializeReference]
|
||||||
private IComponentTemplate[] _components;
|
private IComponentTemplate[] _components;
|
||||||
//[SerializeField]
|
|
||||||
//private EntityTemplateInheritanceMatrix _inheritanceMatrix;
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
string ITemplateInternal.ComponentsPropertyName
|
string ITemplateInternal.ComponentsPropertyName
|
||||||
{
|
{
|
||||||
get { return nameof(_components); }
|
get { return nameof(_components); }
|
||||||
}
|
}
|
||||||
//EntityTemplateInheritanceMatrix ITemplateInternal.InheritanceMatrix
|
|
||||||
//{
|
|
||||||
// get { return _inheritanceMatrix; }
|
|
||||||
//}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
Loading…
Reference in New Issue
Block a user