コード例 #1
0
        /// <summary>
        /// Creates a content manager that creates OpenGL object instances, like textures
        /// </summary>
        /// <param name="resourceAssembly">The assembly that contains the resources.</param>
        /// <param name="solutionMode">Should shaders be built with solution on or off</param>
        /// <returns>A content manager instance</returns>
        public static FileContentManager Create(Assembly resourceAssembly, bool solutionMode)
        {
            var streamLoaderCollection = new NamedStreamLoaderCollection();

            //streamLoaderCollection.Add(new NamedFileStreamLoader()); //load arbitrary files TODO: file name resolution
            streamLoaderCollection.Add(new NamedResourceStreamLoader(resourceAssembly));
            streamLoaderCollection.Add(new NamedResourceStreamLoader(Assembly.GetExecutingAssembly()));             //Zenseless.OpenGL resources

            var mgr = new FileContentManager(streamLoaderCollection);

            mgr.RegisterImporter((res) => ContentImporters.StringBuilder(res).ToString());
            mgr.RegisterImporter(ContentImporters.StringBuilder);
            mgr.RegisterImporter <Stream>((it) =>
            {
                var input = it.First().Stream;
                var s     = new MemoryStream();
                it.First().Stream.CopyTo(s);
                s.Position = 0;
                return(s);
            }
                                          );
            mgr.RegisterUpdater <StringBuilder>(ContentImporters.Update);
            mgr.RegisterImporter(ContentImporters.ByteBuffer);
            mgr.RegisterImporter(ContentImporters.DefaultMesh);
            mgr.RegisterImporter(BitmapImporter);
            mgr.RegisterUpdater <Texture2dGL>(Update);
            mgr.RegisterImporter(TextureArrayImporter);
            mgr.RegisterUpdater <TextureArray2dGL>(Update);
            mgr.RegisterImporter((namedStreams) => ShaderProgramImporter(namedStreams, solutionMode, mgr));
            mgr.RegisterUpdater <ShaderProgramGL>((prog, namedStreams) => Update(prog, namedStreams, solutionMode, mgr));
            return(mgr);
        }
コード例 #2
0
        private static IImporter FindImporter(string importerName, string fileName)
        {
            if (!string.IsNullOrEmpty(importerName))
            {
                return(PipelineBuilder.ContentImporters.FirstOrDefault(i => i.GetType().Name == importerName));
            }

            return(ContentImporters.FirstOrDefault(i => ImporterCompatibleWithFile(i, fileName)));
        }
コード例 #3
0
        private static void FindImportersProcessorAndContentWriters(Assembly assembly)
        {
            if (assembly.FullName.StartsWith("System") ||
                assembly.FullName.StartsWith("mscorlib") ||
                (assembly.FullName.StartsWith("Microsoft.") && !assembly.FullName.StartsWith("Microsoft.Xna.Framework.Content.Pipeline")))
            {
                return;
            }

            foreach (var type in assembly.GetTypes())
            {
                try
                {
                    if (typeof(IImporter).IsAssignableFrom(type) &&
                        type.GetCustomAttributes(typeof(ContentImporterAttribute), false).Any() &&
                        !ContentImporters.Any(i => i.GetType() == type))
                    {
                        ContentImporters.Add((IImporter)Activator.CreateInstance(type));
                    }
                    if (typeof(IProcessor).IsAssignableFrom(type) &&
                        type.GetCustomAttributes(typeof(ContentProcessorAttribute), false).Any() &&
                        !ContentProcessors.Any(i => i.GetType() == type))
                    {
                        ContentProcessors.Add((IProcessor)Activator.CreateInstance(type));
                    }
                    if (typeof(ContentTypeWriter).IsAssignableFrom(type) &&
                        type.GetCustomAttributes(typeof(ContentTypeWriterAttribute), false).Any() &&
                        !ContentWriters.Any(i => i.GetType() == type) && !type.IsGenericTypeDefinition)
                    {
                        ContentWriters.Add((ContentTypeWriter)Activator.CreateInstance(type));
                    }
                }
                catch (Exception e)
                {
                    Trace.TraceWarning("Error load type {0} from assembly {1}", type.AssemblyQualifiedName, assembly.FullName);
                    Trace.WriteLine(e.ToString());
                }
            }
        }