Exemplo n.º 1
0
            public static void Reset(this GalaxyCubeControl skybox)
            {
                Debug.Log("DefaultSkyBox.Reset", "GalaxyCubeControl = " + skybox);
                KSCTriggers.skip = false;

                if (skybox != null)
                {
                    // Rotation
                    if (initRot == null)
                    {
                        initRot = skybox.initRot;
                        Debug.Log("DefaultSkyBox.Reset", "Saved initRot = " + initRot);
                    }
                    else
                    {
                        skybox.initRot = (QuaternionD)initRot;
                        Debug.Log("DefaultSkyBox.Reset", "Loaded initRot = " + skybox.initRot);
                    }

                    // Scale
                    GameObject cube = skybox.gameObject.GetChild("GalaxyCube");
                    if (cube != null)
                    {
                        if (initScale == null)
                        {
                            initScale = cube.transform.localScale;
                            Debug.Log("DefaultSkyBox.Reset", "Saved initScale = " + initScale);
                        }
                        else
                        {
                            cube.transform.localScale = (Vector3)initScale;
                            Debug.Log("DefaultSkyBox.Reset", "Loaded initScale = " + cube.transform.localScale);
                        }
                    }

                    // Textures
                    Renderer[] renderers = skybox?.gameObject?.GetComponentsInChildren <Renderer>(true);

                    for (int i = 0; i < renderers?.Length; i++)
                    {
                        string   name     = renderers[i]?.name;
                        Material material = renderers[i]?.material;
                        if (material == null)
                        {
                            continue;
                        }

                        if (name == "XP")
                        {
                            if (XP == null)
                            {
                                XP = material.mainTexture;
                                Debug.Log("DefaultSkyBox.Reset", "Saved Stock XP texture = " + XP);
                            }
                            else
                            {
                                material.mainTexture = XP;
                                Debug.Log("DefaultSkyBox.Reset", "Loaded Stock XP texture = " + material.mainTexture);
                            }
                        }

                        else

                        if (name == "XN")
                        {
                            if (XN == null)
                            {
                                XN = material.mainTexture;
                                Debug.Log("DefaultSkyBox.Reset", "Saved Stock XN texture = " + XN);
                            }
                            else
                            {
                                material.mainTexture = XN;
                                Debug.Log("DefaultSkyBox.Reset", "Loaded Stock XN texture = " + material.mainTexture);
                            }
                        }

                        else

                        if (name == "YP")
                        {
                            if (YP == null)
                            {
                                YP = material.mainTexture;
                                Debug.Log("DefaultSkyBox.Reset", "Saved Stock YP texture = " + YP);
                            }
                            else
                            {
                                material.mainTexture = YP;
                                Debug.Log("DefaultSkyBox.Reset", "Loaded Stock YP texture = " + material.mainTexture);
                            }
                        }

                        else

                        if (name == "YN")
                        {
                            if (YN == null)
                            {
                                YN = material.mainTexture;
                                Debug.Log("DefaultSkyBox.Reset", "Saved Stock YN texture = " + YN);
                            }
                            else
                            {
                                material.mainTexture = YN;
                                Debug.Log("DefaultSkyBox.Reset", "Loaded Stock YN texture = " + material.mainTexture);
                            }
                        }

                        else

                        if (name == "ZP")
                        {
                            if (ZP == null)
                            {
                                ZP = material.mainTexture;
                                Debug.Log("DefaultSkyBox.Reset", "Saved Stock ZP texture = " + ZP);
                            }
                            else
                            {
                                material.mainTexture = ZP;
                                Debug.Log("DefaultSkyBox.Reset", "Loaded Stock ZP texture = " + material.mainTexture);
                            }
                        }

                        else

                        if (name == "ZN")
                        {
                            if (ZN == null)
                            {
                                ZN = material.mainTexture;
                                Debug.Log("DefaultSkyBox.Reset", "Saved Stock ZN texture = " + ZN);
                            }
                            else
                            {
                                material.mainTexture = ZN;
                                Debug.Log("DefaultSkyBox.Reset", "Loaded Stock ZN texture = " + material.mainTexture);
                            }
                        }
                    }
                }
            }
Exemplo n.º 2
0
            internal void ApplyTo(GameObject skybox)
            {
                Debug.Log("CustomSkyBox.ApplyTo", "Applying to skybox = " + skybox);
                if (skybox == null)
                {
                    return;
                }

                // Set Textures
                Renderer[] renderers = skybox?.GetComponentsInChildren <Renderer>();

                for (int i = 0; i < renderers?.Length; i++)
                {
                    Debug.Log("CustomSkyBox.ApplyTo", "Renderer = " + renderers[i]);
                    string   name     = renderers[i]?.name;
                    Material material = renderers[i]?.material;

                    if (material == null)
                    {
                        continue;
                    }

                    // Select Texture
                    if (SkyBox != null)
                    {
                        Debug.Log("CustomSkyBox.ApplyTo", "Old Texture = " + material.mainTexture);

                        if (name == "XP")
                        {
                            material.SetTexture(SkyBox[0]);
                        }
                        else if (name == "XN")
                        {
                            material.SetTexture(SkyBox[1]);
                        }
                        else if (name == "YP") // SQUAD inverts YP with YN
                        {
                            material.SetTexture(SkyBox[3]);
                        }
                        else if (name == "YN") // SQUAD inverts YN with YP
                        {
                            material.SetTexture(SkyBox[2]);
                        }
                        else if (name == "ZP")
                        {
                            material.SetTexture(SkyBox[4]);
                        }
                        else if (name == "ZN")
                        {
                            material.SetTexture(SkyBox[5]);
                        }

                        Debug.Log("CustomSkyBox.ApplyTo", "New Texture = " + material.mainTexture);
                    }
                }


                // Mirror CubeMap
                if (mirror == true)
                {
                    Debug.Log("CustomSkyBox.ApplyTo", "Mirroring SkyBox Texture");

                    GameObject cube = skybox.GetChild("GalaxyCube");
                    if (cube != null)
                    {
                        cube.transform.localScale *= -1;
                    }
                    else
                    {
                        skybox.transform.localScale *= -1;
                    }

                    GalaxyCubeControl control = skybox.GetComponent <GalaxyCubeControl>();
                    if (control != null)
                    {
                        control.initRot = Quaternion.AngleAxis(180, Vector3.forward);
                    }
                    else
                    {
                        skybox.transform.Rotate(cube.transform.forward, 180);
                    }
                }


                // Rotate CubeMap
                if (rotate == true)
                {
                    Debug.Log("CustomSkyBox.ApplyTo", "Rotating SkyBox Transform");

                    string hash = "";
                    if (HighLogic.LoadedScene == GameScenes.SPACECENTER && HighLogic.CurrentGame != null)
                    {
                        hash += HighLogic.CurrentGame.Seed;
                    }
                    else
                    {
                        hash += DateTime.Today;
                    }

                    int x = hash.GetHashCode();
                    hash = x.ToString();
                    int y = hash.GetHashCode();
                    hash = y.ToString();
                    int z = hash.GetHashCode();
                    hash = z.ToString();

                    Debug.Log("CustomSkyBox.ApplyTo", "Rotatation = {" + (x % 360) + "°, " + (y % 360) + "°, " + (z % 360) + "°}");

                    GalaxyCubeControl cube = skybox.GetComponent <GalaxyCubeControl>();
                    if (cube != null)
                    {
                        cube.initRot = Quaternion.Euler(x % 360, y % 360, z % 360);
                    }
                    else
                    {
                        skybox.transform.rotation = Quaternion.Euler(x % 360, y % 360, z % 360);
                    }
                }
            }