feat: Parent Change Propagation to Children
This commit is contained in:
parent
14e3337daa
commit
3902f1caca
|
@ -133,6 +133,7 @@ public class Transform : ITransform
|
|||
Parent.OnPositionChanged -= RecalculatePosition;
|
||||
Parent.OnScaleChanged -= RecalculateScale;
|
||||
Parent.OnRotationChanged -= RecalculateRotation;
|
||||
Parent.OnParentChanged -= NotifyChildrenOnParentChange;
|
||||
}
|
||||
|
||||
Parent = transform;
|
||||
|
@ -143,6 +144,7 @@ public class Transform : ITransform
|
|||
transform.OnPositionChanged += RecalculatePosition;
|
||||
transform.OnScaleChanged += RecalculateScale;
|
||||
transform.OnRotationChanged += RecalculateRotation;
|
||||
transform.OnParentChanged += NotifyChildrenOnParentChange;
|
||||
}
|
||||
|
||||
UpdateLocalPosition();
|
||||
|
@ -174,6 +176,14 @@ public class Transform : ITransform
|
|||
public IEnumerator<ITransform> GetEnumerator() => _children.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => _children.GetEnumerator();
|
||||
|
||||
private void NotifyChildrenOnParentChange(ITransform transform, ITransform? previousParent)
|
||||
{
|
||||
// TODO No idea how logical this is to propagate this to the children the way I'm doing right now.
|
||||
// I was originally gonna just call `child.OnParentChanged?.Invoke(child, child.Parent);` but seems an unnecessary call too?
|
||||
foreach (var child in Children)
|
||||
child.OnParentChanged?.Invoke(transform, previousParent);
|
||||
}
|
||||
|
||||
private void RecalculatePosition(ITransform _)
|
||||
{
|
||||
if (Parent is null)
|
||||
|
|
Loading…
Reference in New Issue