Compare commits
	
		
			1 Commits
		
	
	
		
			bb6990a80c
			...
			c03d74dbe0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c03d74dbe0 | 
@@ -63,17 +63,23 @@ public interface IBehaviourController : IAssignableGameObject
 | 
			
		||||
    /// </returns>
 | 
			
		||||
    bool TryGetBehaviour<T>([NotNullWhen(returnValue: true)] out T? behaviour);
 | 
			
		||||
 | 
			
		||||
    /// <typeparam name="T">An implemented class or <see cref="interface"/> of <see cref="IBehaviour"/></typeparam>
 | 
			
		||||
    /// <typeparam name="T">An implemented class or <see cref="interface"/>.</typeparam>
 | 
			
		||||
    /// <returns>Returns a list of all the matching <see cref="IBehaviour"/>s found in the <see cref="IBehaviourController"/>.</returns>
 | 
			
		||||
    IList<T> GetBehaviours<T>() where T : IBehaviour;
 | 
			
		||||
    IList<T> GetBehaviours<T>();
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Removes the <see cref="IBehaviour"/> found in the <see cref="IBehaviourController"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="removeAll">If all of the instances of the given Type is to be removed or not.</param>
 | 
			
		||||
    /// <typeparam name="T">An implemented class or <see cref="interface"/> of <see cref="IBehaviour"/></typeparam>
 | 
			
		||||
    void RemoveBehaviour<T>(bool removeAll = false) where T : IBehaviour;
 | 
			
		||||
    void RemoveBehaviour<T>(bool removeAll = false) where T : class, IBehaviour;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Removes the <see cref="IBehaviour"/> found in the <see cref="IBehaviourController"/>.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="removeAll">If all of the instances of the given Type is to be removed or not.</param>
 | 
			
		||||
    /// <typeparam name="T">An implemented class or <see cref="interface"/> of <see cref="IBehaviour"/></typeparam>
 | 
			
		||||
    void RemoveBehaviour<T>(T behaviour) where T : class, IBehaviour;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// To be called in every frame of the engine. Responsible for notifying <see cref="IBehaviour"/>'s under the <see cref="IBehaviourController"/>'s control that a new frame is happening.
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ public class BehaviourController : IBehaviourController
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public IList<T> GetBehaviours<T>() where T : IBehaviour
 | 
			
		||||
    public IList<T> GetBehaviours<T>()
 | 
			
		||||
    {
 | 
			
		||||
        IList<T> behaviours = new List<T>();
 | 
			
		||||
        foreach (var behaviourItem in this.behaviours)
 | 
			
		||||
@@ -70,23 +70,31 @@ public class BehaviourController : IBehaviourController
 | 
			
		||||
        return behaviours;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void RemoveBehaviour<T>(bool removeAll = false) where T : IBehaviour
 | 
			
		||||
    public void RemoveBehaviour<T>(bool removeAll = false) where T : class, IBehaviour
 | 
			
		||||
    {
 | 
			
		||||
        for (int i = behaviours.Count; i >= 0; i--)
 | 
			
		||||
        {
 | 
			
		||||
            if (behaviours[i] is not T behaviour)
 | 
			
		||||
                continue;
 | 
			
		||||
 | 
			
		||||
            behaviour.OnPriorityChanged -= OnPriorityChange;
 | 
			
		||||
            behaviour.Finalize();
 | 
			
		||||
            behaviours.RemoveAt(i);
 | 
			
		||||
            OnBehaviourRemoved?.Invoke(this, behaviour);
 | 
			
		||||
            RemoveBehaviour(behaviour);
 | 
			
		||||
 | 
			
		||||
            if (!removeAll)
 | 
			
		||||
                return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void RemoveBehaviour<T>(T behaviour) where T : class, IBehaviour
 | 
			
		||||
    {
 | 
			
		||||
        if (!behaviours.Contains(behaviour))
 | 
			
		||||
            throw new Exception($"{behaviour.GetType().Name} does not exist in {GameObject.Name}'s {nameof(IBehaviourController)}.");
 | 
			
		||||
 | 
			
		||||
        behaviour.OnPriorityChanged -= OnPriorityChange;
 | 
			
		||||
        behaviour.Finalize();
 | 
			
		||||
        behaviours.Remove(behaviour);
 | 
			
		||||
        OnBehaviourRemoved?.Invoke(this, behaviour);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public bool Assign(IGameObject gameObject)
 | 
			
		||||
    {
 | 
			
		||||
        if (GameObject is not null && GameObject.Initialized)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user