Exemplo n.º 1
0
        private void SetupMainMenuScene()
        {
            // use seated mode during main menu
            TrackingSpace = ETrackingUniverseOrigin.TrackingUniverseSeated;

            // render KerbalVR objects on the default layer
            RenderLayer = 0;

            // generate list of cameras to render
            PopulateCameraList(MAINMENU_SCENE_CAMERAS);

            // cache the menu logic object
            mainMenuLogic = GameObject.FindObjectOfType <MainMenuEnvLogic>();
            mainMenuLogic.fadeEndDistance = 10f;

            // set inital scene position
            InitialPosition = Vector3.zero;
            InitialRotation = Quaternion.LookRotation(Vector3.forward, Vector3.up);

            // create a UI screen
            if (mainMenuUiScreen == null)
            {
                mainMenuUiScreen      = GameObject.CreatePrimitive(PrimitiveType.Quad);
                mainMenuUiScreen.name = "KVR_KSP_UI_Screen";
                mainMenuUiScreen.transform.position = CurrentPosition + new Vector3(0.4f, 0f, 0f);
                mainMenuUiScreen.transform.rotation = Quaternion.Euler(0f, 30f, 0f);
                Vector3 uiScreenScale = Vector3.one * 0.6f;
                uiScreenScale.x = uiScreenScale.y * (16f / 9f);
                mainMenuUiScreen.transform.localScale = uiScreenScale;
                MeshRenderer mr = mainMenuUiScreen.GetComponent <MeshRenderer>();
                mr.material             = new Material(Shader.Find("KSP/Alpha/Unlit Transparent"));
                mr.material.mainTexture = KerbalVR.Core.KspUiRenderTexture;
            }
        }
Exemplo n.º 2
0
        private void Awake()
        {
            if (!Templates.KopernicusMainMenu)
            {
                return;
            }

            // Get the MainMenu-Logic
            MainMenu main = FindObjectOfType <MainMenu>();

            if (main == null)
            {
                Debug.LogError("[Kopernicus] No main menu object!");
                return;
            }
            MainMenuEnvLogic logic = main.envLogic;

            // Set it to Space, because the Mun-Area won't work with sth else than Mun
            if (logic.areas.Length < 2)
            {
                Debug.LogError("[Kopernicus] Not enough scenes");
                return;
            }

            logic.areas[0].SetActive(false);
            logic.areas[1].SetActive(true);
        }
Exemplo n.º 3
0
        public static void PrintMainMenuInfo()
        {
            Log("=== MainMenuEnvLogic ===");

            MainMenuEnvLogic mainMenuLogic = GameObject.FindObjectOfType <MainMenuEnvLogic>();

            if (mainMenuLogic != null)
            {
                Log("GameObject position: " + mainMenuLogic.gameObject.transform.position);
                Log("landscapeCamera position: " + mainMenuLogic.landscapeCamera.gameObject.transform.position);
                Log("currentStage: " + mainMenuLogic.currentStage);

                Log("areas (" + mainMenuLogic.areas.Length + "):");
                foreach (GameObject area in mainMenuLogic.areas)
                {
                    PrintGameObject(area);
                }
                Log("startingArea:");
                PrintGameObject(mainMenuLogic.startingArea);

                Log("camPivots (" + mainMenuLogic.camPivots.Length + "):");
                foreach (MainMenuEnvLogic.MenuStage stage in mainMenuLogic.camPivots)
                {
                    Log("MenuStage initial = " + stage.initialPoint.position + ", target = " + stage.targetPoint.position);
                }
            }
            else
            {
                Log("No MainMenuEnvLogic component found.");
            }
        }
