Пример #1
0
        private void updateDustEmission()
        {
            int len = dustObjects.Length;

            if (HighLogic.CurrentGame.Parameters.CustomParams <KSPWheelSettings>().wheelDustCamera)
            {
                //TODO remove this per-tick component lookup; source say to cache the vessel->module map in a static map in the vessel-module class; add/remove by the start/etc methods on the vessel-module
                KSPWheelDustCamera cm = vessel.GetComponent <KSPWheelDustCamera>();
                updateColorArray(cm.cameraColor);
            }
            else
            {
                if (colorUpdateTimer <= 0)
                {
                    string body  = vessel.mainBody.name;
                    string biome = ScienceUtil.GetExperimentBiome(vessel.mainBody, vessel.latitude, vessel.longitude);
                    if (body != prevBody || biome != prevBiome)
                    {
                        updateColorArray(DustColors.getBodyColor(body, biome));
                    }
                    colorUpdateTimer = colorUpdateTime;
                    prevBody         = body;
                    prevBiome        = biome;
                }
                colorUpdateTimer -= Time.deltaTime;
            }
            KSPWheelCollider wheel;

            KSPWheelBase.KSPWheelData data;
            float springForce = 1f;
            float speedForce  = 1f;
            float slipForce   = 1f;
            float mult        = 0f;

            for (int i = 0; i < len; i++)
            {
                data  = controller.wheelData[i];
                wheel = data.wheel;
                if (dustPower <= 0)
                {
                    dustEmitters[i].emit  = false;
                    waterEmitters[i].emit = false;
                }
                else if (data.waterMode)
                {
                    springForce = data.waterEffectSize;
                    mult        = data.waterEffectForce * dustSpeedMult;
                    waterObjects[i].transform.position = data.waterEffectPos;
                    waterObjects[i].transform.rotation = wheel.transform.rotation;
                    if (mult > 0)
                    {
                        waterEmitters[i].localVelocity = Vector3.up * mult;
                        waterEmitters[i].minEmission   = dustMinEmission * dustPower;
                        waterEmitters[i].maxEmission   = dustMaxEmission * dustPower;
                        waterEmitters[i].minEnergy     = dustMinEnergy * dustPower;
                        waterEmitters[i].maxEnergy     = dustMaxEnergy * mult * dustPower;
                        waterEmitters[i].minSize       = dustMinSize * springForce * dustPower;
                        waterEmitters[i].maxSize       = dustMaxSize * springForce * dustPower;
                        waterEmitters[i].emit          = true;
                    }
                    else
                    {
                        waterEmitters[i].emit = false;
                    }
                    dustEmitters[i].emit = false;
                }
                else if (wheel.isGrounded && wheel.wheelLocalVelocity.magnitude >= minDustSpeed)
                {
                    dustEmitters[i].emit  = true;
                    waterEmitters[i].emit = false;
                    springForce           = wheel.springForce * 0.1f * dustForceMult;
                    speedForce            = Mathf.Clamp(Mathf.Abs(wheel.wheelLocalVelocity.z) / maxDustSpeed, 0, 1);
                    slipForce             = Mathf.Clamp(Mathf.Abs(wheel.wheelLocalVelocity.x) / maxDustSpeed, 0, 1);
                    mult = Mathf.Sqrt(speedForce * speedForce * dustSpeedMult + slipForce * slipForce * dustSlipMult);
                    dustObjects[i].transform.position = wheel.worldHitPos;
                    dustObjects[i].transform.rotation = wheel.transform.rotation;
                    dustEmitters[i].localVelocity     = Vector3.up * (speedForce + slipForce);
                    dustEmitters[i].minEmission       = dustMinEmission * dustPower;
                    dustEmitters[i].maxEmission       = dustMaxEmission * dustPower;
                    dustEmitters[i].minEnergy         = dustMinEnergy * dustPower;
                    dustEmitters[i].maxEnergy         = dustMaxEnergy * mult * dustPower;
                    dustEmitters[i].minSize           = dustMinSize * springForce * dustPower;
                    dustEmitters[i].maxSize           = dustMaxSize * springForce * dustPower;
                }
                else
                {
                    dustEmitters[i].emit  = false;
                    waterEmitters[i].emit = false;
                }
            }
        }
