Add component button

This commit is contained in:
max
2024-11-13 21:11:50 +01:00
parent 87ee6df46f
commit cf6cd080c6
2 changed files with 57 additions and 25 deletions

View File

@ -7,18 +7,29 @@ namespace Nerfed.Runtime.Serialization;
public static class ComponentHelper
{
// Auto generate this.
public static readonly Dictionary<Type, Func<World, Entity, ValueType>> GetComponentByType = new()
{
{ typeof(LocalTransform), (world, entity) => world.Get<LocalTransform>(entity) },
{ typeof(Root), (world, entity) => world.Get<Root>(entity) },
};
// Auto generate this.
public static readonly Dictionary<Type, Action<World, Entity, ValueType>> SetComponentByType = new()
{
{ typeof(LocalTransform), (world, entity, component) => world.Set(entity, (LocalTransform)component) },
{ typeof(Root), (world, entity, component) => world.Set(entity, (Root)component) },
};
// Auto generate this, but it should only contain user assignable components (so something like 'root' should be excluded).
// Maybe use an attribute for this.
public static readonly Dictionary<Type, Action<World, Entity>> AddComponentByType = new()
{
{ typeof(LocalTransform), (world, entity) => world.Set(entity, LocalTransform.Identity) },
};
// Auto generate this, but also keep the option for 'custom inspectors'.
// Maybe via attribute?
public static readonly Dictionary<Type, Action<World, Entity>> ComponentInspectorByType = new()
{
{
@ -31,7 +42,7 @@ public static class ComponentHelper
ImGui.BeginGroup();
ImGui.Text($"{nameof(LocalTransform)}");
isDirty |= ImGui.DragFloat3("Position", ref position, 0.2f, float.MinValue, float.MaxValue, "%f0 m"); // TODO: right format.
isDirty |= ImGui.DragFloat3("Position", ref position, 0.2f, float.MinValue, float.MaxValue /*, "%f0 m" */); // TODO: right format.
isDirty |= ImGui.DragFloat3("Rotation", ref eulerAngles);
isDirty |= ImGui.DragFloat3("Scale", ref scale);
ImGui.EndGroup();