Exemplo n.º 4
0
        // Update the menu body
        void UpdateMenu()
        {
            // Grab the main body
            CelestialBody planetCB = PSystemManager.Instance.localBodies.Find(b => b.bodyName == Templates.menuBody);
            PSystemBody   planet   = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, Templates.menuBody);

            if (planetCB == null || planet == null)
            {
                planet   = Utility.FindHomeBody(PSystemManager.Instance.systemPrefab.rootBody);
                planetCB = PSystemManager.Instance.localBodies.Find(b => b.isHomeWorld);
            }
            if (planet == null || planetCB == null)
            {
                Debug.LogError("[Kopernicus]: Could not find homeworld!");
                return;
            }

            // Get the MainMenu-Logic
            MainMenu main = FindObjectOfType <MainMenu>();

            if (main == null)
            {
                Debug.LogError("[Kopernicus]: No main menu object!");
                return;
            }
            MainMenuEnvLogic logic = main.envLogic;

            // Set it to Space, because the Mun-Area won't work with sth else than Mun
            if (logic.areas.Length < 2)
            {
                Debug.LogError("[Kopernicus]: Not enough bodies");
                return;
            }
            logic.areas[0].SetActive(false);
            logic.areas[1].SetActive(true);

            // Get our active Space
            GameObject space = logic.areas[1];

            // Deactivate Kerbins Transform
            Transform kerbin = space.transform.Find("Kerbin");

            if (kerbin == null)
            {
                Debug.LogError("[Kopernicus]: No Kerbin transform!");
                return;
            }
            kerbin.gameObject.SetActive(false);

            // Deactivate Muns Transform
            Transform mun = space.transform.Find("MunPivot");

            if (mun == null)
            {
                Debug.LogError("[Kopernicus]: No MunPivot transform!");
                return;
            }
            mun.gameObject.SetActive(false);

            // Clone the scaledVersion and attach it to the Scene
            GameObject menuPlanet = Instantiate(planet.scaledVersion) as GameObject;

            menuPlanet.transform.parent = space.transform;

            // Destroy stuff
            DestroyImmediate(menuPlanet.GetComponent <ScaledSpaceFader>());
            DestroyImmediate(menuPlanet.GetComponent <SphereCollider>());
            DestroyImmediate(menuPlanet.GetComponentInChildren <AtmosphereFromGround>());
            DestroyImmediate(menuPlanet.GetComponent <MaterialSetDirection>());

            // That sounds funny
            Rotato planetRotato    = menuPlanet.AddComponent <Rotato>();
            Rotato planetRefRotato = kerbin.GetComponent <Rotato>();

            planetRotato.speed = (planetRefRotato.speed / 9284.50070356553f) * (float)planetCB.orbitDriver.orbit.orbitalSpeed; // calc.exe for the win

            // Scale the body
            menuPlanet.transform.localScale    = kerbin.localScale;
            menuPlanet.transform.localPosition = kerbin.localPosition;
            menuPlanet.transform.position      = kerbin.position;

            // And set it to layer 0
            menuPlanet.layer = 0;

            // Patch the material, because Mods like TextureReplacer run post spawn, and we'd overwrite their changes
            menuPlanet.GetComponent <Renderer>().sharedMaterial = planetCB.scaledBody.GetComponent <Renderer>().sharedMaterial;

            // Copy EVE 7.4 clouds / Rings
            for (int i = 0; i < planetCB.scaledBody.transform.childCount; i++)
            {
                // Just clone everything
                Transform  t    = planetCB.scaledBody.transform.GetChild(i);
                GameObject newT = Instantiate(t.gameObject) as GameObject;
                newT.transform.parent        = menuPlanet.transform;
                newT.layer                   = 0;
                newT.transform.localPosition = Vector3.zero;
                newT.transform.localRotation = Quaternion.identity;
                newT.transform.localScale    = (float)(1008 / planetCB.Radius) * Vector3.one;
            }

            // And now, create the moons
            foreach (PSystemBody moon in planet.children)
            {
                // Grab the CeletialBody of the moon
                CelestialBody moonCB = PSystemManager.Instance.localBodies.Find(b => b.GetTransform().name == moon.name);

                // Create the Rotation-Transforms
                GameObject menuMoonPivot = new GameObject(moon.name + " Pivot");
                menuMoonPivot.gameObject.layer   = 0;
                menuMoonPivot.transform.position = menuPlanet.transform.position;

                // Still funny...
                Rotato munRotato = menuMoonPivot.AddComponent <Rotato>();
                Rotato refRotato = mun.GetComponent <Rotato>();
                munRotato.speed = (refRotato.speed / 542.494239600754f) * (float)moonCB.GetOrbit().getOrbitalSpeedAtDistance(moonCB.GetOrbit().semiMajorAxis);

                // Clone the scaledVersion and attach it to the pivot
                GameObject menuMoon = Instantiate(moon.scaledVersion) as GameObject;
                menuMoon.transform.parent = menuMoonPivot.transform;

                // Move and scale the menuMoon correctly
                menuMoon.transform.localPosition = new Vector3(-5000f * (float)(moonCB.GetOrbit().semiMajorAxis / 12000000.0), 0f, 0f);
                menuMoon.transform.localScale   *= 7f;

                // Destroy stuff
                DestroyImmediate(menuMoon.GetComponent <ScaledSpaceFader>());
                DestroyImmediate(menuMoon.GetComponent <SphereCollider>());
                DestroyImmediate(menuMoon.GetComponentInChildren <AtmosphereFromGround>());
                DestroyImmediate(menuMoon.GetComponent <MaterialSetDirection>());

                // More Rotato
                Rotato moonRotato = menuMoon.AddComponent <Rotato>();
                moonRotato.speed = -0.005f / (float)(moonCB.rotationPeriod / 400.0);

                // Apply orbital stuff
                menuMoon.transform.Rotate(0f, (float)moonCB.orbitDriver.orbit.LAN, 0f);
                menuMoon.transform.Rotate(0f, 0f, (float)moonCB.orbitDriver.orbit.inclination);
                menuMoon.transform.Rotate(0f, (float)moonCB.orbitDriver.orbit.argumentOfPeriapsis, 0f);

                // And set the layer to 0
                menuMoon.layer = 0;

                // Patch the material, because Mods like TextureReplacer run post spawn, and we'd overwrite their changes
                menuMoon.GetComponent <Renderer>().sharedMaterial = moonCB.scaledBody.GetComponent <Renderer>().sharedMaterial;

                // Copy EVE 7.4 clouds / Rings
                for (int i = 0; i < moonCB.scaledBody.transform.childCount; i++)
                {
                    Transform  t    = moonCB.scaledBody.transform.GetChild(i);
                    GameObject newT = Instantiate(t.gameObject) as GameObject;
                    newT.transform.parent        = menuMoon.transform;
                    newT.layer                   = 0;
                    newT.transform.localPosition = Vector3.zero;
                    newT.transform.localRotation = Quaternion.identity;
                    newT.transform.localScale    = (float)(1008 / moonCB.Radius) * Vector3.one;
                }
            }
        }
