fix: UnAssign Problems

This commit is contained in:
Syntriax 2023-11-24 17:20:43 +03:00
parent 251bd948ab
commit d75bae802a
5 changed files with 11 additions and 7 deletions

View File

@ -1,4 +1,5 @@
using System;
using Syntriax.Engine.Core.Abstract;
using Syntriax.Engine.Core.Exceptions;
@ -81,7 +82,6 @@ public abstract class Behaviour : IBehaviour
_stateEnable = null!;
_behaviourController = null!;
_stateEnable.Unassign();
OnUnassigned?.Invoke(this);
return true;

View File

@ -88,7 +88,7 @@ public class BehaviourController : IBehaviourController
public bool Assign(IGameObject gameObject)
{
if (GameObject.Initialized)
if (GameObject is not null && GameObject.Initialized)
return false;
_gameObject = gameObject;
@ -98,7 +98,7 @@ public class BehaviourController : IBehaviourController
public bool Unassign()
{
if (GameObject.Initialized)
if (GameObject is not null && GameObject.Initialized)
return false;
_gameObject = null!;

View File

@ -14,8 +14,12 @@ public abstract class BehaviourOverride : Behaviour
{
OnInitialized += OnInitialize;
OnFinalized += OnFinalize;
OnUnassigned += OnUnassign;
}
protected virtual void OnUnassign() { }
private void OnUnassign(IAssignable assignable) => OnUnassign();
protected virtual void OnInitialize() { }
private void OnInitialize(IInitialize _)
{

View File

@ -32,11 +32,11 @@ public class DrawableSpriteBehaviour : Behaviour, IDrawBehaviour, IAssignableSpr
public bool Assign(ISprite sprite)
{
if (Initialized)
return false;
_sprite = sprite;
OnSpriteAssigned?.Invoke(this);
return true;
}
public DrawableSpriteBehaviour() => OnUnassigned += OnUnassign;
private void OnUnassign(IAssignable assignable) => _sprite = null!;
}

View File

@ -30,7 +30,7 @@ public class StateEnable : IStateEnable
public bool Assign(IEntity entity)
{
if (_entity.Initialized)
if (_entity is not null && _entity.Initialized)
return false;
_entity = entity;