revert: refactor: ITransformWithGameObject

This reverts commit f96c58cbd4.
This commit is contained in:
Syntriax 2024-02-06 12:04:51 +03:00
parent c767e1e856
commit f729cdc0a8
5 changed files with 29 additions and 47 deletions

View File

@ -6,7 +6,7 @@ namespace Syntriax.Engine.Core.Abstract;
/// <summary> /// <summary>
/// Represents the transformation properties of an object such as position, scale, and rotation. /// Represents the transformation properties of an object such as position, scale, and rotation.
/// </summary> /// </summary>
public interface ITransform : IEnumerable<ITransform> public interface ITransform : IAssignableGameObject, IEnumerable<ITransform>
{ {
/// <summary> /// <summary>
/// Event triggered when the <see cref="Position"/> of the <see cref="ITransform"/> changes. /// Event triggered when the <see cref="Position"/> of the <see cref="ITransform"/> changes.

View File

@ -1,6 +0,0 @@
namespace Syntriax.Engine.Core.Abstract;
/// <summary>
/// Represents an <see cref="ITransform"/> attached to an <see cref="IGameObject"/>.
/// </summary>
public interface ITransformWithGameObject : ITransform, IAssignableGameObject { }

View File

@ -9,7 +9,7 @@ public class GameObjectFactory
=> Instantiate<T>(transform: null, behaviourController: null, stateEnable: null, args); => Instantiate<T>(transform: null, behaviourController: null, stateEnable: null, args);
public T Instantiate<T>( public T Instantiate<T>(
ITransformWithGameObject? transform = null, ITransform? transform = null,
IBehaviourController? behaviourController = null, IBehaviourController? behaviourController = null,
IStateEnable? stateEnable = null, IStateEnable? stateEnable = null,
params object?[]? args params object?[]? args
@ -18,7 +18,7 @@ public class GameObjectFactory
{ {
T gameObject = TypeFactory.Get<T>(args); T gameObject = TypeFactory.Get<T>(args);
transform ??= TypeFactory.Get<TransformWithGameObject>(); transform ??= TypeFactory.Get<Transform>();
behaviourController ??= TypeFactory.Get<BehaviourController>(); behaviourController ??= TypeFactory.Get<BehaviourController>();
stateEnable ??= TypeFactory.Get<StateEnable>(); stateEnable ??= TypeFactory.Get<StateEnable>();

View File

@ -6,9 +6,13 @@ using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Core; namespace Syntriax.Engine.Core;
[System.Diagnostics.DebuggerDisplay("Position: {Position.ToString(), nq}, Scale: {Scale.ToString(), nq}, Rotation: {Rotation}")] [System.Diagnostics.DebuggerDisplay("Name: {GameObject.Name, nq} Position: {Position.ToString(), nq}, Scale: {Scale.ToString(), nq}, Rotation: {Rotation}")]
public class Transform : ITransform 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>? OnPositionChanged { get; set; } = null;
public Action<ITransform>? OnScaleChanged { get; set; } = null; public Action<ITransform>? OnScaleChanged { get; set; } = null;
public Action<ITransform>? OnRotationChanged { get; set; } = null; public Action<ITransform>? OnRotationChanged { get; set; } = null;
@ -28,6 +32,7 @@ public class Transform : ITransform
private readonly List<ITransform> _children = []; private readonly List<ITransform> _children = [];
public IGameObject GameObject { get; private set; } = null!;
public ITransform? Parent { get; private set; } = null; public ITransform? Parent { get; private set; } = null;
public IReadOnlyList<ITransform> Children => _children; public IReadOnlyList<ITransform> Children => _children;
@ -245,4 +250,24 @@ public class Transform : ITransform
else else
_rotation = Parent.Rotation + LocalRotation; _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;
}
} }

View File

@ -1,37 +0,0 @@
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;
}
}