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)
|
public void Remove(IHierarchyObject hierarchyObject)
|
||||||
|
{
|
||||||
|
hierarchyObject.SetParent(null);
|
||||||
|
RemoveIncursive(hierarchyObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveIncursive(IHierarchyObject hierarchyObject)
|
||||||
{
|
{
|
||||||
if (!_hierarchyObjects.Contains(hierarchyObject))
|
if (!_hierarchyObjects.Contains(hierarchyObject))
|
||||||
throw new Exception($"{nameof(IHierarchyObject)} named {hierarchyObject.Name} is not registered to the {nameof(GameManager)}.");
|
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]);
|
Remove(hierarchyObject.Children[i]);
|
||||||
|
|
||||||
_hierarchyObjects.Remove(hierarchyObject);
|
_hierarchyObjects.Remove(hierarchyObject);
|
||||||
hierarchyObject.SetParent(null);
|
|
||||||
|
|
||||||
if (!hierarchyObject.ExitHierarchy())
|
if (!hierarchyObject.ExitHierarchy())
|
||||||
throw new Exception($"{hierarchyObject.Name} can't exit the hierarchy");
|
throw new Exception($"{hierarchyObject.Name} can't exit the hierarchy");
|
||||||
|
@ -64,7 +64,6 @@ public class HierarchyObject : BaseEntity, IHierarchyObject
|
|||||||
|
|
||||||
OnExitingHierarchy(gameManager);
|
OnExitingHierarchy(gameManager);
|
||||||
_gameManager = null!;
|
_gameManager = null!;
|
||||||
SetParent(null);
|
|
||||||
OnExitedHierarchy?.Invoke(this, gameManager);
|
OnExitedHierarchy?.Invoke(this, gameManager);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,6 @@ public class Transform2D : Behaviour, ITransform2D
|
|||||||
ITransform2D? previousParent = parentTransform;
|
ITransform2D? previousParent = parentTransform;
|
||||||
if (previousParent is not null)
|
if (previousParent is not null)
|
||||||
{
|
{
|
||||||
previousParent.BehaviourController.HierarchyObject.RemoveChild(HierarchyObject);
|
|
||||||
previousParent.OnPositionChanged -= RecalculatePosition;
|
previousParent.OnPositionChanged -= RecalculatePosition;
|
||||||
previousParent.OnScaleChanged -= RecalculateScale;
|
previousParent.OnScaleChanged -= RecalculateScale;
|
||||||
previousParent.OnRotationChanged -= RecalculateRotation;
|
previousParent.OnRotationChanged -= RecalculateRotation;
|
||||||
@ -232,7 +231,6 @@ public class Transform2D : Behaviour, ITransform2D
|
|||||||
|
|
||||||
if (parentTransform is not null)
|
if (parentTransform is not null)
|
||||||
{
|
{
|
||||||
parentTransform.BehaviourController.HierarchyObject.AddChild(HierarchyObject);
|
|
||||||
parentTransform.OnPositionChanged += RecalculatePosition;
|
parentTransform.OnPositionChanged += RecalculatePosition;
|
||||||
parentTransform.OnScaleChanged += RecalculateScale;
|
parentTransform.OnScaleChanged += RecalculateScale;
|
||||||
parentTransform.OnRotationChanged += RecalculateRotation;
|
parentTransform.OnRotationChanged += RecalculateRotation;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user