Syntriax.Engine/Engine.Core/TransformWithGameObject.cs

38 lines
1004 B
C#

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;
}
}