示例#1
0
        public IndexedResource <T> CacheObjectIfNotExists <T, U>(Key key, U obj, Dictionary <Key, IndexedResource <T> > dic, Gerenator <T, U> generator)
        {
            IndexedResource <T> res;

            var preCond = true;

            if (key is string)
            {
                preCond = !string.IsNullOrEmpty(key as string);
            }
            else
            {
                preCond = key != null;
            }

            if (preCond && dic.TryGetValue(key, out res))
            {
                return(res);
            }

            res = generator(obj);
            if (preCond)
            {
                dic.Add(key, res);
            }

            return(res);
        }
示例#2
0
        public IndexedResource <Transform> CacheObjectIfNotExists(Transform obj, Dictionary <object, IndexedResource <Transform> > dic, Gerenator <Transform, Transform> generator)
        {
            IndexedResource <Transform> res;

            // Cached by reference
            if (dic.TryGetValue(obj, out res))
            {
                return(res);
            }

            res = generator(obj);
            dic.Add(obj, res);

            return(res);
        }