示例#1
0
        public T Load <T>(string name) where T : GraphicsResource
        {
            var key = GetContentKey(typeof(T), name);

            GraphicsResource res;

            if (m_pool.TryGetValue(key, out res))
            {
                return((T)res);
            }

            var path = GetContentPath(name);

            if (typeof(T) == typeof(Texture2D))
            {
                res = Texture2D.Load(this.GraphicsDevice, path);
            }
            else if (typeof(T) == typeof(Effect))
            {
                var effectData = EffectData.Load(path);

                res = (GraphicsResource)Activator.CreateInstance(typeof(T), this.GraphicsDevice, effectData, null);
            }
            else if (typeof(T).IsSubclassOf(typeof(Effect)))
            {
                var effectData = EffectData.Load(path);

                res = (GraphicsResource)Activator.CreateInstance(typeof(T), this.GraphicsDevice, effectData);
            }
            else
            {
                throw new NotImplementedException();
            }

            res = ToDispose(res);

            m_pool.Add(key, res);

            return((T)res);
        }