fix: UnAssign Problems
This commit is contained in:
parent
251bd948ab
commit
d75bae802a
|
@ -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;
|
||||
|
|
|
@ -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!;
|
||||
|
|
|
@ -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 _)
|
||||
{
|
||||
|
|
|
@ -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!;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue