This commit is contained in:
Mikhail 2023-05-23 01:48:54 +08:00
parent dc575bd516
commit 0d9c0dc8a1
9 changed files with 66 additions and 36 deletions

View File

@ -1,5 +1,6 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace DCFApixels.DragonECS.Editors
{
@ -34,6 +35,7 @@ namespace DCFApixels.DragonECS.Editors
Save(false);
}
}
}
}
#endif

View File

@ -1,6 +1,5 @@
#if UNITY_EDITOR
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using UnityEngine;
@ -48,40 +47,13 @@ namespace DCFApixels.DragonECS.Editors
}
public static string GetGenericName(Type type)
{
string friendlyName = type.Name;
if (type.IsGenericType)
{
int iBacktick = friendlyName.IndexOf('`');
if (iBacktick > 0)
friendlyName = friendlyName.Remove(iBacktick);
friendlyName += "<";
Type[] typeParameters = type.GetGenericArguments();
for (int i = 0; i < typeParameters.Length; ++i)
{
string typeParamName = GetGenericName(typeParameters[i]);
friendlyName += (i == 0 ? typeParamName : "," + typeParamName);
}
friendlyName += ">";
}
return friendlyName;
}
public static string GetGenericName(Type type) => EcsDebugUtility.GetGenericTypeName(type);
public static string GetName<T>() => GetName(typeof(T));
public static string GetName(Type type)
{
var atr = type.GetCustomAttribute<DebugNameAttribute>();
return atr != null ? atr.name : GetGenericName(type);
}
public static string GetName(Type type) => EcsDebugUtility.GetName(type);
public static string GetDescription<T>() => GetDescription(typeof(T));
public static string GetDescription(Type type)
{
var atr = type.GetCustomAttribute<DebugDescriptionAttribute>();
return atr != null ? atr.description : string.Empty;
}
public static string GetDescription(Type type) => EcsDebugUtility.GetDescription(type);
#region Utils
[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)]

View File

@ -61,7 +61,7 @@ namespace DCFApixels.DragonECS
[CustomEditor(typeof(PipelineDebugMonitor))]
public class PipelineDebugMonitorEditor : Editor
{
private DebugColorAttribute _fakeDebugColorAttribute = new DebugColorAttribute(DebugColor.White);
private DebugColorAttribute _fakeDebugColorAttribute = new DebugColorAttribute(190, 190, 190);
private Type _debugColorAttributeType = typeof(DebugColorAttribute);
private GUIStyle _headerStyle;
private GUIStyle _interfacesStyle;

View File

@ -88,6 +88,7 @@ namespace DCFApixels.DragonECS
public override void OnInspectorGUI()
{
_scroll = GUILayout.BeginScrollView(_scroll, GUILayout.Height(800f));
var pools = Target.world.AllPools.ToArray().Where(o => !o.IsNullOrDummy()).OfType<IEcsPool>();
GUILayout.Label("", GUILayout.ExpandWidth(true));
@ -158,7 +159,7 @@ namespace DCFApixels.DragonECS
textStyle2.wordWrap = true;
textStyle2.alignment = TextAnchor.LowerCenter;
string name = EcsEditor.GetGenericName(pool.ComponentType);
GUIContent label = new GUIContent(name, $"t({name})");
GUIContent label = new GUIContent(name, $"{name} e:{count}");
GUI.Label(AddMargin(position, -10f, 3f), label, textStyle2);
}

View File

@ -13,5 +13,24 @@ namespace DCFApixels.DragonECS
foreach (var item in _components)
item.Add(world, entityID);
}
private void OnDrawGizmos()
{
if (_components == null) return;
foreach (var item in _components)
{
if (item is ITemplateComponentGizmos g)
g.OnGizmos(transform, ITemplateComponentGizmos.Mode.Always);
}
}
private void OnDrawGizmosSelected()
{
if (_components == null) return;
foreach (var item in _components)
{
if (item is ITemplateComponentGizmos g)
g.OnGizmos(transform, ITemplateComponentGizmos.Mode.Selected);
}
}
}
}

View File

@ -17,7 +17,7 @@ namespace DCFApixels.DragonECS
{
public static int NewEntity(this ITemplate self, EcsWorld world)
{
int e = world.NewEntity();
int e = world.NewEmptyEntity();
self.Apply(world, e);
return e;
}

View File

@ -15,6 +15,15 @@ namespace DCFApixels.DragonECS
{
public string Name { get; }
}
public interface ITemplateComponentGizmos
{
public void OnGizmos(Transform transform, Mode mode);
public enum Mode
{
Always,
Selected
}
}
[Serializable]
public abstract class TemplateComponentInitializerBase
@ -62,7 +71,7 @@ namespace DCFApixels.DragonECS
#endregion
}
[Serializable]
public abstract class TemplateComponentInitializer<T> : TemplateComponentInitializerBase, ITemplateComponentName
public abstract class TemplateComponentInitializer<T> : TemplateComponentInitializerBase, ITemplateComponentName, ITemplateComponentGizmos
{
private static string _autoname = GetName(typeof(T));
private static Color _autoColor = GetColor(typeof(T));
@ -79,6 +88,7 @@ namespace DCFApixels.DragonECS
#endregion
public abstract void Add(EcsWorld w, int e);
public virtual void OnGizmos(Transform transform, ITemplateComponentGizmos.Mode mode) { }
}
internal static class ITemplateBrowsableExt

View File

@ -69,4 +69,30 @@ namespace DCFApixels.DragonECS
}
#endregion
#region Joints
[Serializable]
public sealed class UnityComponentJointInitializer : TemplateComponentInitializer<UnityComponent<Joint>>
{
public override string Name => "UnityComponent/Joint/" + nameof(Joint);
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<Joint>>().Add(e) = component;
}
[Serializable]
public sealed class UnityComponentFixedJointInitializer : TemplateComponentInitializer<UnityComponent<FixedJoint>>
{
public override string Name => "UnityComponent/Joint/" + nameof(FixedJoint);
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<FixedJoint>>().Add(e) = component;
}
[Serializable]
public sealed class UnityComponentCharacterJointInitializer : TemplateComponentInitializer<UnityComponent<CharacterJoint>>
{
public override string Name => "UnityComponent/Joint/" + nameof(CharacterJoint);
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<CharacterJoint>>().Add(e) = component;
}
[Serializable]
public sealed class UnityComponentConfigurableJointInitializer : TemplateComponentInitializer<UnityComponent<ConfigurableJoint>>
{
public override string Name => "UnityComponent/Joint/" + nameof(ConfigurableJoint);
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<ConfigurableJoint>>().Add(e) = component;
}
#endregion
}

View File

@ -62,7 +62,7 @@ namespace DCFApixels.DragonECS
{
public static entlong NewEntityWithGameObject(this EcsWorld self, string name = "EcsEntity", GameObjectIcon icon = GameObjectIcon.NONE)
{
entlong result = self.GetEntityLong(self.NewEntity());
entlong result = self.GetEntityLong(self.NewEmptyEntity());
GameObject newGameObject = new GameObject(name);
newGameObject.AddComponent<EcsEntityConnect>().ConnectWith(result);
// self.GetPool<UnityGameObject>().Add(result.id) =