add subtemplates for ScriptableEntityTemplate

This commit is contained in:
DCFApixels 2025-03-24 19:32:41 +08:00
parent f9596752bb
commit a50a1f79fa
3 changed files with 22 additions and 6 deletions

View File

@ -30,7 +30,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
internal class ComponentTemplateReferenceDrawer : ExtendedPropertyDrawer<ComponentTemplateReferenceAttribute> internal class ComponentTemplateReferenceDrawer : ExtendedPropertyDrawer<ComponentTemplateReferenceAttribute>
{ {
private const float DamagedComponentHeight = 18f * 2f; private const float DamagedComponentHeight = 18f * 2f;
private static readonly Rect HeadIconsRect = new Rect(0f, 0f, 19f, 19f);
private static ComponentDropDown _componentDropDown; private static ComponentDropDown _componentDropDown;
#region Properties #region Properties

View File

@ -9,8 +9,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
{ {
internal abstract class EntityTemplateEditorBase : ExtendedEditor<IEntityTemplateInternal> internal abstract class EntityTemplateEditorBase : ExtendedEditor<IEntityTemplateInternal>
{ {
private static readonly Rect HeadIconsRect = new Rect(0f, 0f, 19f, 19f);
private ComponentDropDown _componentDropDown; private ComponentDropDown _componentDropDown;
private SerializedProperty _componentsProp; private SerializedProperty _componentsProp;
@ -184,10 +182,23 @@ namespace DCFApixels.DragonECS.Unity.Editors
} }
} }
using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetTransperentBlackBackgrounStyle()))
SerializedProperty iterator = serializedObject.GetIterator();
iterator.NextVisible(true);
while (iterator.NextVisible(false))
{ {
DrawTop(Target, _componentsProp); if (iterator.name == _componentsProp.name)
_reorderableComponentsList.DoLayoutList(); {
using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetTransperentBlackBackgrounStyle()))
{
DrawTop(Target, _componentsProp);
_reorderableComponentsList.DoLayoutList();
}
}
else
{
EditorGUILayout.PropertyField(iterator, true);
}
} }
} }
private void DrawTop(IEntityTemplateInternal target, SerializedProperty componentsProp) private void DrawTop(IEntityTemplateInternal target, SerializedProperty componentsProp)

View File

@ -20,6 +20,8 @@ namespace DCFApixels.DragonECS
[MetaID("DragonECS_7C4DBA809201D959401A5BDFB6363EC0")] [MetaID("DragonECS_7C4DBA809201D959401A5BDFB6363EC0")]
public class ScriptableEntityTemplate : ScriptableEntityTemplateBase, IEntityTemplateInternal public class ScriptableEntityTemplate : ScriptableEntityTemplateBase, IEntityTemplateInternal
{ {
[SerializeField]
private ScriptableEntityTemplateBase[] _templates;
[SerializeReference] [SerializeReference]
[ReferenceButton(true, typeof(IComponentTemplate))] [ReferenceButton(true, typeof(IComponentTemplate))]
private IComponentTemplate[] _components; private IComponentTemplate[] _components;
@ -34,6 +36,10 @@ namespace DCFApixels.DragonECS
#region Methods #region Methods
public override void Apply(short worldID, int entityID) public override void Apply(short worldID, int entityID)
{ {
foreach (var template in _templates)
{
template.Apply(worldID, entityID);
}
foreach (var item in _components) foreach (var item in _components)
{ {
item.Apply(worldID, entityID); item.Apply(worldID, entityID);