示例#1
0
        public static void Return([NotNull] CachedComponentResolver resolver)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            resolver.Clear();
            if (FreeResolversSet.Contains(resolver))
            {
                return;
            }

            FreeResolvers.Add(resolver);
            FreeResolversSet.Add(resolver);
        }
示例#2
0
        public static CachedComponentResolver Rent([NotNull] GameObject gameObject,
                                                   DependencySource dependencySource)
        {
            if (gameObject == null)
            {
                throw new ArgumentNullException(nameof(gameObject));
            }

            if (FreeResolvers.Count == 0)
            {
                return(new CachedComponentResolver(gameObject, dependencySource));
            }

            var lastIndex = FreeResolvers.Count - 1;
            var resolver  = FreeResolvers[lastIndex];

            FreeResolvers.RemoveAt(lastIndex);
            FreeResolversSet.Remove(resolver);
            resolver.Clear();
            resolver.GameObject       = gameObject;
            resolver.DependencySource = dependencySource;
            return(resolver);
        }