Ejemplo n.º 1
0
        /// <summary>
        /// Loads Shader class from path and unity3d asset bundle
        /// </summary>
        /// <param name="path"></param>
        /// <param name="shaderName"></param>
        /// <returns></returns>
        public static Shader OpenShaderFromDisk(ShaderManager.ConfigShader shader)
        {
            Shader s = null;

            try
            {
                using (WWW www = new WWW("file://" + shader.diskPath))
                {
                    AssetBundle b = www.assetBundle;

                    s = b.LoadAsset <Shader>(shader.name);

                    if (s == null)
                    {
                        Logging.Error("Shader [" + shader.name + "] is not existing or path is incorrect. Please take in note that the unity3d file has been found.");
                    }

                    b.Unload(false);
                }
            }
            catch (Exception e)
            {
                Logging.Error("unity3d file [" + shader.path + "] is not existing or path is incorrect." + Environment.NewLine + e);
            }

            return(s);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Apply a shader to a body
        /// </summary>
        /// <param name="shader"></param>
        /// <param name="body"></param>
        private static void ApplyToBody(ShaderManager.ConfigShader configShader, object body)
        {
            if (body != null)
            {
                Type t = body.GetType();
                Body b = new Body();

                if (t == typeof(Body))
                {
                    b = (Body)body;
                }

                else if (t == typeof(CelestialBody))
                {
                    b = new Body((CelestialBody)body);
                }

                else if (t == typeof(String))
                {
                    if (FlightGlobals.Bodies != null)
                    {
                        bool found = false;

                        foreach (CelestialBody cb in FlightGlobals.Bodies)
                        {
                            if (cb.name == (string)body)
                            {
                                b = new Body(cb);

                                found = true;
                            }
                        }

                        if (!found)
                        {
                            Logging.Warning(UTA(configShader) + ": Body \"" + (string)body + "\" was not found!");

                            return;
                        }
                    }

                    else
                    {
                        Logging.Warning(UTA(configShader) + ": FlightGlobals.Bodies is null!");
                    }
                }

                else
                {
                    Logging.Warning(UTA(configShader) + ": Object is not recognized as a body (its type must be CelestialBody, Kopernicus.Configuration.Body or String");

                    return;
                }

                b.scaledVersion.material.shader = configShader.shader;

                ParseSettings(b.scaledVersion.material, configShader);
            }
        }
Ejemplo n.º 3
0
        public static void Apply(ShaderManager.ConfigShader shader)
        {
            if (shader.gameObjectIsCelestialBody)
            {
                ApplyToBody(shader, shader.gameObject);
            }

            else
            {
                ApplyToAllGameObjects(shader, shader.gameObject);
            }
        }
Ejemplo n.º 4
0
        public static void ApplyToAllGameObjects(ShaderManager.ConfigShader shader, string gameObject)
        {
            foreach (GameObject go in Resources.FindObjectsOfTypeAll <GameObject>().Where(obj => obj.name == gameObject))
            {
                MeshRenderer mr = go.GetComponent <MeshRenderer>();

                if (mr == null)
                {
                    continue;
                }

                foreach (Material m in mr.materials)
                {
                    m.shader = shader.shader;
                    ParseSettings(m, shader);
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// UTA: Unable To Apply - Returns the default message of apply error
 /// </summary>
 private static string UTA(ShaderManager.ConfigShader shader)
 {
     return("Unable to apply shader " + shader.name + " to body");
 }
Ejemplo n.º 6
0
 public static bool ParseSettings(Material m, ShaderManager.ConfigShader shader)
 {
     return(ParseSettings(m, shader.settings));
 }