Exemple #1
0
    // Use this for initialization


    void Start()
    {
        speed  = 10f;
        player = GameObject.Find("Player");
        Rotato rotato = player.GetComponent <Rotato> ();

        position           = transform.position;
        transform.rotation = Quaternion.Euler(0, 0, rotato.target);

        //Handles which direction the bullet should fly
        if (rotato.target == -90f)
        {
            velocity = new Vector2(position.x + speed * Time.deltaTime, position.y);
        }
        else if (rotato.target == -180f)
        {
            velocity = new Vector2(position.x, position.y - speed * Time.deltaTime);
        }
        else if (rotato.target == -270f)
        {
            velocity = new Vector2(position.x - speed * Time.deltaTime, position.y);
        }
        else if (rotato.target == 0)
        {
            velocity = new Vector2(position.x, position.y + speed * Time.deltaTime);
        }
    }
Exemple #2
0
    void resetT()
    {
        Rotato rotato            = player.GetComponent <Rotato> ();
        string previousDirection = direction;

        if (rotato.target == -90f)
        {
            direction = "Right";
        }
        else if (rotato.target == -270f)
        {
            direction = "Left";
        }
        else if (rotato.target == 0)
        {
            direction = "Up";
        }
        else if (rotato.target == -180)
        {
            direction = "Down";
        }
        if (previousDirection != direction)
        {
            t = 0;
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        Rotato rotato = player.GetComponent <Rotato> ();

        if (rotato.target == -90f)
        {
            t += Time.deltaTime;
            boxCollider.size   = Vector2.Lerp(upDown, leftRight, growSpeed * t);
            boxCollider.offset = Vector2.Lerp(startOffset, targetOffset, growSpeed * t);
        }
        else if (rotato.target == -270f)
        {
            t += Time.deltaTime;
            boxCollider.size   = Vector2.Lerp(upDown, leftRight, growSpeed * t);
            boxCollider.offset = Vector2.Lerp(startOffset, targetOffset, growSpeed * t);
        }
        else if (rotato.target == 0)
        {
            boxCollider.size   = upDown;
            boxCollider.offset = startOffset;
        }
        else if (rotato.target == -180)
        {
            boxCollider.size   = upDown;
            boxCollider.offset = startOffset;
        }
        resetT();
    }
Exemple #4
0
            // Apply MenuObject to GameObject
            internal void ApplyTo(GameObject obj, float scaleMult = 1)
            {
                if (obj == null)
                {
                    return;
                }
                if (debug)
                {
                    obj.AddOrGetComponent <LiveDebug>();
                }

                // Edit Position/Rotation/Scale
                obj.transform.position = position ?? obj.transform.position;
                obj.transform.rotation = rotation ?? obj.transform.rotation;
                if (scale != null)
                {
                    obj.transform.localScale = (Vector3)scale * scaleMult;
                }

                // Adjust Scale by Distance
                if (adjustScale)
                {
                    obj.transform.transform.localScale *= (0.25f + (new Vector3(0.7814472f, -0.7841411f, 2.28511f) - obj.transform.transform.position).magnitude / 100);
                }


                // Edit Appearances
                MeshFilter meshFilter = obj.transform.GetComponent <MeshFilter>();

                if (meshFilter != null)
                {
                    meshFilter.mesh = mesh ?? meshFilter.mesh;
                }

                Renderer renderer = obj.transform.GetComponent <Renderer>();

                if (renderer != null)
                {
                    renderer.material        = material ?? renderer.material;
                    renderer.material.shader = shader ?? renderer.material.shader;

                    renderer.material.SetTexture(texture1);
                    renderer.material.SetColor(color1);
                    renderer.material.SetNormal(normal1);
                }


                // Rotato
                if (rotatoSpeed != null)
                {
                    Rotato rotato = obj.AddOrGetComponent <Rotato>();
                    rotato.speed = (float)rotatoSpeed;
                }


                // Pivot
                if (!string.IsNullOrEmpty(pivotAround))
                {
                    GameObject scene = obj;

                    while (scene != null && scene.name != "OrbitScene" && scene.name != "MunScene")
                    {
                        scene = scene?.transform?.parent?.gameObject;
                    }

                    if (scene == null)
                    {
                        return;
                    }

                    GameObject parent = null;

                    if (pivotAround != null)
                    {
                        parent = scene.GetChild(pivotAround);
                    }

                    parent = parent ?? obj?.transform?.parent?.gameObject;


                    if (parent != null)
                    {
                        GameObject pivot = new GameObject(obj.name + "_Pivot");

                        pivot.transform.SetParent(parent.transform);

                        pivot.transform.position      = pivotPosition ?? parent.transform.position;
                        pivot.transform.localRotation = pivotRotation ?? Quaternion.Euler(Vector3.zero);
                        pivot.transform.localScale    = pivotScale ?? Vector3.one;

                        obj.transform.SetParent(pivot.transform);

                        if (pivotDistance != null)
                        {
                            obj.transform.localPosition = Vector3.left * (float)pivotDistance;
                        }
                    }
                }

                if (pivotRotatoSpeed != null)
                {
                    if (obj?.transform?.parent?.gameObject != null)
                    {
                        Rotato pivotRotato = obj.transform.parent.gameObject.AddOrGetComponent <Rotato>();
                        pivotRotato.speed = (float)pivotRotatoSpeed;
                    }
                }


                // Bobber
                if (bobberSeed != null || bobberOFS != null)
                {
                    Bobber bobber = obj.AddOrGetComponent <Bobber>();

                    bobber.seed = bobberSeed ?? bobber.seed;

                    bobber.ofs1 = bobberOFS?.x ?? bobber.ofs1;
                    bobber.ofs2 = bobberOFS?.y ?? bobber.ofs2;
                    bobber.ofs3 = bobberOFS?.z ?? bobber.ofs3;
                }
            }
Exemple #5
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;
                }
            }
        }
        // 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();
        }