refactor: ITransformWithGameObject
This commit is contained in:
parent
fed288859f
commit
f96c58cbd4
|
@ -6,7 +6,7 @@ namespace Syntriax.Engine.Core.Abstract;
|
|||
/// <summary>
|
||||
/// Represents the transformation properties of an object such as position, scale, and rotation.
|
||||
/// </summary>
|
||||
public interface ITransform : IAssignableGameObject, IEnumerable<ITransform>
|
||||
public interface ITransform : IEnumerable<ITransform>
|
||||
{
|
||||
/// <summary>
|
||||
/// Event triggered when the <see cref="Position"/> of the <see cref="ITransform"/> changes.
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
namespace Syntriax.Engine.Core.Abstract;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an <see cref="ITransform"/> attached to an <see cref="IGameObject"/>.
|
||||
/// </summary>
|
||||
public interface ITransformWithGameObject : ITransform, IAssignableGameObject { }
|
|
@ -9,7 +9,7 @@ public class GameObjectFactory
|
|||
=> Instantiate<T>(transform: null, behaviourController: null, stateEnable: null, args);
|
||||
|
||||
public T Instantiate<T>(
|
||||
ITransform? transform = null,
|
||||
ITransformWithGameObject? transform = null,
|
||||
IBehaviourController? behaviourController = null,
|
||||
IStateEnable? stateEnable = null,
|
||||
params object?[]? args
|
||||
|
@ -18,7 +18,7 @@ public class GameObjectFactory
|
|||
{
|
||||
T gameObject = TypeFactory.Get<T>(args);
|
||||
|
||||
transform ??= TypeFactory.Get<Transform>();
|
||||
transform ??= TypeFactory.Get<TransformWithGameObject>();
|
||||
behaviourController ??= TypeFactory.Get<BehaviourController>();
|
||||
stateEnable ??= TypeFactory.Get<StateEnable>();
|
||||
|
||||
|
|
|
@ -6,13 +6,9 @@ using Syntriax.Engine.Core.Abstract;
|
|||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
[System.Diagnostics.DebuggerDisplay("Name: {GameObject.Name, nq} Position: {Position.ToString(), nq}, Scale: {Scale.ToString(), nq}, Rotation: {Rotation}")]
|
||||
[System.Diagnostics.DebuggerDisplay("Position: {Position.ToString(), nq}, Scale: {Scale.ToString(), nq}, Rotation: {Rotation}")]
|
||||
public class Transform : ITransform
|
||||
{
|
||||
public Action<IAssignableGameObject>? OnGameObjectAssigned { get; set; } = null;
|
||||
|
||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||
|
||||
public Action<ITransform>? OnPositionChanged { get; set; } = null;
|
||||
public Action<ITransform>? OnScaleChanged { get; set; } = null;
|
||||
public Action<ITransform>? OnRotationChanged { get; set; } = null;
|
||||
|
@ -32,7 +28,6 @@ public class Transform : ITransform
|
|||
|
||||
private readonly List<ITransform> _children = [];
|
||||
|
||||
public IGameObject GameObject { get; private set; } = null!;
|
||||
public ITransform? Parent { get; private set; } = null;
|
||||
|
||||
public IReadOnlyList<ITransform> Children => _children;
|
||||
|
@ -250,24 +245,4 @@ public class Transform : ITransform
|
|||
else
|
||||
_rotation = Parent.Rotation + LocalRotation;
|
||||
}
|
||||
|
||||
public bool Assign(IGameObject gameObject)
|
||||
{
|
||||
if (GameObject is not null && GameObject.Initialized)
|
||||
return false;
|
||||
|
||||
GameObject = gameObject;
|
||||
OnGameObjectAssigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Unassign()
|
||||
{
|
||||
if (GameObject is not null && GameObject.Initialized)
|
||||
return false;
|
||||
|
||||
GameObject = null!;
|
||||
OnUnassigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
[System.Diagnostics.DebuggerDisplay("Name: {GameObject.Name, nq} Position: {Position.ToString(), nq}, Scale: {Scale.ToString(), nq}, Rotation: {Rotation}")]
|
||||
public class TransformWithGameObject : Transform, ITransformWithGameObject
|
||||
{
|
||||
public Action<IAssignableGameObject>? OnGameObjectAssigned { get; set; } = null;
|
||||
|
||||
public Action<IAssignable>? OnUnassigned { get; set; } = null;
|
||||
|
||||
|
||||
public IGameObject GameObject { get; private set; } = null!;
|
||||
|
||||
|
||||
public bool Assign(IGameObject gameObject)
|
||||
{
|
||||
if (GameObject is not null && GameObject.Initialized)
|
||||
return false;
|
||||
|
||||
GameObject = gameObject;
|
||||
OnGameObjectAssigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Unassign()
|
||||
{
|
||||
if (GameObject is not null && GameObject.Initialized)
|
||||
return false;
|
||||
|
||||
GameObject = null!;
|
||||
OnUnassigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue