mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 10:04:36 +08:00
update
This commit is contained in:
parent
3701423bf6
commit
6e718691cd
@ -5,6 +5,13 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
internal static class UnityComponentConsts
|
||||||
|
{
|
||||||
|
private const string UNITY_COMPONENT_NAME = "UnityComponent";
|
||||||
|
public static readonly MetaGroup BaseGroup = new MetaGroupRef(UNITY_COMPONENT_NAME);
|
||||||
|
public static readonly MetaGroup ColliderGroup = new MetaGroupRef($"{UNITY_COMPONENT_NAME}/Collider/");
|
||||||
|
public static readonly MetaGroup JointGroup = new MetaGroupRef($"{UNITY_COMPONENT_NAME}/Joint/");
|
||||||
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[MetaColor(255 / 3, 255, 0)]
|
[MetaColor(255 / 3, 255, 0)]
|
||||||
public struct UnityComponent<T> : IEcsComponent, IEnumerable<T>//IntelliSense hack
|
public struct UnityComponent<T> : IEcsComponent, IEnumerable<T>//IntelliSense hack
|
||||||
@ -22,7 +29,14 @@ namespace DCFApixels.DragonECS
|
|||||||
#region Unity Component Templates
|
#region Unity Component Templates
|
||||||
public class UnityComponentTemplate<T> : ComponentTemplateBase<UnityComponent<T>> where T : Component
|
public class UnityComponentTemplate<T> : ComponentTemplateBase<UnityComponent<T>> where T : Component
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/" + typeof(T).Name;
|
public override string Name
|
||||||
|
{
|
||||||
|
get { return typeof(T).Name; }
|
||||||
|
}
|
||||||
|
public override MetaGroup Group
|
||||||
|
{
|
||||||
|
get { return UnityComponentConsts.BaseGroup; }
|
||||||
|
}
|
||||||
public sealed override void Apply(int worldID, int entityID)
|
public sealed override void Apply(int worldID, int entityID)
|
||||||
{
|
{
|
||||||
EcsWorld.GetPool<EcsPool<UnityComponent<T>>>(worldID).TryAddOrGet(entityID) = component;
|
EcsWorld.GetPool<EcsPool<UnityComponent<T>>>(worldID).TryAddOrGet(entityID) = component;
|
||||||
@ -51,27 +65,27 @@ namespace DCFApixels.DragonECS
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentColliderTemplate : UnityComponentTemplate<Collider>
|
public sealed class UnityComponentColliderTemplate : UnityComponentTemplate<Collider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(Collider);
|
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentBoxColliderTemplate : UnityComponentTemplate<BoxCollider>
|
public sealed class UnityComponentBoxColliderTemplate : UnityComponentTemplate<BoxCollider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(BoxCollider);
|
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentSphereColliderTemplate : UnityComponentTemplate<SphereCollider>
|
public sealed class UnityComponentSphereColliderTemplate : UnityComponentTemplate<SphereCollider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(SphereCollider);
|
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentCapsuleColliderTemplate : UnityComponentTemplate<CapsuleCollider>
|
public sealed class UnityComponentCapsuleColliderTemplate : UnityComponentTemplate<CapsuleCollider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(CapsuleCollider);
|
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentMeshColliderTemplate : UnityComponentTemplate<MeshCollider>
|
public sealed class UnityComponentMeshColliderTemplate : UnityComponentTemplate<MeshCollider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(MeshCollider);
|
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -79,22 +93,22 @@ namespace DCFApixels.DragonECS
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentJointTemplate : UnityComponentTemplate<Joint>
|
public sealed class UnityComponentJointTemplate : UnityComponentTemplate<Joint>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Joint/" + nameof(Joint);
|
public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } }
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentFixedJointTemplate : UnityComponentTemplate<FixedJoint>
|
public sealed class UnityComponentFixedJointTemplate : UnityComponentTemplate<FixedJoint>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Joint/" + nameof(FixedJoint);
|
public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } }
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentCharacterJointTemplate : UnityComponentTemplate<CharacterJoint>
|
public sealed class UnityComponentCharacterJointTemplate : UnityComponentTemplate<CharacterJoint>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Joint/" + nameof(CharacterJoint);
|
public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } }
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentConfigurableJointTemplate : UnityComponentTemplate<ConfigurableJoint>
|
public sealed class UnityComponentConfigurableJointTemplate : UnityComponentTemplate<ConfigurableJoint>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Joint/" + nameof(ConfigurableJoint);
|
public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,19 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
|
|
||||||
genericMenu = new GenericMenu();
|
genericMenu = new GenericMenu();
|
||||||
|
|
||||||
var dummies = ComponentTemplateTypeCache.Dummies;
|
var componentTemplateDummies = ComponentTemplateTypeCache.Dummies;
|
||||||
foreach (var dummy in dummies)
|
foreach (var dummy in componentTemplateDummies)
|
||||||
{
|
{
|
||||||
string name = dummy.Name;
|
ITypeMeta meta = dummy is ITypeMeta metaOverride ? metaOverride : dummy.Type.ToMeta();
|
||||||
string description = dummy.Description;
|
string name = meta.Name;
|
||||||
|
string description = meta.Description;
|
||||||
|
MetaGroup group = meta.Group;
|
||||||
|
|
||||||
|
if(group.Name.Length > 0)
|
||||||
|
{
|
||||||
|
name = group.Name + name;
|
||||||
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(description) == false)
|
if (string.IsNullOrEmpty(description) == false)
|
||||||
{
|
{
|
||||||
name = $"{name} {EcsUnityConsts.INFO_MARK}";
|
name = $"{name} {EcsUnityConsts.INFO_MARK}";
|
||||||
@ -156,10 +164,11 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
{
|
{
|
||||||
componentType = componentProperty.managedReferenceValue.GetType(); ;
|
componentType = componentProperty.managedReferenceValue.GetType(); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
string name = template.Name;
|
ITypeMeta meta = template is ITypeMeta metaOverride ? metaOverride : template.Type.ToMeta();
|
||||||
string description = template.Description;
|
string name = meta.Name;
|
||||||
Color panelColor = template.Color.Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE);
|
string description = meta.Description;
|
||||||
|
Color panelColor = meta.Color.ToUnityColor().Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE);
|
||||||
|
|
||||||
Rect removeButtonRect = GUILayoutUtility.GetLastRect();
|
Rect removeButtonRect = GUILayoutUtility.GetLastRect();
|
||||||
|
|
||||||
@ -231,19 +240,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
|
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetLastPathComponent(string input)
|
|
||||||
{
|
|
||||||
int lastSlashIndex = input.LastIndexOfAny(new char[] { '/', '\\' });
|
|
||||||
if (lastSlashIndex == -1)
|
|
||||||
{
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return input.Substring(lastSlashIndex + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomEditor(typeof(ScriptableEntityTemplate), true)]
|
[CustomEditor(typeof(ScriptableEntityTemplate), true)]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Codice.Utils;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@ -11,11 +12,6 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
Type Type { get; }
|
Type Type { get; }
|
||||||
string Name { get; }
|
|
||||||
MetaGroup Group { get; }
|
|
||||||
string Description { get; }
|
|
||||||
IReadOnlyCollection<string> Tags { get; }
|
|
||||||
Color Color { get; }
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
@ -31,17 +27,18 @@ namespace DCFApixels.DragonECS
|
|||||||
Selected
|
Selected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public interface IComponentTemplateWithMetaOverride : IComponentTemplate, ITypeMeta { }
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public abstract class ComponentTemplateBase : IComponentTemplate
|
public abstract class ComponentTemplateBase : IComponentTemplateWithMetaOverride
|
||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
public abstract Type Type { get; }
|
public abstract Type Type { get; }
|
||||||
public virtual string Name { get { return string.Empty; } }
|
public virtual string Name { get { return string.Empty; } }
|
||||||
public virtual MetaGroup Group { get { return default; } }
|
public virtual MetaColor Color { get { return new MetaColor(MetaColor.Black); } }
|
||||||
|
public virtual MetaGroup Group { get { return MetaGroup.Empty; } }
|
||||||
public virtual string Description { get { return string.Empty; } }
|
public virtual string Description { get { return string.Empty; } }
|
||||||
public virtual IReadOnlyCollection<string> Tags { get { return Array.Empty<string>(); } }
|
public virtual IReadOnlyCollection<string> Tags { get { return Array.Empty<string>(); } }
|
||||||
public virtual Color Color { get { return Color.black; } }
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
@ -54,19 +51,19 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public abstract class ComponentTemplateBase<T> : ComponentTemplateBase, IComponentTemplate
|
public abstract class ComponentTemplateBase<T> : ComponentTemplateBase
|
||||||
{
|
{
|
||||||
private static TypeMeta _meta = EcsDebugUtility.GetTypeMeta<T>();
|
protected static TypeMeta Meta = EcsDebugUtility.GetTypeMeta<T>();
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
protected T component;
|
protected T component;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public override Type Type { get { return typeof(T); } }
|
public override Type Type { get { return typeof(T); } }
|
||||||
public override string Name { get { return _meta.Name; } }
|
public override string Name { get { return Meta.Name; } }
|
||||||
public override MetaGroup Group { get { return _meta.Group; } }
|
public override MetaGroup Group { get { return Meta.Group; } }
|
||||||
public override string Description { get { return _meta.Description; } }
|
public override string Description { get { return Meta.Description; } }
|
||||||
public override IReadOnlyCollection<string> Tags { get { return _meta.Tags; } }
|
public override IReadOnlyCollection<string> Tags { get { return Meta.Tags; } }
|
||||||
public override Color Color { get { return _meta.Color.ToUnityColor(); } }
|
public override MetaColor Color { get { return Meta.Color; } }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
@ -81,7 +78,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class ComponentTemplate<T> : ComponentTemplateBase<T>, IComponentTemplate
|
public abstract class ComponentTemplate<T> : ComponentTemplateBase<T>
|
||||||
where T : struct, IEcsComponent
|
where T : struct, IEcsComponent
|
||||||
{
|
{
|
||||||
public override void Apply(int worldID, int entityID)
|
public override void Apply(int worldID, int entityID)
|
||||||
@ -89,7 +86,7 @@ namespace DCFApixels.DragonECS
|
|||||||
EcsWorld.GetPool<EcsPool<T>>(worldID).TryAddOrGet(entityID) = component;
|
EcsWorld.GetPool<EcsPool<T>>(worldID).TryAddOrGet(entityID) = component;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public abstract class TagComponentTemplate<T> : ComponentTemplateBase<T>, IComponentTemplate
|
public abstract class TagComponentTemplate<T> : ComponentTemplateBase<T>
|
||||||
where T : struct, IEcsTagComponent
|
where T : struct, IEcsTagComponent
|
||||||
{
|
{
|
||||||
public override void Apply(int worldID, int entityID)
|
public override void Apply(int worldID, int entityID)
|
||||||
@ -118,8 +115,14 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
{
|
{
|
||||||
private static Type[] _types;
|
private static Type[] _types;
|
||||||
private static IComponentTemplate[] _dummies;
|
private static IComponentTemplate[] _dummies;
|
||||||
internal static ReadOnlySpan<Type> Types => _types;
|
internal static ReadOnlySpan<Type> Types
|
||||||
internal static ReadOnlySpan<IComponentTemplate> Dummies => _dummies;
|
{
|
||||||
|
get { return _types; }
|
||||||
|
}
|
||||||
|
internal static ReadOnlySpan<IComponentTemplate> Dummies
|
||||||
|
{
|
||||||
|
get { return _dummies; }
|
||||||
|
}
|
||||||
|
|
||||||
static ComponentTemplateTypeCache()
|
static ComponentTemplateTypeCache()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user