Compare commits
	
		
			5 Commits
		
	
	
		
			feb2a05aa3
			...
			67d7f401b8
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 67d7f401b8 | |||
| 9bf17cc191 | |||
| bf8fbebae3 | |||
| 1b0f25e854 | |||
| 61a7f685c1 | 
@@ -7,7 +7,7 @@ namespace Syntriax.Engine.Core;
 | 
			
		||||
/// Provides mechanisms for tracking additions and removals, and notifies subscribers when such events occur on the assigned <see cref="IUniverse"/>.
 | 
			
		||||
/// </summary>
 | 
			
		||||
/// <typeparam name="T">The type of objects tracked by the collector.</typeparam>
 | 
			
		||||
public interface IBehaviourCollector<T> : IHasUniverse, IEnumerable<T> where T : class
 | 
			
		||||
public interface IBehaviourCollector<T> : IHasUniverse where T : class
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Event triggered when an object of type <typeparamref name="T"/> is added to the collector.
 | 
			
		||||
 
 | 
			
		||||
@@ -19,8 +19,6 @@ public class ActiveBehaviourCollector<T> : IBehaviourCollector<T> where T : clas
 | 
			
		||||
    public IReadOnlyList<T> Behaviours => activeBehaviours;
 | 
			
		||||
    public IUniverse Universe { get; private set; } = null!;
 | 
			
		||||
 | 
			
		||||
    public T this[Index index] => activeBehaviours[index];
 | 
			
		||||
 | 
			
		||||
    public ActiveBehaviourCollector() { }
 | 
			
		||||
    public ActiveBehaviourCollector(IUniverse universe) => Assign(universe);
 | 
			
		||||
 | 
			
		||||