Пример #2
0
        private void updateDustEmission()
        {
            if (!dustEnabled)
            {
                return;
            }
            //TODO remove this per-tick component lookup; source say to cache the vessel->module map in a static map in the vessel-module class; add/remove by the start/etc methods on the vessel-module
            KSPWheelDustCamera cm = vessel.GetComponent <KSPWheelDustCamera>();
            Color color           = cm.cameraColor;

            int len = dustEmitters.Length;

            Vector3 antiGravity = (-vessel.gravityForPos).normalized;

            KSPWheelCollider wheel;

            KSPWheelBase.KSPWheelData data;
            float springForce = 1f;
            float speedForce  = 1f;
            float slipForce   = 1f;
            float mult        = 0f;

            for (int i = 0; i < len; i++)
            {
                data  = controller.wheelData[i];
                wheel = data.wheel;
                if (dustPower <= 0)//dust disabled via game settings, really should never branch to this, but might if someone set dust to enabled, with dust power at zero
                {
                    dustEmitters[i].ext_setEmissionEnable(false);
                    waterEmitters[i].ext_setEmissionEnable(false);
                }
                else if (data.waterMode)
                {
                    waterEmitters[i].ext_setColor(color);
                    springForce = data.waterEffectSize * 0.25f;//0.25f mult is correction for changes between unity 5.4 / 2017.1.3
                    mult        = data.waterEffectForce * dustSpeedMult;
                    waterEmitters[i].transform.position = data.waterEffectPos;
                    waterEmitters[i].transform.rotation = wheel.transform.rotation;
                    waterEmitters[i].transform.LookAt(waterEmitters[i].transform.position + antiGravity, Vector3.forward);
                    if (mult > 0)
                    {
                        waterEmitters[i].ext_setVelocity(antiGravity * mult, Vector3.zero);
                        waterEmitters[i].ext_setEmissionMinMax(dustMinEmission * dustPower, dustMaxEmission * dustPower);
                        waterEmitters[i].ext_setSize(dustMinSize * springForce * dustPower, dustMaxSize * springForce * dustPower);
                        waterEmitters[i].ext_setEmissionEnable(true);
                    }
                    else
                    {
                        waterEmitters[i].ext_setEmissionEnable(false);
                    }
                    dustEmitters[i].ext_setEmissionEnable(false);
                }
                else if (wheel.isGrounded && wheel.wheelLocalVelocity.magnitude >= minDustSpeed)
                {
                    dustEmitters[i].ext_setColor(color);
                    springForce = wheel.springForce * 0.025f * dustForceMult;
                    speedForce  = Mathf.Clamp(Mathf.Abs(wheel.wheelLocalVelocity.z) / maxDustSpeed, 0, 1);
                    slipForce   = Mathf.Clamp(Mathf.Abs(wheel.wheelLocalVelocity.x) / maxDustSpeed, 0, 1);
                    mult        = Mathf.Sqrt(speedForce * speedForce * dustSpeedMult + slipForce * slipForce * dustSlipMult);
                    dustEmitters[i].transform.position = wheel.worldHitPos;
                    dustEmitters[i].transform.LookAt(dustEmitters[i].transform.position + antiGravity, Vector3.forward);
                    dustEmitters[i].ext_setVelocity(antiGravity * (speedForce + slipForce), Vector3.zero);
                    dustEmitters[i].ext_setEmissionMinMax(dustMinEmission * dustPower * mult, dustMaxEmission * dustPower * mult);
                    dustEmitters[i].ext_setSize(dustMinSize * springForce * dustPower, dustMaxSize * springForce * dustPower);
                    dustEmitters[i].ext_setEmissionEnable(true);
                    waterEmitters[i].ext_setEmissionEnable(false);
                }
                else//not grounded or wheel velocity is below threshold
                {
                    dustEmitters[i].ext_setEmissionEnable(false);
                    waterEmitters[i].ext_setEmissionEnable(false);
                }
            }
        }