Пример #1
0
        public void Apply(AtmosphereFromGround afg)
        {
            afg.DEBUG_alwaysUpdateAll = DEBUG_alwaysUpdateAll;
            afg.doScale = doScale;
            afg.ESun    = ESun;
            afg.Kr      = Kr;
            afg.Km      = Km;
            afg.transform.localScale = transformScale;
            afg.scaleDepth           = scaleDepth;
            afg.samples                 = samples;
            afg.g                       = g;
            afg.waveLength              = waveLength;
            afg.invWaveLength           = invWaveLength;
            afg.outerRadius             = outerRadius;
            afg.innerRadius             = innerRadius;
            afg.transform.localPosition = Vector3.zero;

            Configuration.AtmosphereFromGroundLoader.CalculatedMembers(afg);
            afg.SetMaterial(true);
        }
Пример #2
0
        private void Apply(AtmosphereFromGround afg)
        {
            Transform transform = afg.transform;

            afg.DEBUG_alwaysUpdateAll = _debugAlwaysUpdateAll;
            afg.doScale          = _doScale;
            afg.ESun             = _eSun;
            afg.Kr               = _kr;
            afg.Km               = _km;
            transform.localScale = _transformScale;
            afg.scaleDepth       = _scaleDepth;
            afg.samples          = _samples;
            afg.g                   = _g;
            afg.waveLength          = _waveLength;
            afg.invWaveLength       = _invWaveLength;
            afg.outerRadius         = _outerRadius;
            afg.innerRadius         = _innerRadius;
            transform.localPosition = Vector3.zero;

            AtmosphereFromGroundLoader.CalculatedMembers(afg);
            afg.SetMaterial(true);

            Events.OnRuntimeUtilityPatchAFG.Fire(afg);
        }