@@ -61,12 +59,12 @@ public class ActiveBehaviourCollector<T> : IBehaviourCollector<T> where T : clas
 | 
			
		||||
        {
 | 
			
		||||
            activeBehaviours.Add(behaviour);
 | 
			
		||||
            OnBehaviourAdd(behaviour);
 | 
			
		||||
            OnCollected?.InvokeSafe(this, behaviour);
 | 
			
		||||
            OnCollected?.Invoke(this, behaviour);
 | 
			
		||||
        }
 | 
			
		||||
        else if (activeBehaviours.Remove(behaviour))
 | 
			
		||||
        {
 | 
			
		||||
            OnBehaviourRemove(behaviour);
 | 
			
		||||
            OnRemoved?.InvokeSafe(this, behaviour);
 | 
			
		||||
            OnRemoved?.Invoke(this, behaviour);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -83,7 +81,7 @@ public class ActiveBehaviourCollector<T> : IBehaviourCollector<T> where T : clas
 | 
			
		||||
        if (activeBehaviours.Remove(tBehaviour))
 | 
			
		||||
        {
 | 
			
		||||
            OnBehaviourRemove(tBehaviour);
 | 
			
		||||
            OnRemoved?.InvokeSafe(this, tBehaviour);
 | 
			
		||||
            OnRemoved?.Invoke(this, tBehaviour);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -99,7 +97,7 @@ public class ActiveBehaviourCollector<T> : IBehaviourCollector<T> where T : clas
 | 
			
		||||
        universe.OnUniverseObjectUnRegistered += OnUniverseObjectUnregistered;
 | 
			
		||||
 | 
			
		||||
        Universe = universe;
 | 
			
		||||
        OnUniverseAssigned?.InvokeSafe(this);
 | 
			
		||||
        OnUniverseAssigned?.Invoke(this);
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
@@ -116,10 +114,7 @@ public class ActiveBehaviourCollector<T> : IBehaviourCollector<T> where T : clas
 | 
			
		||||
        Universe.OnUniverseObjectUnRegistered -= OnUniverseObjectUnregistered;
 | 
			
		||||
 | 
			
		||||
        Universe = null!;
 | 
			
		||||
        OnUnassigned?.InvokeSafe(this);
 | 
			
		||||
        OnUnassigned?.Invoke(this);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public IEnumerator<T> GetEnumerator() => activeBehaviours.GetEnumerator();
 | 
			
		||||
    IEnumerator IEnumerable.GetEnumerator() => activeBehaviours.GetEnumerator();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ public abstract class BaseEntity : IEntity
 | 
			
		||||
            string previousId = _id;
 | 
			
		||||
 | 
			
		||||
            _id = value;
 | 
			
		||||
            OnIdChanged?.InvokeSafe(this, previousId);
 | 
			
		||||
            OnIdChanged?.Invoke(this, previousId);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -47,9 +47,9 @@ public abstract class BaseEntity : IEntity
 | 
			
		||||
 | 
			
		||||
            _initialized = value;
 | 
			
		||||
            if (value)
 | 
			
		||||
                OnInitialized?.InvokeSafe(this);
 | 
			
		||||
                OnInitialized?.Invoke(this);
 | 
			
		||||
            else
 | 
			
		||||
                OnFinalized?.InvokeSafe(this);
 | 
			
		||||
                OnFinalized?.Invoke(this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -62,7 +62,7 @@ public abstract class BaseEntity : IEntity
 | 
			
		||||
        _stateEnable = stateEnable;
 | 
			
		||||
        _stateEnable.Assign(this);
 | 
			
		||||
        OnAssign(stateEnable);
 | 
			
		||||
        OnStateEnableAssigned?.InvokeSafe(this);
 | 
			
		||||
        OnStateEnableAssigned?.Invoke(this);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -76,7 +76,7 @@ public abstract class BaseEntity : IEntity
 | 
			
		||||
 | 
			
		||||
        _stateEnable = null!;
 | 
			
		||||
        _stateEnable.Unassign();
 | 
			
		||||
        OnUnassigned?.InvokeSafe(this);
 | 
			
		||||
        OnUnassigned?.Invoke(this);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
 | 
			
		||||
 | 
			
		||||
            int previousPriority = _priority;
 | 
			
		||||
            _priority = value;
 | 
			
		||||
            OnPriorityChanged?.InvokeSafe(this, previousPriority);
 | 
			
		||||
            OnPriorityChanged?.Invoke(this, previousPriority);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -39,7 +39,7 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
 | 
			
		||||
        behaviourController.OnUniverseObjectAssigned += OnUniverseObjectAssigned;
 | 
			
		||||
        if (behaviourController.UniverseObject is not null)
 | 
			
		||||
            OnUniverseObjectAssigned(behaviourController);
 | 
			
		||||
        OnBehaviourControllerAssigned?.InvokeSafe(this);
 | 
			
		||||
        OnBehaviourControllerAssigned?.Invoke(this);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -79,6 +79,6 @@ public abstract class BehaviourBase : BaseEntity, IBehaviour
 | 
			
		||||
        _isActive = StateEnable.Enabled && _behaviourController.UniverseObject.IsActive;
 | 
			
		||||
 | 
			
		||||
        if (previousActive != IsActive)
 | 
			
		||||
            OnActiveChanged?.InvokeSafe(this, previousActive);
 | 
			
		||||
            OnActiveChanged?.Invoke(this, previousActive);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,8 +17,6 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
 | 
			
		||||
    public IReadOnlyList<T> Behaviours => behaviours;
 | 
			
		||||
    public IUniverse Universe { get; private set; } = null!;
 | 
			
		||||
 | 
			
		||||
    public T this[Index index] => behaviours[index];
 | 
			
		||||
 | 
			
		||||
    public BehaviourCollector() { }
 | 
			
		||||
    public BehaviourCollector(IUniverse universe) => Assign(universe);
 | 
			
		||||
 | 
			
		||||
@@ -48,7 +46,7 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
 | 
			
		||||
 | 
			
		||||
        behaviours.Add(tBehaviour);
 | 
			
		||||
        OnBehaviourAdd(behaviour);
 | 
			
		||||
        OnCollected?.InvokeSafe(this, tBehaviour);
 | 
			
		||||
        OnCollected?.Invoke(this, tBehaviour);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected virtual void OnBehaviourRemove(IBehaviour behaviour) { }
 | 
			
		||||
@@ -61,7 +59,7 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
        OnBehaviourRemove(behaviour);
 | 
			
		||||
        OnRemoved?.InvokeSafe(this, tBehaviour);
 | 
			
		||||
        OnRemoved?.Invoke(this, tBehaviour);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected virtual void OnAssign(IUniverse universe) { }
 | 
			
		||||
@@ -78,7 +76,7 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
 | 
			
		||||
 | 
			
		||||
        Universe = universe;
 | 
			
		||||
        OnAssign(universe);
 | 
			
		||||
        OnUniverseAssigned?.InvokeSafe(this);
 | 
			
		||||
        OnUniverseAssigned?.Invoke(this);
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
@@ -95,10 +93,7 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
 | 
			
		||||
        Universe.OnUniverseObjectUnRegistered -= OnUniverseObjectUnregistered;
 | 
			
		||||
 | 
			
		||||
        Universe = null!;
 | 
			
		||||
        OnUnassigned?.InvokeSafe(this);
 | 
			
		||||
        OnUnassigned?.Invoke(this);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public IEnumerator<T> GetEnumerator() => behaviours.GetEnumerator();
 | 
			
		||||
    IEnumerator IEnumerable.GetEnumerator() => behaviours.GetEnumerator();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ public class BehaviourController : BaseEntity, IBehaviourController
 | 
			
		||||
        if (IsInitialized)
 | 
			
		||||
            behaviour.Initialize();
 | 
			
		||||
        behaviour.OnPriorityChanged += OnPriorityChange;
 | 
			
		||||
        OnBehaviourAdded?.InvokeSafe(this, behaviour);
 | 
			
		||||
        OnBehaviourAdded?.Invoke(this, behaviour);
 | 
			
		||||
        return behaviour;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -95,7 +95,7 @@ public class BehaviourController : BaseEntity, IBehaviourController
 | 
			
		||||
        behaviour.OnPriorityChanged -= OnPriorityChange;
 | 
			
		||||
        behaviour.Finalize();
 | 
			
		||||
        behaviours.Remove(behaviour);
 | 
			
		||||
        OnBehaviourRemoved?.InvokeSafe(this, behaviour);
 | 
			
		||||
        OnBehaviourRemoved?.Invoke(this, behaviour);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected virtual void OnAssign(IUniverseObject universeObject) { }
 | 
			
		||||
@@ -106,7 +106,7 @@ public class BehaviourController : BaseEntity, IBehaviourController
 | 
			
		||||
 | 
			
		||||
        _universeObject = universeObject;
 | 
			
		||||
        OnAssign(universeObject);
 | 
			
		||||
        OnUniverseObjectAssigned?.InvokeSafe(this);
 | 
			
		||||
        OnUniverseObjectAssigned?.Invoke(this);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,9 +4,10 @@ namespace Syntriax.Engine.Core;
 | 
			
		||||
 | 
			
		||||
public static class DelegateExtensions
 | 
			
		||||
{
 | 
			
		||||
    [Obsolete($"{nameof(InvokeSafe)} causes memory allocation, please use Invoke() instead.")]
 | 
			
		||||
    public static void InvokeSafe(this Delegate @delegate, params object?[] args)
 | 
			
		||||
    {
 | 
			
		||||
        foreach (Delegate invocation in @delegate.GetInvocationList())
 | 
			
		||||
        foreach (Delegate invocation in Delegate.EnumerateInvocationList(@delegate))
 | 
			
		||||
            try { invocation.DynamicInvoke(args); }
 | 
			
		||||
            catch (Exception exception)
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -19,10 +19,10 @@ public class ProgressionTracker : IProgressionTracker
 | 
			
		||||
        Progression = progression.Clamp(Progression, 1f);
 | 
			
		||||
        Status = status;
 | 
			
		||||
 | 
			
		||||
        OnUpdated?.InvokeSafe(this, previousProgression, previousStatus);
 | 
			
		||||
        OnUpdated?.Invoke(this, previousProgression, previousStatus);
 | 
			
		||||
 | 
			
		||||
        if (progression >= 1f)
 | 
			
		||||
            OnEnded?.InvokeSafe(this);
 | 
			
		||||
            OnEnded?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void IProgressionTracker.Reset()
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,7 @@ public class Shape2D(List<Vector2D> vertices) : IEnumerable<Vector2D>
 | 
			
		||||
            foreach (Vector2D vertex in value)
 | 
			
		||||
                _vertices.Add(vertex);
 | 
			
		||||
 | 
			
		||||
            OnShapeUpdated?.InvokeSafe(this);
 | 
			
		||||
            OnShapeUpdated?.Invoke(this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -229,7 +229,7 @@ public class Shape2D(List<Vector2D> vertices) : IEnumerable<Vector2D>
 | 
			
		||||
        for (int i = 0; i < count; i++)
 | 
			
		||||
            to._vertices.Add(transform.Transform(from[i]));
 | 
			
		||||
 | 
			
		||||
        to.OnShapeUpdated?.InvokeSafe(to);
 | 
			
		||||
        to.OnShapeUpdated?.Invoke(to);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ public class EntityRegistry
 | 
			
		||||
    public void Add(IEntity entity)
 | 
			
		||||
    {
 | 
			
		||||
        if (registeredEntities.TryAdd(entity.Id, entity))
 | 
			
		||||
            OnEntityRegistered?.InvokeSafe(this, entity);
 | 
			
		||||
            OnEntityRegistered?.Invoke(this, entity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void QueueAssign(string id, Action<IEntity> setMethod)
 | 
			
		||||
@@ -26,7 +26,7 @@ public class EntityRegistry
 | 
			
		||||
    public void AssignAll()
 | 
			
		||||
    {
 | 
			
		||||
        foreach ((string id, Action<IEntity>? action) in assignCallbacks)
 | 
			
		||||
            action?.InvokeSafe(registeredEntities[id]);
 | 
			
		||||
            action?.Invoke(registeredEntities[id]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Reset()
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@ public class StateEnable : IStateEnable
 | 
			
		||||
 | 
			
		||||
            bool previousState = _enabled;
 | 
			
		||||
            _enabled = value;
 | 
			
		||||
            OnEnabledChanged?.InvokeSafe(this, previousState);
 | 
			
		||||
            OnEnabledChanged?.Invoke(this, previousState);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -33,7 +33,7 @@ public class StateEnable : IStateEnable
 | 
			
		||||
 | 
			
		||||
        _entity = entity;
 | 
			
		||||
        OnAssign(entity);
 | 
			
		||||
        OnEntityAssigned?.InvokeSafe(this);
 | 
			
		||||
        OnEntityAssigned?.Invoke(this);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -43,7 +43,7 @@ public class StateEnable : IStateEnable
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        _entity = null!;
 | 
			
		||||
        OnUnassigned?.InvokeSafe(this);
 | 
			
		||||
        OnUnassigned?.Invoke(this);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ public class UpdateManager : UniverseObject
 | 
			
		||||
    private readonly ActiveBehaviourCollectorSorted<IUpdate> updateEntities = new() { SortBy = SortByPriority() };
 | 
			
		||||
    private readonly ActiveBehaviourCollectorSorted<IPostUpdate> postUpdateEntities = new() { SortBy = SortByPriority() };
 | 
			
		||||
 | 
			
		||||
    private readonly List<IFirstFrameUpdate> toCallFirstFrameUpdates = [];
 | 
			
		||||
    private readonly List<IFirstFrameUpdate> toCallFirstFrameUpdates = new(32);
 | 
			
		||||
 | 
			
		||||
    protected override void OnEnteringUniverse(IUniverse universe)
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,7 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
            _position = value;
 | 
			
		||||
 | 
			
		||||
            UpdateLocalPosition();
 | 
			
		||||
            OnPositionChanged?.InvokeSafe(this, previousPosition);
 | 
			
		||||
            OnPositionChanged?.Invoke(this, previousPosition);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -47,7 +47,7 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
            _scale = value;
 | 
			
		||||
 | 
			
		||||
            UpdateLocalScale();
 | 
			
		||||
            OnScaleChanged?.InvokeSafe(this, previousScale);
 | 
			
		||||
            OnScaleChanged?.Invoke(this, previousScale);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -63,7 +63,7 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
            _rotation = value;
 | 
			
		||||
 | 
			
		||||
            UpdateLocalRotation();
 | 
			
		||||
            OnRotationChanged?.InvokeSafe(this, previousRotation);
 | 
			
		||||
            OnRotationChanged?.Invoke(this, previousRotation);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -79,7 +79,7 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
            _localPosition = value;
 | 
			
		||||
 | 
			
		||||
            UpdatePosition();
 | 
			
		||||
            OnPositionChanged?.InvokeSafe(this, previousPosition);
 | 
			
		||||
            OnPositionChanged?.Invoke(this, previousPosition);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -97,8 +97,8 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
 | 
			
		||||
            UpdateScale();
 | 
			
		||||
            UpdatePosition();
 | 
			
		||||
            OnScaleChanged?.InvokeSafe(this, previousScale);
 | 
			
		||||
            OnPositionChanged?.InvokeSafe(this, previousPosition);
 | 
			
		||||
            OnScaleChanged?.Invoke(this, previousScale);
 | 
			
		||||
            OnPositionChanged?.Invoke(this, previousPosition);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -114,7 +114,7 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
            _localRotation = value;
 | 
			
		||||
 | 
			
		||||
            UpdateRotation();
 | 
			
		||||
            OnRotationChanged?.InvokeSafe(this, previousRotation);
 | 
			
		||||
            OnRotationChanged?.Invoke(this, previousRotation);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +125,7 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
 | 
			
		||||
        UpdatePosition();
 | 
			
		||||
 | 
			
		||||
        OnPositionChanged?.InvokeSafe(this, previousPosition);
 | 
			
		||||
        OnPositionChanged?.Invoke(this, previousPosition);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void RecalculateScale(ITransform2D _, Vector2D previousScale)
 | 
			
		||||
@@ -138,8 +138,8 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
        UpdateScale();
 | 
			
		||||
        UpdatePosition();
 | 
			
		||||
 | 
			
		||||
        OnScaleChanged?.InvokeSafe(this, previousScale);
 | 
			
		||||
        OnPositionChanged?.InvokeSafe(this, previousPosition);
 | 
			
		||||
        OnScaleChanged?.Invoke(this, previousScale);
 | 
			
		||||
        OnPositionChanged?.Invoke(this, previousPosition);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void RecalculateRotation(ITransform2D _, float previousRotation)
 | 
			
		||||
@@ -152,8 +152,8 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
        UpdateRotation();
 | 
			
		||||
        UpdatePosition();
 | 
			
		||||
 | 
			
		||||
        OnRotationChanged?.InvokeSafe(this, previousRotation);
 | 
			
		||||
        OnPositionChanged?.InvokeSafe(this, previousPosition);
 | 
			
		||||
        OnRotationChanged?.Invoke(this, previousRotation);
 | 
			
		||||
        OnPositionChanged?.Invoke(this, previousPosition);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void UpdateLocalPosition()
 | 
			
		||||
@@ -247,9 +247,9 @@ public class Transform2D : Behaviour, ITransform2D
 | 
			
		||||
        UpdateLocalScale();
 | 
			
		||||
        UpdateLocalRotation();
 | 
			
		||||
 | 
			
		||||
        OnPositionChanged?.InvokeSafe(this, Position);
 | 
			
		||||
        OnScaleChanged?.InvokeSafe(this, Scale);
 | 
			
		||||
        OnRotationChanged?.InvokeSafe(this, Rotation);
 | 
			
		||||
        OnPositionChanged?.Invoke(this, Position);
 | 
			
		||||
        OnScaleChanged?.Invoke(this, Scale);
 | 
			
		||||
        OnRotationChanged?.Invoke(this, Rotation);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void LookForTransform2D(IBehaviourController sender, IBehaviour behaviourAdded)
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,7 @@ public class Universe : BaseEntity, IUniverse
 | 
			
		||||
 | 
			
		||||
            float previousTimeScale = _timeScale;
 | 
			
		||||
            _timeScale = value;
 | 
			
		||||
            OnTimeScaleChanged?.InvokeSafe(this, previousTimeScale);
 | 
			
		||||
            OnTimeScaleChanged?.Invoke(this, previousTimeScale);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -60,7 +60,7 @@ public class Universe : BaseEntity, IUniverse
 | 
			
		||||
        if (!universeObject.EnterUniverse(this))
 | 
			
		||||
            throw new Exception($"{universeObject.Name} can't enter the universe");
 | 
			
		||||
 | 
			
		||||
        OnUniverseObjectRegistered?.InvokeSafe(this, universeObject);
 | 
			
		||||
        OnUniverseObjectRegistered?.Invoke(this, universeObject);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public T InstantiateUniverseObject<T>(params object?[]? args) where T : class, IUniverseObject
 | 
			
		||||
@@ -95,7 +95,7 @@ public class Universe : BaseEntity, IUniverse
 | 
			
		||||
        if (!universeObject.Finalize())
 | 
			
		||||
            throw new Exception($"{universeObject.Name} can't be finalized");
 | 
			
		||||
 | 
			
		||||
        OnUniverseObjectUnRegistered?.InvokeSafe(this, universeObject);
 | 
			
		||||
        OnUniverseObjectUnRegistered?.Invoke(this, universeObject);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void InitializeInternal()
 | 
			
		||||
@@ -118,18 +118,18 @@ public class Universe : BaseEntity, IUniverse
 | 
			
		||||
        UnscaledTime = engineTime;
 | 
			
		||||
        Time = new(TimeSpan.FromTicks((long)(Time.TimeSinceStart.Ticks + engineTime.DeltaSpan.Ticks * TimeScale)), TimeSpan.FromTicks((long)(engineTime.DeltaSpan.Ticks * TimeScale)));
 | 
			
		||||
 | 
			
		||||
        OnPreUpdate?.InvokeSafe(this, Time);
 | 
			
		||||
        OnUpdate?.InvokeSafe(this, Time);
 | 
			
		||||
        OnPostUpdate?.InvokeSafe(this, Time);
 | 
			
		||||
        OnPreUpdate?.Invoke(this, Time);
 | 
			
		||||
        OnUpdate?.Invoke(this, Time);
 | 
			
		||||
        OnPostUpdate?.Invoke(this, Time);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Draw()
 | 
			
		||||
    {
 | 
			
		||||
        Debug.Assert.AssertInitialized(this);
 | 
			
		||||
 | 
			
		||||
        OnPreDraw?.InvokeSafe(this);
 | 
			
		||||
        OnDraw?.InvokeSafe(this);
 | 
			
		||||
        OnPostDraw?.InvokeSafe(this);
 | 
			
		||||
        OnPreDraw?.Invoke(this);
 | 
			
		||||
        OnDraw?.Invoke(this);
 | 
			
		||||
        OnPostDraw?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void OnUniverseObjectFinalize(IInitializable initializable)
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
 | 
			
		||||
 | 
			
		||||
            string previousName = _name;
 | 
			
		||||
            _name = value;
 | 
			
		||||
            OnNameChanged?.InvokeSafe(this, previousName);
 | 
			
		||||
            OnNameChanged?.Invoke(this, previousName);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -50,7 +50,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
 | 
			
		||||
        _universe = universe;
 | 
			
		||||
        UpdateActive();
 | 
			
		||||
        OnEnteringUniverse(universe);
 | 
			
		||||
        OnEnteredUniverse?.InvokeSafe(this, universe);
 | 
			
		||||
        OnEnteredUniverse?.Invoke(this, universe);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -62,7 +62,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
 | 
			
		||||
 | 
			
		||||
        OnExitingUniverse(universe);
 | 
			
		||||
        _universe = null!;
 | 
			
		||||
        OnExitedUniverse?.InvokeSafe(this, universe);
 | 
			
		||||
        OnExitedUniverse?.Invoke(this, universe);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -93,7 +93,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        UpdateActive();
 | 
			
		||||
        OnParentChanged?.InvokeSafe(this, previousParent, parent);
 | 
			
		||||
        OnParentChanged?.Invoke(this, previousParent, parent);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void AddChild(IUniverseObject parent)
 | 
			
		||||
@@ -103,7 +103,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
 | 
			
		||||
 | 
			
		||||
        _children.Add(parent);
 | 
			
		||||
        parent.SetParent(this);
 | 
			
		||||
        OnChildrenAdded?.InvokeSafe(this, parent);
 | 
			
		||||
        OnChildrenAdded?.Invoke(this, parent);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void RemoveChild(IUniverseObject child)
 | 
			
		||||
@@ -112,7 +112,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
        child.SetParent(null);
 | 
			
		||||
        OnChildrenRemoved?.InvokeSafe(this, child);
 | 
			
		||||
        OnChildrenRemoved?.Invoke(this, child);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected virtual void OnAssign(IBehaviourController behaviourController) { }
 | 
			
		||||
@@ -123,7 +123,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
 | 
			
		||||
 | 
			
		||||
        _behaviourController = behaviourController;
 | 
			
		||||
        OnAssign(behaviourController);
 | 
			
		||||
        OnBehaviourControllerAssigned?.InvokeSafe(this);
 | 
			
		||||
        OnBehaviourControllerAssigned?.Invoke(this);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -143,7 +143,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
 | 
			
		||||
        _isActive = StateEnable.Enabled && (Parent?.IsActive ?? true);
 | 
			
		||||
 | 
			
		||||
        if (previousActive != IsActive)
 | 
			
		||||
            OnActiveChanged?.InvokeSafe(this, previousActive);
 | 
			
		||||
            OnActiveChanged?.Invoke(this, previousActive);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void UnassignInternal()
 | 
			
		||||
 
 | 
			
		||||
@@ -69,7 +69,7 @@ public abstract class Collider2DBehaviourBase : Behaviour2D, ICollider2D
 | 
			
		||||
        Transform.OnRotationChanged -= SetNeedsRecalculationFromRotation;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Detect(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionDetected?.InvokeSafe(this, collisionDetectionInformation);
 | 
			
		||||
    public void Resolve(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionResolved?.InvokeSafe(this, collisionDetectionInformation);
 | 
			
		||||
    public void Trigger(ICollider2D initiator) => OnTriggered?.InvokeSafe(this, initiator);
 | 
			
		||||
    public void Detect(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionDetected?.Invoke(this, collisionDetectionInformation);
 | 
			
		||||
    public void Resolve(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionResolved?.Invoke(this, collisionDetectionInformation);
 | 
			
		||||
    public void Trigger(ICollider2D initiator) => OnTriggered?.Invoke(this, initiator);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -28,21 +28,21 @@ public class PhysicsEngine2D : UniverseObject, IPhysicsEngine2D
 | 
			
		||||
    {
 | 
			
		||||
        float intervalDeltaTime = deltaTime / IterationPerStep;
 | 
			
		||||
 | 
			
		||||
        foreach (IPrePhysicsUpdate physicsPreUpdate in physicsPreUpdateCollector)
 | 
			
		||||
            physicsPreUpdate.PrePhysicsUpdate(deltaTime);
 | 
			
		||||
        for (int i = physicsPreUpdateCollector.Behaviours.Count - 1; i >= 0; i--)
 | 
			
		||||
            physicsPreUpdateCollector.Behaviours[i].PrePhysicsUpdate(deltaTime);
 | 
			
		||||
 | 
			
		||||
        foreach (IPhysicsUpdate physicsUpdate in physicsUpdateCollector)
 | 
			
		||||
            physicsUpdate.PhysicsUpdate(deltaTime);
 | 
			
		||||
        for (int i = physicsUpdateCollector.Behaviours.Count - 1; i >= 0; i--)
 | 
			
		||||
            physicsUpdateCollector.Behaviours[i].PhysicsUpdate(deltaTime);
 | 
			
		||||
 | 
			
		||||
        for (int iterationIndex = 0; iterationIndex < IterationPerStep; iterationIndex++)
 | 
			
		||||
        {
 | 
			
		||||
            // Can Parallel
 | 
			
		||||
            foreach (IRigidBody2D rigidBody in rigidBodyCollector)
 | 
			
		||||
                StepRigidBody(rigidBody, intervalDeltaTime);
 | 
			
		||||
            for (int i = rigidBodyCollector.Behaviours.Count - 1; i >= 0; i--)
 | 
			
		||||
                StepRigidBody(rigidBodyCollector.Behaviours[i], intervalDeltaTime);
 | 
			
		||||
 | 
			
		||||
            // Can Parallel
 | 
			
		||||
            foreach (ICollider2D collider in colliderCollector)
 | 
			
		||||
                collider.Recalculate();
 | 
			
		||||
            for (int i = colliderCollector.Behaviours.Count - 1; i >= 0; i--)
 | 
			
		||||
                colliderCollector.Behaviours[i].Recalculate();
 | 
			
		||||
 | 
			
		||||
            // Can Parallel
 | 
			
		||||
            for (int x = 0; x < colliderCollector.Behaviours.Count; x++)
 | 
			
		||||
@@ -62,13 +62,13 @@ public class PhysicsEngine2D : UniverseObject, IPhysicsEngine2D
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            OnPhysicsIteration?.InvokeSafe(this, intervalDeltaTime);
 | 
			
		||||
            OnPhysicsIteration?.Invoke(this, intervalDeltaTime);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        foreach (IPostPhysicsUpdate physicsPostUpdate in physicsPostUpdateCollector)
 | 
			
		||||
            physicsPostUpdate.PostPhysicsUpdate(deltaTime);
 | 
			
		||||
        for (int i = physicsPostUpdateCollector.Behaviours.Count - 1; i >= 0; i--)
 | 
			
		||||
            physicsPostUpdateCollector.Behaviours[i].PostPhysicsUpdate(deltaTime);
 | 
			
		||||
 | 
			
		||||
        OnPhysicsStep?.InvokeSafe(this, deltaTime);
 | 
			
		||||
        OnPhysicsStep?.Invoke(this, deltaTime);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void StepIndividual(IRigidBody2D rigidBody, float deltaTime)
 | 
			
		||||
@@ -95,8 +95,8 @@ public class PhysicsEngine2D : UniverseObject, IPhysicsEngine2D
 | 
			
		||||
        {
 | 
			
		||||
            StepRigidBody(rigidBody, intervalDeltaTime);
 | 
			
		||||
 | 
			
		||||
            foreach (ICollider2D collider in childColliders)
 | 
			
		||||
                collider.Recalculate();
 | 
			
		||||
            for (int i = childColliders.Count - 1; i >= 0; i--)
 | 
			
		||||
                childColliders[i].Recalculate();
 | 
			
		||||
 | 
			
		||||
            for (int x = 0; x < childColliders.Count; x++)
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -45,12 +45,12 @@ public class PhysicsEngine2DStandalone : IPhysicsEngine2D
 | 
			
		||||
        for (int iterationIndex = 0; iterationIndex < IterationPerStep; iterationIndex++)
 | 
			
		||||
        {
 | 
			
		||||
            // Can Parallel
 | 
			
		||||
            for (int i = 0; i < rigidBodies.Count; i++)
 | 
			
		||||
            for (int i = rigidBodies.Count - 1; i >= 0; i--)
 | 
			
		||||
                StepRigidBody(rigidBodies[i], intervalDeltaTime);
 | 
			
		||||
 | 
			
		||||
            // Can Parallel
 | 
			
		||||
            foreach (ICollider2D collider in colliders)
 | 
			
		||||
                collider.Recalculate();
 | 
			
		||||
            for (int i = colliders.Count - 1; i >= 0; i--)
 | 
			
		||||
                colliders[i].Recalculate();
 | 
			
		||||
 | 
			
		||||
            // Can Parallel
 | 
			
		||||
            for (int x = 0; x < colliders.Count; x++)
 | 
			
		||||
@@ -68,9 +68,9 @@ public class PhysicsEngine2DStandalone : IPhysicsEngine2D
 | 
			
		||||
                    ResolveColliders(colliderX, colliderY);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            OnPhysicsIteration?.InvokeSafe(this, intervalDeltaTime);
 | 
			
		||||
            OnPhysicsIteration?.Invoke(this, intervalDeltaTime);
 | 
			
		||||
        }
 | 
			
		||||
        OnPhysicsStep?.InvokeSafe(this, deltaTime);
 | 
			
		||||
        OnPhysicsStep?.Invoke(this, deltaTime);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void StepIndividual(IRigidBody2D rigidBody, float deltaTime)
 | 
			
		||||
 
 | 
			
		||||
@@ -53,12 +53,12 @@ public class State : BaseEntity, IState
 | 
			
		||||
    public void Update()
 | 
			
		||||
    {
 | 
			
		||||
        if (GetNextState() is IState transitionState)
 | 
			
		||||
            OnStateTransitionReady?.InvokeSafe(this, transitionState);
 | 
			
		||||
        OnStateUpdate?.InvokeSafe(this);
 | 
			
		||||
            OnStateTransitionReady?.Invoke(this, transitionState);
 | 
			
		||||
        OnStateUpdate?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void TransitionTo(IState from) => OnStateTransitionedTo?.InvokeSafe(this, from);
 | 
			
		||||
    public void TransitionFrom(IState to) => OnStateTransitionedFrom?.InvokeSafe(this, to);
 | 
			
		||||
    public void TransitionTo(IState from) => OnStateTransitionedTo?.Invoke(this, from);
 | 
			
		||||
    public void TransitionFrom(IState to) => OnStateTransitionedFrom?.Invoke(this, to);
 | 
			
		||||
 | 
			
		||||
    public IState? GetNextState()
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -30,21 +30,21 @@ public abstract class StateBehaviourBase : Behaviour, IState
 | 
			
		||||
    public void Update()
 | 
			
		||||
    {
 | 
			
		||||
        OnUpdateState();
 | 
			
		||||
        OnStateUpdate?.InvokeSafe(this);
 | 
			
		||||
        OnStateUpdate?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected virtual void OnTransitionedToState(IState from) { }
 | 
			
		||||
    public void TransitionTo(IState from)
 | 
			
		||||
    {
 | 
			
		||||
        OnTransitionedToState(from);
 | 
			
		||||
        OnStateTransitionedTo?.InvokeSafe(this, from);
 | 
			
		||||
        OnStateTransitionedTo?.Invoke(this, from);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected virtual void OnTransitionedFromState(IState to) { }
 | 
			
		||||
    public void TransitionFrom(IState to)
 | 
			
		||||
    {
 | 
			
		||||
        OnTransitionedFromState(to);
 | 
			
		||||
        OnStateTransitionedFrom?.InvokeSafe(this, to);
 | 
			
		||||
        OnStateTransitionedFrom?.Invoke(this, to);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public abstract IState? GetNextState();
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ public class StateMachine : Behaviour
 | 
			
		||||
            _state = value;
 | 
			
		||||
            previousState.TransitionFrom(value);
 | 
			
		||||
            value.TransitionTo(_state);
 | 
			
		||||
            OnStateChanged?.InvokeSafe(this, previousState, value);
 | 
			
		||||
            OnStateChanged?.Invoke(this, previousState, value);
 | 
			
		||||
 | 
			
		||||
            value.OnStateTransitionReady += OnStateTransitionReady;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,7 @@ public class StopwatchBehaviour : Behaviour, IStopwatch
 | 
			
		||||
        shouldBeTicking = false;
 | 
			
		||||
 | 
			
		||||
        State = TimerState.Stopped;
 | 
			
		||||
        OnStopped?.InvokeSafe(this);
 | 
			
		||||
        OnStopped?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void OnUpdate()
 | 
			
		||||
@@ -46,7 +46,7 @@ public class StopwatchBehaviour : Behaviour, IStopwatch
 | 
			
		||||
        double delta = Universe.Time.DeltaSpan.TotalSeconds;
 | 
			
		||||
 | 
			
		||||
        Time += delta;
 | 
			
		||||
        OnDelta?.InvokeSafe(this, delta);
 | 
			
		||||
        OnDelta?.Invoke(this, delta);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void OnEnteredUniverse(IUniverse universe)
 | 
			
		||||
@@ -71,13 +71,13 @@ public class StopwatchBehaviour : Behaviour, IStopwatch
 | 
			
		||||
    public virtual void Pause()
 | 
			
		||||
    {
 | 
			
		||||
        State = TimerState.Paused;
 | 
			
		||||
        OnPaused?.InvokeSafe(this);
 | 
			
		||||
        OnPaused?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public virtual void Resume()
 | 
			
		||||
    {
 | 
			
		||||
        State = TimerState.Ticking;
 | 
			
		||||
        OnResumed?.InvokeSafe(this);
 | 
			
		||||
        OnResumed?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void StartStopwatch()
 | 
			
		||||
@@ -85,7 +85,7 @@ public class StopwatchBehaviour : Behaviour, IStopwatch
 | 
			
		||||
        hasStartedTickingBefore = true;
 | 
			
		||||
 | 
			
		||||
        State = TimerState.Ticking;
 | 
			
		||||
        OnStarted?.InvokeSafe(this);
 | 
			
		||||
        OnStarted?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void OnFinalize()
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ public class TickerBehaviour : StopwatchBehaviour, ITicker
 | 
			
		||||
        {
 | 
			
		||||
            nextTick += Period;
 | 
			
		||||
            TickCounter++;
 | 
			
		||||
            OnTick?.InvokeSafe(this);
 | 
			
		||||
            OnTick?.Invoke(this);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -50,7 +50,7 @@ public class TimerBehaviour : Behaviour, ITimer
 | 
			
		||||
        shouldBeTicking = false;
 | 
			
		||||
 | 
			
		||||
        State = TimerState.Stopped;
 | 
			
		||||
        OnStopped?.InvokeSafe(this);
 | 
			
		||||
        OnStopped?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void OnUpdate()
 | 
			
		||||
@@ -61,7 +61,7 @@ public class TimerBehaviour : Behaviour, ITimer
 | 
			
		||||
        double delta = Universe.Time.DeltaSpan.TotalSeconds;
 | 
			
		||||
 | 
			
		||||
        Remaining -= delta;
 | 
			
		||||
        OnDelta?.InvokeSafe(this, delta);
 | 
			
		||||
        OnDelta?.Invoke(this, delta);
 | 
			
		||||
 | 
			
		||||
        if (Remaining <= .0f)
 | 
			
		||||
            Stop();
 | 
			
		||||
@@ -89,13 +89,13 @@ public class TimerBehaviour : Behaviour, ITimer
 | 
			
		||||
    public virtual void Pause()
 | 
			
		||||
    {
 | 
			
		||||
        State = TimerState.Paused;
 | 
			
		||||
        OnPaused?.InvokeSafe(this);
 | 
			
		||||
        OnPaused?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public virtual void Resume()
 | 
			
		||||
    {
 | 
			
		||||
        State = TimerState.Ticking;
 | 
			
		||||
        OnResumed?.InvokeSafe(this);
 | 
			
		||||
        OnResumed?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void StartTimer()
 | 
			
		||||
@@ -103,7 +103,7 @@ public class TimerBehaviour : Behaviour, ITimer
 | 
			
		||||
        hasStartedTickingBefore = true;
 | 
			
		||||
 | 
			
		||||
        State = TimerState.Ticking;
 | 
			
		||||
        OnStarted?.InvokeSafe(this);
 | 
			
		||||
        OnStarted?.Invoke(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void OnFinalize()
 | 
			
		||||
 
 | 
			
		||||
@@ -6,5 +6,5 @@ namespace Syntriax.Engine.Systems.Tween;
 | 
			
		||||
public static class TweenAABBExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenAABB(this AABB initialAABB, ITweenManager tweenManager, float duration, AABB targetAABB, Action<AABB> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(new AABB(initialAABB.LowerBoundary.Lerp(targetAABB.LowerBoundary, t), initialAABB.UpperBoundary.Lerp(targetAABB.UpperBoundary, t))));
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.Invoke(new AABB(initialAABB.LowerBoundary.Lerp(targetAABB.LowerBoundary, t), initialAABB.UpperBoundary.Lerp(targetAABB.UpperBoundary, t))));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ public static class TweenCircleExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenCircle(this Circle initialCircle, ITweenManager tweenManager, float duration, Circle targetCircle, System.Action<Circle> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration,
 | 
			
		||||
            t => setMethod?.InvokeSafe(
 | 
			
		||||
            t => setMethod?.Invoke(
 | 
			
		||||
                new Circle(
 | 
			
		||||
                    initialCircle.Center.Lerp(targetCircle.Center, t),
 | 
			
		||||
                    initialCircle.Diameter.Lerp(targetCircle.Diameter, t)
 | 
			
		||||
 
 | 
			
		||||
@@ -5,11 +5,11 @@ namespace Syntriax.Engine.Systems.Tween;
 | 
			
		||||
public static class TweenColorExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenColor(this ColorRGB initialColorRGB, ITweenManager tweenManager, float duration, ColorRGB targetColorRGB, System.Action<ColorRGB> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorRGB.Lerp(targetColorRGB, t)));
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.Invoke(initialColorRGB.Lerp(targetColorRGB, t)));
 | 
			
		||||
 | 
			
		||||
    public static ITween TweenColor(this ColorRGBA initialColorRGBA, ITweenManager tweenManager, float duration, ColorRGBA targetColorRGBA, System.Action<ColorRGBA> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorRGBA.Lerp(targetColorRGBA, t)));
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.Invoke(initialColorRGBA.Lerp(targetColorRGBA, t)));
 | 
			
		||||
 | 
			
		||||
    public static ITween TweenColor(this ColorHSV initialColorHSV, ITweenManager tweenManager, float duration, ColorHSV targetColorHSV, System.Action<ColorHSV> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorHSV.Lerp(targetColorHSV, t)));
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.Invoke(initialColorHSV.Lerp(targetColorHSV, t)));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ public static class TweenLine2DEquationExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenLine2DEquation(this Line2DEquation initialLine2DEquation, ITweenManager tweenManager, float duration, Line2DEquation targetLine2DEquation, System.Action<Line2DEquation> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration,
 | 
			
		||||
            t => setMethod?.InvokeSafe(
 | 
			
		||||
            t => setMethod?.Invoke(
 | 
			
		||||
                new Line2DEquation(
 | 
			
		||||
                    initialLine2DEquation.Slope.Lerp(targetLine2DEquation.Slope, t),
 | 
			
		||||
                    initialLine2DEquation.OffsetY.Lerp(targetLine2DEquation.OffsetY, t)
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ public static class TweenLine2DExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenLine2D(this Line2D initialLine2D, ITweenManager tweenManager, float duration, Line2D targetLine2D, System.Action<Line2D> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration,
 | 
			
		||||
            t => setMethod?.InvokeSafe(
 | 
			
		||||
            t => setMethod?.Invoke(
 | 
			
		||||
                new Line2D(
 | 
			
		||||
                    initialLine2D.From.Lerp(targetLine2D.From, t),
 | 
			
		||||
                    initialLine2D.To.Lerp(targetLine2D.To, t)
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ public static class TweenProjection1DExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenProjection1D(this Projection1D initialProjection1D, ITweenManager tweenManager, float duration, Projection1D targetProjection1D, Action<Projection1D> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration,
 | 
			
		||||
            t => setMethod?.InvokeSafe(
 | 
			
		||||
            t => setMethod?.Invoke(
 | 
			
		||||
                new Projection1D(
 | 
			
		||||
                    initialProjection1D.Min.Lerp(targetProjection1D.Min, t),
 | 
			
		||||
                    initialProjection1D.Max.Lerp(targetProjection1D.Max, t)
 | 
			
		||||
 
 | 
			
		||||
@@ -6,5 +6,5 @@ namespace Syntriax.Engine.Systems.Tween;
 | 
			
		||||
public static class TweenQuaternionExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenQuaternion(this Quaternion initialQuaternion, ITweenManager tweenManager, float duration, Quaternion targetQuaternion, Action<Quaternion> setMethod)
 | 
			
		||||
       => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialQuaternion.SLerp(targetQuaternion, t)));
 | 
			
		||||
       => tweenManager.StartTween(duration, t => setMethod?.Invoke(initialQuaternion.SLerp(targetQuaternion, t)));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ public static class TweenTriangleExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenTriangle(this Triangle initialTriangle, ITweenManager tweenManager, float duration, Triangle targetTriangle, Action<Triangle> setMethod)
 | 
			
		||||
       => tweenManager.StartTween(duration,
 | 
			
		||||
            t => setMethod?.InvokeSafe(
 | 
			
		||||
            t => setMethod?.Invoke(
 | 
			
		||||
                new Triangle(
 | 
			
		||||
                    initialTriangle.A.Lerp(targetTriangle.A, t),
 | 
			
		||||
                    initialTriangle.B.Lerp(targetTriangle.B, t),
 | 
			
		||||
 
 | 
			
		||||
@@ -5,5 +5,5 @@ namespace Syntriax.Engine.Systems.Tween;
 | 
			
		||||
public static class TweenVector2DExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenVector2D(this Vector2D initialVector2D, ITweenManager tweenManager, float duration, Vector2D targetVector2D, System.Action<Vector2D> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialVector2D.Lerp(targetVector2D, t)));
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.Invoke(initialVector2D.Lerp(targetVector2D, t)));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,5 +5,5 @@ namespace Syntriax.Engine.Systems.Tween;
 | 
			
		||||
public static class TweenVector3DExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static ITween TweenVector3D(this Vector3D initialVector3D, ITweenManager tweenManager, float duration, Vector3D targetVector3D, System.Action<Vector3D> setMethod)
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialVector3D.Lerp(targetVector3D, t)));
 | 
			
		||||
        => tweenManager.StartTween(duration, t => setMethod?.Invoke(initialVector3D.Lerp(targetVector3D, t)));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -26,14 +26,14 @@ internal class Tween : ITween
 | 
			
		||||
            _state = value;
 | 
			
		||||
            switch (value)
 | 
			
		||||
            {
 | 
			
		||||
                case TweenState.Completed: OnCompleted?.InvokeSafe(this); OnEnded?.InvokeSafe(this); break;
 | 
			
		||||
                case TweenState.Cancelled: OnCancelled?.InvokeSafe(this); OnEnded?.InvokeSafe(this); break;
 | 
			
		||||
                case TweenState.Paused: OnPaused?.InvokeSafe(this); break;
 | 
			
		||||
                case TweenState.Completed: OnCompleted?.Invoke(this); OnEnded?.Invoke(this); break;
 | 
			
		||||
                case TweenState.Cancelled: OnCancelled?.Invoke(this); OnEnded?.Invoke(this); break;
 | 
			
		||||
                case TweenState.Paused: OnPaused?.Invoke(this); break;
 | 
			
		||||
                case TweenState.Playing:
 | 
			
		||||
                    if (previousState == TweenState.Idle)
 | 
			
		||||
                        OnStarted?.InvokeSafe(this);
 | 
			
		||||
                        OnStarted?.Invoke(this);
 | 
			
		||||
                    else
 | 
			
		||||
                        OnResumed?.InvokeSafe(this);
 | 
			
		||||
                        OnResumed?.Invoke(this);
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -58,9 +58,9 @@ internal class Tween : ITween
 | 
			
		||||
 | 
			
		||||
            _counter = value.Min(Duration).Max(0f);
 | 
			
		||||
            Progress = Counter / Duration;
 | 
			
		||||
            OnUpdated?.InvokeSafe(this);
 | 
			
		||||
            OnUpdated?.Invoke(this);
 | 
			
		||||
 | 
			
		||||
            OnDeltaUpdated?.InvokeSafe(this, Easing.Evaluate(Progress) - Easing.Evaluate(previousProgress));
 | 
			
		||||
            OnDeltaUpdated?.Invoke(this, Easing.Evaluate(Progress) - Easing.Evaluate(previousProgress));
 | 
			
		||||
 | 
			
		||||
            if (_counter >= Duration)
 | 
			
		||||
                State = TweenState.Completed;
 | 
			
		||||
 
 | 
			
		||||
@@ -46,56 +46,56 @@ public static class TweenExtensions
 | 
			
		||||
    public static ITween OnStart(this ITween tween, Action callback)
 | 
			
		||||
    {
 | 
			
		||||
        Tween tweenConcrete = (Tween)tween;
 | 
			
		||||
        tweenConcrete.OnStarted += _ => callback.InvokeSafe();
 | 
			
		||||
        tweenConcrete.OnStarted += _ => callback.Invoke();
 | 
			
		||||
        return tween;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static ITween OnPause(this ITween tween, Action callback)
 | 
			
		||||
    {
 | 
			
		||||
        Tween tweenConcrete = (Tween)tween;
 | 
			
		||||
        tweenConcrete.OnPaused += _ => callback.InvokeSafe();
 | 
			
		||||
        tweenConcrete.OnPaused += _ => callback.Invoke();
 | 
			
		||||
        return tween;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static ITween OnResume(this ITween tween, Action callback)
 | 
			
		||||
    {
 | 
			
		||||
        Tween tweenConcrete = (Tween)tween;
 | 
			
		||||
        tweenConcrete.OnResumed += _ => callback.InvokeSafe();
 | 
			
		||||
        tweenConcrete.OnResumed += _ => callback.Invoke();
 | 
			
		||||
        return tween;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static ITween OnCancel(this ITween tween, Action callback)
 | 
			
		||||
    {
 | 
			
		||||
        Tween tweenConcrete = (Tween)tween;
 | 
			
		||||
        tweenConcrete.OnCancelled += _ => callback.InvokeSafe();
 | 
			
		||||
        tweenConcrete.OnCancelled += _ => callback.Invoke();
 | 
			
		||||
        return tween;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static ITween OnComplete(this ITween tween, Action callback)
 | 
			
		||||
    {
 | 
			
		||||
        Tween tweenConcrete = (Tween)tween;
 | 
			
		||||
        tweenConcrete.OnCompleted += _ => callback.InvokeSafe();
 | 
			
		||||
        tweenConcrete.OnCompleted += _ => callback.Invoke();
 | 
			
		||||
        return tween;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static ITween OnEnd(this ITween tween, Action callback)
 | 
			
		||||
    {
 | 
			
		||||
        Tween tweenConcrete = (Tween)tween;
 | 
			
		||||
        tweenConcrete.OnEnded += _ => callback.InvokeSafe();
 | 
			
		||||
        tweenConcrete.OnEnded += _ => callback.Invoke();
 | 
			
		||||
        return tween;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static ITween OnUpdate(this ITween tween, Action callback)
 | 
			
		||||
    {
 | 
			
		||||
        Tween tweenConcrete = (Tween)tween;
 | 
			
		||||
        tweenConcrete.OnUpdated += _ => callback.InvokeSafe();
 | 
			
		||||
        tweenConcrete.OnUpdated += _ => callback.Invoke();
 | 
			
		||||
        return tween;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static ITween OnDeltaUpdate(this ITween tween, Action<float> callback)
 | 
			
		||||
    {
 | 
			
		||||
        Tween tweenConcrete = (Tween)tween;
 | 
			
		||||
        tweenConcrete.OnDeltaUpdated += (_, delta) => callback.InvokeSafe(delta);
 | 
			
		||||
        tweenConcrete.OnDeltaUpdated += (_, delta) => callback.Invoke(delta);
 | 
			
		||||
        return tween;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ public class TweenManager : UniverseObject, ITweenManager
 | 
			
		||||
    public ITween StartTween(float duration, ITweenManager.TweenSetCallback? setCallback = null)
 | 
			
		||||
    {
 | 
			
		||||
        Tween tween = new(duration);
 | 
			
		||||
        tween.OnUpdated += tween => setCallback?.InvokeSafe(tween.Value);
 | 
			
		||||
        tween.OnUpdated += tween => setCallback?.Invoke(tween.Value);
 | 
			
		||||
        runningCoroutines.Add(tween, coroutineManager.StartCoroutine(RunTween(tween)));
 | 
			
		||||
        return tween;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user