Exemplo n.º 1
0
        public SkyLight CreateSkyLight(Dictionary <string, Texture> textures)
        {
            var        assembly     = typeof(SkyLight).Assembly;
            var        types        = assembly.GetTypes();
            MethodInfo createMethod = null;

            for (int i = 0; i < types.Length; i++)
            {
                if (types[i].IsAbstract || !types[i].IsSubclassOf(typeof(SkyLight)))
                {
                    continue;
                }
                var attributes = types[i].GetCustomAttributes(typeof(SkyLightTypeAttribute), true);
                if (attributes != null && attributes.Length > 0)
                {
                    var shaderAttribute = attributes[0] as SkyLightTypeAttribute;
                    if (shaderAttribute != null && shaderAttribute.skyLightType == shaderType)
                    {
                        var method = types[i].GetMethod("Create", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                        if (method != null)
                        {
                            createMethod = method;
                            break;
                        }
                    }
                }
            }

            if (createMethod == null)
            {
                return(null);
            }
            SkyLight sky = createMethod.Invoke(null, new object[] { }) as SkyLight;

            if (sky == null)
            {
                return(null);
            }

            if (shaderParams != null)
            {
                for (int i = 0; i < shaderParams.Count; i++)
                {
                    SceneSerialization.SetParameterToObject(sky, shaderParams[i].paramName, shaderParams[i].paramValue, textures);
                }
            }

            Log.Info($"天空盒创建成功:{sky.GetType()}");


            return(sky);
        }