コード例 #1
0
        /// <summary>
        /// Zoom in on a planet
        /// </summary>
        public void EnterPlanet(CelestialBody celestialBody)
        {
            controller.zoomed    = celestialBody;
            celestialBody.zoomed = true;
            systemScale.SetActive(false);
            planetScale.SetActive(true);
            Utility.DestroyAllChildren(planetScale.transform);
            var localCopy = GameObject.Instantiate(celestialBody.gameObject, Vector3.zero, Quaternion.identity, planetScale.transform);

            localCopy.name = "Local Copy of " + celestialBody.type.ToString();
            localCopy.transform.localRotation = Quaternion.identity;
            localCopy.transform.localScale    = Vector3.one * controller.planetScaleMultiplier;

            if (celestialBody is DynamicPlanet)
            {
                Utility.DestroyAllChildren(localCopy.transform, "region");
                (celestialBody as DynamicPlanet).regions.ForEach(r => r.Destroy());
            }
            var rings = localCopy.transform.Find("rings");

            if (rings != null)
            {
                PlanetRings.UpdatePlanetRadius(rings.gameObject, celestialBody.radius * controller.planetScaleMultiplier);
            }

            celestialBody.originalGameObject = celestialBody.gameObject;
            celestialBody.gameObject         = localCopy;

            TeleportPlayerIn(celestialBody);
            CopyRelativeCelestials(celestialBody);
            UpdateVolumetricAtmosphere(celestialBody);
        }
コード例 #2
0
        private void UpdateRelativePositions()
        {
            Vector3 player = GetWorldPlayerPosition();

            foreach (var kv in localCopies)
            {
                CelestialBody celestialBody = kv.Key;
                GameObject    copy          = kv.Value;
                CelestialBody zoomed        = controller.zoomed;

                Quaternion inverse = Quaternion.Inverse(zoomed.rotation);
                Shader.SetGlobalVector("_SkyboxRotation", zoomed.rotation.eulerAngles);

                Vector3 planetToPlanet = celestialBody.position - zoomed.position;
                planetToPlanet = inverse * planetToPlanet;

                Vector3 rotatedCelestialBodyPosition = zoomed.position + planetToPlanet;

                Vector3 realDistance    = rotatedCelestialBodyPosition - player;
                float   realMagnitude   = realDistance.magnitude;
                float   v_realMagnitude = Mathf.Clamp((realMagnitude + 2000f) / 14000f, 0, 1); //0 - 1
                v_realMagnitude = Mathf.Pow(v_realMagnitude, .1f);                             //move close objects farther away

                float   newMagnitude = 90000 * v_realMagnitude;                                //max unity coords
                Vector3 newDistance  = realDistance.normalized * newMagnitude;
                float   factor       = newMagnitude / realMagnitude;

                Vector3 relativePos = controller.playerPosition + newDistance;
                celestialBody.relativePosition = relativePos;
                copy.transform.position        = relativePos;
                copy.transform.localScale      = Vector3.one * factor;

                foreach (Transform child in copy.transform)
                {
                    if (child.name == "rings")
                    {
                        PlanetRings.UpdatePlanetRadius(child.gameObject, celestialBody.radius * factor);
                    }
                }

                if (celestialBody.type is CelestialType.Star)
                {
                    Shader.SetGlobalVector("_SunPos", celestialBody.relativePosition);
                    Vector3 from = Vector3.forward;
                    Vector3 to   = Vector3.zero - celestialBody.relativePosition;
                    copy.transform.rotation = Quaternion.FromToRotation(from, to); //Directional Light
                }
            }
        }