Exemplo n.º 5
0
        // Update the menu body
        private void Start()
        {
            if (!Templates.KopernicusMainMenu)
            {
                return;
            }

            // Select a random body?
            if (Templates.RandomMainMenuBodies.Any())
            {
                Templates.MenuBody =
                    Templates.RandomMainMenuBodies[new Random().Next(0, Templates.RandomMainMenuBodies.Count)];
            }

            // Grab the main body
            CelestialBody planetCb = UBI.GetBody(Templates.MenuBody);

            if (planetCb == null)
            {
                planetCb = PSystemManager.Instance.localBodies.Find(b => b.isHomeWorld);
            }
            if (planetCb == null)
            {
                Debug.LogError("[Kopernicus] Could not find home world!");
                return;
            }

            // Load Textures
            OnDemandStorage.EnableBody(Templates.MenuBody);

            // Get the MainMenu-Logic
            MainMenu main = FindObjectOfType <MainMenu>();

            if (main == null)
            {
                Debug.LogError("[Kopernicus] No main menu object!");
                return;
            }
            MainMenuEnvLogic logic = main.envLogic;

            // Set it to Space, because the Mun-Area won't work with sth else than Mun
            if (logic.areas.Length < 2)
            {
                Debug.LogError("[Kopernicus] Not enough bodies");
                return;
            }

            // Get our active Space
            GameObject space = logic.areas[1];

            // Deactivate Kerbins Transform
            Transform kerbin = space.transform.Find("Kerbin");

            if (kerbin == null)
            {
                Debug.LogError("[Kopernicus] No Kerbin transform!");
                return;
            }
            kerbin.gameObject.SetActive(false);

            // Deactivate Muns Transform
            Transform munPivot = space.transform.Find("MunPivot");

            if (munPivot == null)
            {
                Debug.LogError("[Kopernicus] No MunPivot transform!");
                return;
            }
            munPivot.gameObject.SetActive(false);

            // Activate the textures
            ScaledSpaceOnDemand od = planetCb.scaledBody.GetComponentInChildren <ScaledSpaceOnDemand>();

            if (od != null)
            {
                od.Start();
                od.LoadTextures();
            }

            // Clone the scaledVersion and attach it to the Scene
            GameObject menuPlanet = Utility.Instantiate(Utility
                                                        .FindBody(PSystemManager.Instance.systemPrefab.rootBody, planetCb.transform.name).scaledVersion, space.transform, true);

            menuPlanet.name = planetCb.transform.name;

            // Destroy stuff
            DestroyImmediate(menuPlanet.GetComponent <ScaledSpaceFader>());
            DestroyImmediate(menuPlanet.GetComponent <SphereCollider>());
            DestroyImmediate(menuPlanet.GetComponentInChildren <AtmosphereFromGround>());
            DestroyImmediate(menuPlanet.GetComponent <MaterialSetDirection>());

            // That sounds funny
            Rotato planetRotato    = menuPlanet.AddComponent <Rotato>();
            Rotato planetRefRotato = kerbin.GetComponent <Rotato>();

            planetRotato.speed = planetRefRotato.speed * ((Single)planetCb.rotationPeriod / KERBIN_ROTATION_PERIOD);
            menuPlanet.transform.Rotate(0f, (Single)planetCb.initialRotation, 0f);

            // Scale the body
            menuPlanet.transform.localScale    = kerbin.localScale;
            menuPlanet.transform.localPosition = kerbin.localPosition;
            menuPlanet.transform.position      = kerbin.position;

            // And set it to layer 0
            menuPlanet.layer = 0;

            Events.OnRuntimeUtilityUpdateMenu.Fire();
        }