Exemple #1
0
        /************************************************************************************************************************/

        /// <summary>
        /// Calls <see cref="ObjectPool{T}.Acquire"/> to get a spare <see cref="HashSet{T}"/> if
        /// there are any or create a new one.
        /// </summary>
        public static HashSet <T> AcquireSet <T>()
        {
            var set = ObjectPool <HashSet <T> > .Acquire();

            Debug.Assert(set.Count == 0, "A pooled set is not empty." + NotClearError);
            return(set);
        }
Exemple #2
0
        /************************************************************************************************************************/

        /// <summary>
        /// Calls <see cref="ObjectPool{T}.Acquire"/> to get a spare <see cref="StringBuilder"/> if
        /// there are any or create a new one.
        /// </summary>
        public static StringBuilder AcquireStringBuilder()
        {
            var builder = ObjectPool <StringBuilder> .Acquire();

            Debug.Assert(builder.Length == 0, $"A pooled {nameof(StringBuilder)} is not empty." + NotClearError);
            return(builder);
        }
Exemple #3
0
        /************************************************************************************************************************/

        /// <summary>
        /// Calls <see cref="ObjectPool{T}.Acquire"/> to get a spare <see cref="List{T}"/> if
        /// there are any or create a new one.
        /// </summary>
        public static List <T> AcquireList <T>()
        {
            var list = ObjectPool <List <T> > .Acquire();

            Debug.Assert(list.Count == 0, "A pooled list is not empty." + NotClearError);
            return(list);
        }
Exemple #4
0
        /************************************************************************************************************************/

        /// <summary>
        /// Calls <see cref="ObjectPool{T}.Acquire"/> to get a spare <see cref="HashSet{T}"/> if
        /// there are any or create a new one.
        /// </summary>
        public static HashSet <T> AcquireSet <T>()
        {
            var set = ObjectPool <HashSet <T> > .Acquire();

            Debug.Assert(set.Count == 0,
                         "A pooled collection is not empty. Collections must not be modified after being released to the pool.");
            return(set);
        }
Exemple #5
0
        /************************************************************************************************************************/

        /// <summary>
        /// Calls <see cref="ObjectPool{T}.Acquire"/> to get a spare <see cref="List{T}"/> if
        /// there are any or create a new one.
        /// </summary>
        public static List <T> AcquireList <T>()
        {
            var list = ObjectPool <List <T> > .Acquire();

            Debug.Assert(list.Count == 0,
                         "A pooled collection is not empty. Collections must not be modified after being released to the pool.");
            return(list);
        }
Exemple #6
0
        /************************************************************************************************************************/

        /// <summary>
        /// Registers the `callback` to be triggered when the <see cref="AnimancerNode.EffectiveWeight"/> becomes 0.
        /// </summary>
        /// <remarks>
        /// The <see cref="AnimancerNode.EffectiveWeight"/> is only checked at the end of the animation update so if it
        /// is set to 0 then back to a higher number before the next update, the callback will not be triggered.
        /// </remarks>
        public static void Register(AnimancerNode node, Action callback)
        {
#if UNITY_ASSERTIONS
            AnimancerUtilities.Assert(node != null, "Node is null.");
            AnimancerUtilities.Assert(node.IsValid, "Node is not valid.");
#endif

            var exit = ObjectPool.Acquire <ExitEvent>();
            exit._Callback = callback;
            exit._Node     = node;
            node.Root.RequirePostUpdate(exit);
        }
Exemple #7
0
            /************************************************************************************************************************/

            public static Curve Acquire(AnimationCurve curve)
            {
                if (curve == null)
                {
                    OptionalWarning.CustomFadeNotNull.Log($"{nameof(curve)} is null.");
                    return(null);
                }

                var fade = ObjectPool <Curve> .Acquire();

                fade._Curve = curve;
                return(fade);
            }
Exemple #8
0
            /************************************************************************************************************************/

            public static Delegate Acquire(Func <float, float> calculateWeight)
            {
                if (calculateWeight == null)
                {
                    OptionalWarning.CustomFadeNotNull.Log($"{nameof(calculateWeight)} is null.");
                    return(null);
                }

                var fade = ObjectPool <Delegate> .Acquire();

                fade._CalculateWeight = calculateWeight;
                return(fade);
            }
            /************************************************************************************************************************/
            #region Pooling
            /************************************************************************************************************************/

            /// <summary>
            /// If the `state` has no <see cref="EventUpdatable"/>, this method gets one from the
            /// <see cref="ObjectPool"/>.
            /// </summary>
            public static void Acquire(AnimancerState state)
            {
                var updatable = state._EventUpdatable;

                if (updatable != null)
                {
                    return;
                }

                ObjectPool.Acquire(out updatable);

#if UNITY_ASSERTIONS
                if (updatable._State != null)
                {
                    Debug.LogError(updatable + " already has a state even though it was in the list of spares.");
                }

                if (updatable._Events != null)
                {
                    Debug.LogError(updatable + " has event sequence even though it was in the list of spares.");
                }

                if (updatable._GotEventsFromPool)
                {
                    Debug.LogError(updatable + " is marked as having pooled events even though it has no events.");
                }

                if (updatable._NextEventIndex != RecalculateEventIndex)
                {
                    Debug.LogError(updatable + " has a _NextEventIndex even though it was pooled.");
                }

                if (IsInList(updatable))
                {
                    Debug.LogError(updatable + " is currently in a Keyed List even though it was in the list of spares.");
                }
#endif

                updatable._IsLooping  = state.IsLooping;
                updatable._State      = state;
                state._EventUpdatable = updatable;
                state.Root.RequireUpdate(updatable);
            }
Exemple #10
0
 /// <summary>
 /// Calls <see cref="ObjectPool{T}.Acquire"/> to get a spare item if there are any, or create a new one.
 /// </summary>
 public static void Acquire <T>(out T item)
     where T : class, new()
 => item = ObjectPool <T> .Acquire();
Exemple #11
0
        /************************************************************************************************************************/

        /// <summary>
        /// Calls <see cref="ObjectPool{T}.Acquire"/> to get a spare item if there are any, or create a new one.
        /// </summary>
        public static T Acquire <T>()
            where T : class, new()
        => ObjectPool <T> .Acquire();
Exemple #12
0
        /************************************************************************************************************************/

        /// <summary>
        /// Calls <see cref="ObjectPool{T}.Acquire"/> to get a spare item if there are any, or create a new one.
        /// </summary>
        public static T Acquire <T>() where T : class, new()
        {
            return(ObjectPool <T> .Acquire());
        }