refactor!: IGameObject removed
This commit is contained in:
@@ -17,19 +17,19 @@ public class BehaviourController : IBehaviourController
|
||||
|
||||
public event IBehaviourController.OnBehaviourAddedEventHandler? OnBehaviourAdded = null;
|
||||
public event IBehaviourController.OnBehaviourRemovedEventHandler? OnBehaviourRemoved = null;
|
||||
public event IAssignableGameObject.OnGameObjectAssignedEventHandler? OnGameObjectAssigned = null;
|
||||
public event IHasHierarchyObject.OnHierarchyObjectAssignedEventHandler? OnHierarchyObjectAssigned = null;
|
||||
|
||||
public event IInitialize.OnInitializedEventHandler? OnInitialized = null;
|
||||
public event IInitialize.OnFinalizedEventHandler? OnFinalized = null;
|
||||
public event IInitializable.OnInitializedEventHandler? OnInitialized = null;
|
||||
public event IInitializable.OnFinalizedEventHandler? OnFinalized = null;
|
||||
|
||||
public event IAssignable.OnUnassignedEventHandler? OnUnassigned = null;
|
||||
|
||||
private readonly IList<IBehaviour> behaviours = new List<IBehaviour>(Constants.BEHAVIOURS_SIZE_INITIAL);
|
||||
|
||||
private IGameObject _gameObject = null!;
|
||||
private IHierarchyObject _hierarchyObject = null!;
|
||||
private bool _initialized = false;
|
||||
|
||||
public IGameObject GameObject => _gameObject;
|
||||
public IHierarchyObject HierarchyObject => _hierarchyObject;
|
||||
|
||||
public bool IsInitialized
|
||||
{
|
||||
@@ -52,7 +52,7 @@ public class BehaviourController : IBehaviourController
|
||||
InsertBehaviourByPriority(behaviour);
|
||||
|
||||
behaviour.Assign(this);
|
||||
behaviour.Assign(GameObject.StateEnable);
|
||||
behaviour.Assign(HierarchyObject.StateEnable);
|
||||
|
||||
behaviour.Initialize();
|
||||
behaviour.OnPriorityChanged += OnPriorityChange;
|
||||
@@ -61,7 +61,7 @@ public class BehaviourController : IBehaviourController
|
||||
}
|
||||
|
||||
public T AddBehaviour<T>(params object?[]? args) where T : class, IBehaviour
|
||||
=> AddBehaviour(new Factory.BehaviourFactory().Instantiate<T>(_gameObject, args));
|
||||
=> AddBehaviour(new Factory.BehaviourFactory().Instantiate<T>(_hierarchyObject, args));
|
||||
|
||||
public T? GetBehaviour<T>()
|
||||
{
|
||||
@@ -116,7 +116,7 @@ public class BehaviourController : IBehaviourController
|
||||
public void RemoveBehaviour<T>(T behaviour) where T : class, IBehaviour
|
||||
{
|
||||
if (!behaviours.Contains(behaviour))
|
||||
throw new Exception($"{behaviour.GetType().Name} does not exist in {GameObject.Name}'s {nameof(IBehaviourController)}.");
|
||||
throw new Exception($"{behaviour.GetType().Name} does not exist in {HierarchyObject.Name}'s {nameof(IBehaviourController)}.");
|
||||
|
||||
behaviour.OnPriorityChanged -= OnPriorityChange;
|
||||
behaviour.Finalize();
|
||||
@@ -124,13 +124,13 @@ public class BehaviourController : IBehaviourController
|
||||
OnBehaviourRemoved?.Invoke(this, behaviour);
|
||||
}
|
||||
|
||||
public bool Assign(IGameObject gameObject)
|
||||
public bool Assign(IHierarchyObject hierarchyObject)
|
||||
{
|
||||
if (GameObject is not null && GameObject.IsInitialized)
|
||||
if (HierarchyObject is not null && HierarchyObject.IsInitialized)
|
||||
return false;
|
||||
|
||||
_gameObject = gameObject;
|
||||
OnGameObjectAssigned?.Invoke(this);
|
||||
_hierarchyObject = hierarchyObject;
|
||||
OnHierarchyObjectAssigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public class BehaviourController : IBehaviourController
|
||||
if (IsInitialized)
|
||||
return false;
|
||||
|
||||
NotAssignedException.Check(this, _gameObject);
|
||||
NotAssignedException.Check(this, _hierarchyObject);
|
||||
|
||||
foreach (IBehaviour behaviour in behaviours)
|
||||
behaviour.Initialize();
|
||||
@@ -165,14 +165,14 @@ public class BehaviourController : IBehaviourController
|
||||
if (IsInitialized)
|
||||
return false;
|
||||
|
||||
_gameObject = null!;
|
||||
_hierarchyObject = null!;
|
||||
OnUnassigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!GameObject.StateEnable.Enabled)
|
||||
if (!HierarchyObject.StateEnable.Enabled)
|
||||
return;
|
||||
|
||||
OnPreUpdate?.Invoke(this);
|
||||
@@ -181,14 +181,14 @@ public class BehaviourController : IBehaviourController
|
||||
|
||||
public void UpdatePreDraw()
|
||||
{
|
||||
if (!GameObject.StateEnable.Enabled)
|
||||
if (!HierarchyObject.StateEnable.Enabled)
|
||||
return;
|
||||
|
||||
OnPreDraw?.Invoke(this);
|
||||
}
|
||||
|
||||
public BehaviourController() { }
|
||||
public BehaviourController(IGameObject gameObject) => Assign(gameObject);
|
||||
public BehaviourController(IHierarchyObject hierarchyObject) => Assign(hierarchyObject);
|
||||
|
||||
private void InsertBehaviourByPriority<T>(T behaviour) where T : class, IBehaviour
|
||||
{
|
||||
|
Reference in New Issue
Block a user