fix: removing an object from hierarchy setting all children's parents null
This commit is contained in:
parent
193d23c877
commit
4081693d32
@ -68,6 +68,12 @@ public class GameManager : BaseEntity, IGameManager
|
||||
}
|
||||
|
||||
public void Remove(IHierarchyObject hierarchyObject)
|
||||
{
|
||||
hierarchyObject.SetParent(null);
|
||||
RemoveIncursive(hierarchyObject);
|
||||
}
|
||||
|
||||
private void RemoveIncursive(IHierarchyObject hierarchyObject)
|
||||
{
|
||||
if (!_hierarchyObjects.Contains(hierarchyObject))
|
||||
throw new Exception($"{nameof(IHierarchyObject)} named {hierarchyObject.Name} is not registered to the {nameof(GameManager)}.");
|
||||
@ -79,7 +85,6 @@ public class GameManager : BaseEntity, IGameManager
|
||||
Remove(hierarchyObject.Children[i]);
|
||||
|
||||
_hierarchyObjects.Remove(hierarchyObject);
|
||||
hierarchyObject.SetParent(null);
|
||||
|
||||
if (!hierarchyObject.ExitHierarchy())
|
||||
throw new Exception($"{hierarchyObject.Name} can't exit the hierarchy");
|
||||
|
@ -64,7 +64,6 @@ public class HierarchyObject : BaseEntity, IHierarchyObject
|
||||
|
||||
OnExitingHierarchy(gameManager);
|
||||
_gameManager = null!;
|
||||
SetParent(null);
|
||||
OnExitedHierarchy?.Invoke(this, gameManager);
|
||||
return true;
|
||||
}
|
||||
|
@ -220,7 +220,6 @@ public class Transform2D : Behaviour, ITransform2D
|
||||
ITransform2D? previousParent = parentTransform;
|
||||
if (previousParent is not null)
|
||||
{
|
||||
previousParent.BehaviourController.HierarchyObject.RemoveChild(HierarchyObject);
|
||||
previousParent.OnPositionChanged -= RecalculatePosition;
|
||||
previousParent.OnScaleChanged -= RecalculateScale;
|
||||
previousParent.OnRotationChanged -= RecalculateRotation;
|
||||
@ -232,7 +231,6 @@ public class Transform2D : Behaviour, ITransform2D
|
||||
|
||||
if (parentTransform is not null)
|
||||
{
|
||||
parentTransform.BehaviourController.HierarchyObject.AddChild(HierarchyObject);
|
||||
parentTransform.OnPositionChanged += RecalculatePosition;
|
||||
parentTransform.OnScaleChanged += RecalculateScale;
|
||||
parentTransform.OnRotationChanged += RecalculateRotation;
|
||||
|
Loading…
x
Reference in New Issue
Block a user