Пример #3
0
        private IEnumerator <YieldInstruction> NovaCoroutine()
        {
            LoggingUtil.LogDebug(this, "Jool is going nova");
            state     = State.JOOL_SHRINK;
            joolScale = 1.0f;

            SetTransformed(false);

            // Get the AtmosphereFromGround object
            AtmosphereFromGround afg = Resources.FindObjectsOfTypeAll <AtmosphereFromGround>().
                                       Where(a => a != null && a.planet != null && a.planet.name == "Jool").First();

            // Capture original scaling info
            origScale       = jool.scaledBody.transform.localScale;
            origInnerRadius = afg.innerRadius;
            origOuterRadius = afg.outerRadius;
            origAtmoScale   = afg.transform.localScale;

            // Rescale over every iteration
            while (true)
            {
                // Check if this will be the last scaling operation
                bool lastIteration = joolScale <= SHRUNK_SCALE;
                if (lastIteration)
                {
                    joolScale = SHRUNK_SCALE;
                }

                // Rescale Jool's ScaledVersion Transform
                jool.scaledBody.transform.localScale = origScale * joolScale;

                // Rescale atmosphere
                afg.innerRadius          = origInnerRadius * joolScale;
                afg.outerRadius          = origOuterRadius * joolScale;
                afg.transform.localScale = origAtmoScale * joolScale;

                afg.KrESun              = afg.Kr * afg.ESun;
                afg.KmESun              = afg.Km * afg.ESun;
                afg.Kr4PI               = afg.Kr * 4f * (float)Math.PI;
                afg.Km4PI               = afg.Km * 4f * (float)Math.PI;
                afg.g2                  = afg.g * afg.g;
                afg.outerRadius2        = afg.outerRadius * afg.outerRadius;
                afg.innerRadius2        = afg.innerRadius * afg.innerRadius;
                afg.scale               = 1f / (afg.outerRadius - afg.innerRadius);
                afg.scaleDepth          = -0.25f;
                afg.scaleOverScaleDepth = afg.scale / afg.scaleDepth;

                afg.SetMaterial(true);

                yield return(null);

                if (lastIteration)
                {
                    break;
                }
            }

            // Do the transformation
            SetTransformed(true);

            // Add our extra stuff
            GameObject explosion = new GameObject("Explosion");

            explosion.transform.parent        = jool.scaledBody.transform;
            explosion.layer                   = jool.scaledBody.layer;
            explosion.transform.localScale    = Vector3.one * 1.01f;
            explosion.transform.localPosition = Vector3.zero;
            explosion.transform.localRotation = Quaternion.identity;
            MeshRenderer explosionRenderer = explosion.AddComponent <MeshRenderer>();

            foreach (FieldInfo field in typeof(MeshRenderer).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                field.SetValue(explosionRenderer, field.GetValue(jool.scaledBody.GetComponent <MeshRenderer>()));
            }
            Texture2D explosionTex = TextureUtil.LoadTexture("ContractPacks/JoolianEncounter/Images/explosion.dds.noload");

            explosionRenderer.material.shader = Shader.Find("KSP/Alpha/Translucent");
            explosionRenderer.material.SetTexture(Shader.PropertyToID("_MainTex"), explosionTex);
            MeshFilter explosionMesh = explosion.AddComponent <MeshFilter>();

            explosionMesh.sharedMesh = jool.scaledBody.GetComponent <MeshFilter>().sharedMesh;
            explosion.SetActive(true);

            // Rescale over every iteration
            joolScale = SHRUNK_SCALE;
            state     = State.SUN_GROW;
            stateTime = Time.time;
            while (true)
            {
                // Check if this will be the last scaling operation
                bool lastIteration = joolScale >= FINAL_SCALE;
                if (lastIteration)
                {
                    joolScale = FINAL_SCALE;
                }

                // Rescale Jool's scaled body Transform
                jool.scaledBody.transform.localScale = origScale * joolScale;

                // Fade the alpha out as the explosion grows
                float alpha = Mathf.Lerp(1.0f, 0.0f, (explosionScale / joolScale) / 10.0f);
                explosionRenderer.material.color = new Color(1.0f, 1.0f, 1.0f, alpha);

                // Rescale the explosion
                explosion.transform.localScale = Vector3.one * (explosionScale / joolScale);

                if (lastIteration)
                {
                    break;
                }
                yield return(null);
            }

            // Continue with the outer part of the explosion
            state          = State.EXPLOSION_GROW;
            explosionsDone = false;
            while (true)
            {
                // Rescale the explosion
                explosion.transform.localScale = Vector3.one * (explosionScale / joolScale);

                // Stop burninating 5000 km after it has passed
                if ((explosionScale / joolScale) * 1.01f * jool.Radius >= FlightGlobals.ActiveVessel.altitude + jool.Radius + 5000000)
                {
                    burninating = false;
                }
                // There's a big delay before the atmospheric effects kick in, so start burninating pretty early (5000 km)
                else if (!burninating && (explosionScale / joolScale) * jool.Radius >= FlightGlobals.ActiveVessel.altitude + jool.Radius - 5000000)
                {
                    burninating = true;
                    StartCoroutine(Burninator());
                }

                // Blow up the ship! (part of it)
                if (!explosionsDone && (explosionScale / joolScale) * jool.Radius >= FlightGlobals.ActiveVessel.altitude + jool.Radius)
                {
                    ExplodeParts();

                    // Do a camera wobble
                    LoggingUtil.LogDebug(this, "overheat event");
                    FlightCameraFX fcfx        = UnityEngine.Object.FindObjectOfType <FlightCameraFX>();
                    MethodInfo     eventMethod = typeof(FlightCameraFX).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).
                                                 Where(mi => mi.Name == "OnVesselEvent").First();
                    eventMethod.Invoke(fcfx, new object[] { new EventReport(FlightEvents.OVERHEAT, FlightGlobals.ActiveVessel.rootPart,
                                                                            FlightGlobals.ActiveVessel.name, "Jool") });
                }

                // Fade the alpha out as the explosion grows
                float alpha = Mathf.Lerp(1.0f, 0.0f, (explosionScale / joolScale) / 10.0f);
                explosionRenderer.material.color = new Color(1.0f, 1.0f, 1.0f, alpha);

                if ((explosionScale / joolScale) >= 10.0f)
                {
                    break;
                }
                yield return(null);
            }

            // Remove explodey part
            burninating = false;
            explosion.transform.parent = null;
            Destroy(explosion);
            Destroy(explosionTex);
        }
Пример #4
0
        public void Apply(AtmosphereFromGround afg)
        {
            afg.DEBUG_alwaysUpdateAll = DEBUG_alwaysUpdateAll;
            afg.doScale = doScale;
            afg.ESun = ESun;
            afg.Kr = Kr;
            afg.Km = Km;
            afg.transform.localScale = transformScale;
            afg.scaleDepth = scaleDepth;
            afg.samples = samples;
            afg.g = g;
            afg.waveLength = waveLength;
            afg.invWaveLength = invWaveLength;
            afg.outerRadius = outerRadius;
            afg.innerRadius = innerRadius;
            afg.transform.localPosition = Vector3.zero;

            Configuration.AtmosphereFromGroundLoader.CalculatedMembers(afg);
            afg.SetMaterial(true);
        }