fix: UnAssign Problems
This commit is contained in:
parent
251bd948ab
commit
d75bae802a
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
using Syntriax.Engine.Core.Abstract;
|
using Syntriax.Engine.Core.Abstract;
|
||||||
using Syntriax.Engine.Core.Exceptions;
|
using Syntriax.Engine.Core.Exceptions;
|
||||||
|
|
||||||
|
@ -81,7 +82,6 @@ public abstract class Behaviour : IBehaviour
|
||||||
|
|
||||||
_stateEnable = null!;
|
_stateEnable = null!;
|
||||||
_behaviourController = null!;
|
_behaviourController = null!;
|
||||||
_stateEnable.Unassign();
|
|
||||||
|
|
||||||
OnUnassigned?.Invoke(this);
|
OnUnassigned?.Invoke(this);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class BehaviourController : IBehaviourController
|
||||||
|
|
||||||
public bool Assign(IGameObject gameObject)
|
public bool Assign(IGameObject gameObject)
|
||||||
{
|
{
|
||||||
if (GameObject.Initialized)
|
if (GameObject is not null && GameObject.Initialized)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_gameObject = gameObject;
|
_gameObject = gameObject;
|
||||||
|
@ -98,7 +98,7 @@ public class BehaviourController : IBehaviourController
|
||||||
|
|
||||||
public bool Unassign()
|
public bool Unassign()
|
||||||
{
|
{
|
||||||
if (GameObject.Initialized)
|
if (GameObject is not null && GameObject.Initialized)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_gameObject = null!;
|
_gameObject = null!;
|
||||||
|
|
|
@ -14,8 +14,12 @@ public abstract class BehaviourOverride : Behaviour
|
||||||
{
|
{
|
||||||
OnInitialized += OnInitialize;
|
OnInitialized += OnInitialize;
|
||||||
OnFinalized += OnFinalize;
|
OnFinalized += OnFinalize;
|
||||||
|
OnUnassigned += OnUnassign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnUnassign() { }
|
||||||
|
private void OnUnassign(IAssignable assignable) => OnUnassign();
|
||||||
|
|
||||||
protected virtual void OnInitialize() { }
|
protected virtual void OnInitialize() { }
|
||||||
private void OnInitialize(IInitialize _)
|
private void OnInitialize(IInitialize _)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,11 +32,11 @@ public class DrawableSpriteBehaviour : Behaviour, IDrawBehaviour, IAssignableSpr
|
||||||
|
|
||||||
public bool Assign(ISprite sprite)
|
public bool Assign(ISprite sprite)
|
||||||
{
|
{
|
||||||
if (Initialized)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_sprite = sprite;
|
_sprite = sprite;
|
||||||
OnSpriteAssigned?.Invoke(this);
|
OnSpriteAssigned?.Invoke(this);
|
||||||
return true;
|
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)
|
public bool Assign(IEntity entity)
|
||||||
{
|
{
|
||||||
if (_entity.Initialized)
|
if (_entity is not null && _entity.Initialized)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_entity = entity;
|
_entity = entity;
|
||||||
|
|
Loading…
Reference in New Issue