fix: OnEnterHierarchy Not Being Called Correctly
This commit is contained in:
parent
cb60c71184
commit
cc44e1ea69
|
@ -29,7 +29,11 @@ public abstract class Behaviour : BehaviourBase
|
||||||
BehaviourController.OnUpdate += Update;
|
BehaviourController.OnUpdate += Update;
|
||||||
BehaviourController.GameObject.OnEnteredHierarchy += EnteredHierarchy;
|
BehaviourController.GameObject.OnEnteredHierarchy += EnteredHierarchy;
|
||||||
BehaviourController.GameObject.OnExitedHierarchy += ExitedHierarchy;
|
BehaviourController.GameObject.OnExitedHierarchy += ExitedHierarchy;
|
||||||
|
|
||||||
OnInitialize();
|
OnInitialize();
|
||||||
|
|
||||||
|
if (GameObject.IsInHierarchy)
|
||||||
|
EnteredHierarchy(GameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnFinalize() { }
|
protected virtual void OnFinalize() { }
|
||||||
|
|
|
@ -61,12 +61,12 @@ public class GameManager : BaseEntity, IGameManager
|
||||||
Register(gameObject);
|
Register(gameObject);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (!hierarchyObject.Initialize())
|
||||||
|
throw new Exception($"{nameof(hierarchyObject)} can't be initialized");
|
||||||
|
|
||||||
_hierarchyObjects.Add(hierarchyObject);
|
_hierarchyObjects.Add(hierarchyObject);
|
||||||
hierarchyObject.EnterHierarchy(this);
|
hierarchyObject.EnterHierarchy(this);
|
||||||
|
|
||||||
if (!hierarchyObject.Initialize())
|
|
||||||
throw new Exception($"{nameof(hierarchyObject)} can't be finalized");
|
|
||||||
|
|
||||||
OnHierarchyObjectRegistered?.Invoke(this, hierarchyObject);
|
OnHierarchyObjectRegistered?.Invoke(this, hierarchyObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,15 +140,15 @@ public class GameManager : BaseEntity, IGameManager
|
||||||
gameObject.OnFinalized += OnGameObjectFinalize;
|
gameObject.OnFinalized += OnGameObjectFinalize;
|
||||||
gameObject.OnExitedHierarchy += OnGameObjectExitedHierarchy;
|
gameObject.OnExitedHierarchy += OnGameObjectExitedHierarchy;
|
||||||
|
|
||||||
|
if (!gameObject.Initialize())
|
||||||
|
throw new Exception($"{nameof(gameObject)} can't be initialized");
|
||||||
|
|
||||||
_gameObjects.Add(gameObject);
|
_gameObjects.Add(gameObject);
|
||||||
_hierarchyObjects.Add(gameObject);
|
_hierarchyObjects.Add(gameObject);
|
||||||
|
|
||||||
if (!gameObject.EnterHierarchy(this))
|
if (!gameObject.EnterHierarchy(this))
|
||||||
throw new Exception($"{nameof(gameObject)} can't enter the hierarchy");
|
throw new Exception($"{nameof(gameObject)} can't enter the hierarchy");
|
||||||
|
|
||||||
if (!gameObject.Initialize())
|
|
||||||
throw new Exception($"{nameof(gameObject)} can't be initialized");
|
|
||||||
|
|
||||||
OnHierarchyObjectRegistered?.Invoke(this, gameObject);
|
OnHierarchyObjectRegistered?.Invoke(this, gameObject);
|
||||||
OnGameObjectRegistered?.Invoke(this, gameObject);
|
OnGameObjectRegistered?.Invoke(this, gameObject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ public class GameObject : BaseEntity, IGameObject
|
||||||
|
|
||||||
NotAssignedException.Check(this, _transform);
|
NotAssignedException.Check(this, _transform);
|
||||||
NotAssignedException.Check(this, _behaviourController);
|
NotAssignedException.Check(this, _behaviourController);
|
||||||
NotAssignedException.Check(this, _gameManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
|
|
Loading…
Reference in New Issue