public static void Remove(PersistentKSPParticleEmitter pkpe)
    {
        EffectBehaviour.RemoveParticleEmitter(pkpe.pe);
        persistentEmitters.Remove(pkpe);

        //print("[SmokeScreen PersistentEmitterManager]: Removed 1 PersistentKSPParticleEmitter. Count = " + persistentEmitters.Count);
    }
    public static void Add(PersistentKSPParticleEmitter pkpe)
    {
        persistentEmitters.Add(pkpe);
        EffectBehaviour.AddParticleEmitter(pkpe.pe);

        //print("[SmokeScreen PersistentEmitterManager]: Added 1 PersistentKSPParticleEmitter. Count = " + persistentEmitters.Count);
    }
Esempio n. 3
0
    public static void Remove(PersistentKSPParticleEmitter pkpe)
    {
        EffectBehaviour.RemoveParticleEmitter(pkpe.pe);
        persistentEmitters.Remove(pkpe);

        //print("[SmokeScreen PersistentEmitterManager]: Removed 1 PersistentKSPParticleEmitter. Count = " + persistentEmitters.Count);
    }
Esempio n. 4
0
    public static void Add(PersistentKSPParticleEmitter pkpe)
    {
        persistentEmitters.Add(pkpe);
        EffectBehaviour.AddParticleEmitter(pkpe.pe);

        //print("[SmokeScreen PersistentEmitterManager]: Added 1 PersistentKSPParticleEmitter. Count = " + persistentEmitters.Count);
    }
Esempio n. 5
0
    public void FixedUpdate()
    {
        //Print("FixedUpdate");
        if (persistentEmitters == null || hostPart == null || hostPart.rb == null)
        {
            return;
        }

        if (singleTimerEnd > 0)
        {
            if (Time.fixedTime <= singleTimerEnd)
            {
                OnEvent(1);
            }
            else
            {
                OnEvent(0);
                singleTimerEnd = 0;
            }
        }
        SmokeScreenConfig.UpdateParticlesCount();

        //RaycastHit vHit = new RaycastHit();
        //Ray vRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        //if(Physics.Raycast(vRay, out vHit))
        //{
        //    RaycastHit vHit2 = new RaycastHit();
        //    if (Physics.Raycast(vHit.point + vHit.normal * 10, -vHit.normal, out vHit2))
        //        Debug.Log(vHit2.collider.name);
        //}

        PersistentKSPParticleEmitter[] persistentKspParticleEmitters = persistentEmitters.ToArray();
        for (int i = 0; i < persistentKspParticleEmitters.Length; i++)
        {
            PersistentKSPParticleEmitter persistentKspParticleEmitter = persistentKspParticleEmitters[i];

            persistentKspParticleEmitter.EmitterOnUpdate(hostPart.rb.velocity + Krakensbane.GetFrameVelocity());
        }
    }
Esempio n. 6
0
    public override void OnInitialize()
    {
        //Print("Init");

        // Restore the Curve config from the node content backup
        // Done because I could not get the serialization of MultiInputCurve to work
        if (node_backup != string.Empty)
        {
            Restore();
        }

        // The shader loading require proper testing
        // Unity doc says that "Creating materials this way supports only simple shaders (fixed function ones).
        // If you need a surface shader, or vertex/pixel shaders, you'll need to create shader asset in the editor and use that."
        // But importing the same shader that the one used in the editor seems to work
        string filename = KSPUtil.ApplicationRootPath + "GameData/" + shaderFileName;

        if (shaderFileName != string.Empty && File.Exists(filename))
        {
            try
            {
                TextReader shaderFile = new StreamReader(filename);
                string     shaderText = shaderFile.ReadToEnd();
                shader = new Material(shaderText).shader;
            }
            catch (Exception e)
            {
                Print("unable to load shader " + shaderFileName + " : " + e);
            }
        }

        List <Transform> transforms = new List <Transform>(hostPart.FindModelTransforms(transformName));

        if (transforms.Count == 0)
        {
            Print("Cannot find transform " + transformName);
            return;
        }
        GameObject model = GameDatabase.Instance.GetModel(modelName);

        if (model == null)
        {
            Print("Cannot find model " + modelName);
            return;
        }
        model.SetActive(true);
        KSPParticleEmitter templateKspParticleEmitter = model.GetComponentInChildren <KSPParticleEmitter>();

        if (templateKspParticleEmitter == null)
        {
            Print("Cannot find particle emitter on " + modelName);
            Destroy(model);
            return;
        }

        if (shader != null)
        {
            templateKspParticleEmitter.material.shader = shader;
        }

        if (persistentEmitters == null)
        {
            persistentEmitters = new List <PersistentKSPParticleEmitter>();
        }

        if (hostPart.Modules.Contains("ProceduralSRB"))
        {
            PartModule pm = hostPart.Modules["ProceduralSRB"];

            specialScale = pm.Fields.GetValue <float>("bellScale");
            Print("Found ProceduralSRB. Rescaling by " + specialScale.ToString("F3") + " final scale " + (fixedScale * specialScale).ToString("F3"));
        }

        for (int i = 0; i < transforms.Count; i++)
        {
            GameObject         emitterGameObject       = Instantiate(model) as GameObject;
            KSPParticleEmitter childKSPParticleEmitter = emitterGameObject.GetComponentInChildren <KSPParticleEmitter>();

            if (shader != null)
            {
                childKSPParticleEmitter.material.shader    = shader;
                childKSPParticleEmitter.pr.material.shader = shader;
            }

            if (childKSPParticleEmitter != null)
            {
                PersistentKSPParticleEmitter pkpe = new PersistentKSPParticleEmitter(
                    emitterGameObject,
                    childKSPParticleEmitter,
                    templateKspParticleEmitter);

                try
                {
                    childKSPParticleEmitter.particleRenderMode =
                        (ParticleRenderMode)Enum.Parse(typeof(ParticleRenderMode), renderMode);
                }
                catch (ArgumentException)
                {
                    Print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleRenderMode");
                }

                persistentEmitters.Add(pkpe);

                DisableCollider(pkpe.go);

                emitterGameObject.transform.SetParent(transforms[i]);

                emitterGameObject.transform.localPosition = localPosition;
                emitterGameObject.transform.localRotation = Quaternion.Euler(localRotation);
            }
        }

        Destroy(templateKspParticleEmitter);

        list.Add(this);

        // 1.0 don't seems to properly do this for engines.
        OnEvent(0);
    }
Esempio n. 7
0
    public void UpdateEmitters(float power)
    {
        UpdateInputs(power);

        for (int i = 0; i < persistentEmitters.Count; i++)
        {
            PersistentKSPParticleEmitter pkpe = persistentEmitters[i];

            if (pkpe.go == null)
            {
                continue;
            }

            //pkpe.pe.useWorldSpace
            float finalScale = fixedScale * specialScale;

            float finalSizeClamp = sizeClamp + sizeClampCurve.Value(inputs);

            float sizePower = size.Value(inputs) * finalScale;
            pkpe.pe.minSize = Mathf.Min(pkpe.minSizeBase * sizePower, finalSizeClamp);
            pkpe.pe.maxSize = Mathf.Min(pkpe.maxSizeBase * sizePower, finalSizeClamp);

            float emissionPower = emission.Value(inputs) * emissionMult;
            pkpe.pe.minEmission = Mathf.FloorToInt(pkpe.minEmissionBase * emissionPower);
            pkpe.pe.maxEmission = Mathf.FloorToInt(pkpe.maxEmissionBase * emissionPower);

            float energyPower = energy.Value(inputs);
            pkpe.pe.minEnergy = pkpe.minEnergyBase * energyPower;
            pkpe.pe.maxEnergy = pkpe.maxEnergyBase * energyPower;

            float velocityPower = speed.Value(inputs) * finalScale;
            pkpe.pe.localVelocity = pkpe.localVelocityBase * velocityPower;
            pkpe.pe.worldVelocity = pkpe.worldVelocityBase * velocityPower;

            float forcePower = force.Value(inputs);
            pkpe.pe.force = pkpe.forceBase * forcePower;

            pkpe.pe.sizeGrow = grow.Value(inputs);

            float currentScale = scale.Value(inputs) * finalScale;
            pkpe.pe.shape1D = pkpe.scale1DBase * currentScale;
            pkpe.pe.shape2D = pkpe.scale2DBase * currentScale;
            pkpe.pe.shape3D = pkpe.scale3DBase * currentScale;

            pkpe.sizeClamp = finalSizeClamp;
            pkpe.randomInitalVelocityOffsetMaxRadius = randomInitalVelocityOffsetMaxRadius + initalVelocityOffsetMaxRadius.Value(inputs);

            pkpe.randConeEmit = randConeEmit.Value(inputs);
            pkpe.xyForce      = xyForce.Value(inputs);
            pkpe.zForce       = zForce.Value(inputs);

            pkpe.vRandPosOffset = vRandPosOffset.Value(inputs);
            pkpe.vPosOffset     = vPosOffset.Value(inputs);

            pkpe.physical        = physical && !SmokeScreenConfig.Instance.globalPhysicalDisable;
            pkpe.initialDensity  = initialDensity;
            pkpe.dragCoefficient = dragCoefficient;

            pkpe.collide      = collide && !SmokeScreenConfig.Instance.globalCollideDisable;
            pkpe.stickiness   = stickiness;
            pkpe.collideRatio = collideRatio;

            pkpe.logarithmicGrow      = logGrow.Value(inputs);
            pkpe.logarithmicGrowScale = logGrowScale.Value(inputs);

            pkpe.linearGrow = linGrow.Value(inputs);

            if (alpha.Value(inputs) != 1 || linAlphaDecay.Value(inputs) != 0 || logAlphaDecay.Value(inputs) != 0)
            {
                Color[] cols = new Color[5];

                for (int t = 0; t < 5; t++)
                {
                    float a =
                        Mathf.Clamp01(alpha.Value(inputs) *
                                      (1 - linAlphaDecay.Value(inputs) * (t / 4) -
                                       Mathf.Log(logAlphaDecay.Value(inputs) * (t / 4) + 1)));
                    cols[t] = new Color(a, a, a, a);
                }

                pkpe.pe.colorAnimation   = cols;
                pkpe.pe.doesAnimateColor = true;
            }

            pkpe.go.transform.localPosition = localPosition
                                              + offsetDirection.normalized * offset.Value(inputs) * finalScale;

            pkpe.go.transform.localRotation = Quaternion.Euler(localRotation);


            if (renderMode != lastRenderMode)
            {
                // Bad code is bad
                try
                {
                    pkpe.pe.particleRenderMode = (ParticleRenderMode)Enum.Parse(typeof(ParticleRenderMode), renderMode);
                }
                catch (ArgumentException) { }
                lastRenderMode = renderMode;
            }
        }
    }
    public override void OnInitialize()
    {
        //Print("Init");

        // Restore the Curve config from the node content backup
        // Done because I could not get the serialization of MultiInputCurve to work
        if (node_backup != string.Empty)
        {
            Restore();
        }

        // The shader loading require proper testing
        // Unity doc says that "Creating materials this way supports only simple shaders (fixed function ones).
        // If you need a surface shader, or vertex/pixel shaders, you'll need to create shader asset in the editor and use that."
        // But importing the same shader that the one used in the editor seems to work
        string filename = KSPUtil.ApplicationRootPath + "GameData/" + shaderFileName;
        if (shaderFileName != string.Empty && File.Exists(filename))
        {
            try
            {
                TextReader shaderFile = new StreamReader(filename);
                string shaderText = shaderFile.ReadToEnd();
                shader = new Material(shaderText).shader;
            }
            catch (Exception e)
            {
                Print("unable to load shader " + shaderFileName + " : " + e);
            }
        }

        List<Transform> transforms = new List<Transform>(hostPart.FindModelTransforms(transformName));
        if (transforms.Count == 0)
        {
            Print("Cannot find transform " + transformName);
            return;
        }
        GameObject model = GameDatabase.Instance.GetModel(modelName);
        if (model == null)
        {
            Print("Cannot find model " + modelName);
            return;
        }
        model.SetActive(true);
        KSPParticleEmitter templateKspParticleEmitter = model.GetComponentInChildren<KSPParticleEmitter>();

        if (templateKspParticleEmitter == null)
        {
            Print("Cannot find particle emitter on " + modelName);
            Destroy(model);
            return;
        }

        if (shader != null)
        {
            templateKspParticleEmitter.material.shader = shader;
        }

        if (persistentEmitters == null)
        {
            persistentEmitters = new List<PersistentKSPParticleEmitter>();
        }

        if (hostPart.Modules.Contains("ProceduralSRB"))
        {
            PartModule pm = hostPart.Modules["ProceduralSRB"];

            specialScale = pm.Fields.GetValue<float>("bellScale");
            Print("Found ProceduralSRB. Rescaling by " + specialScale.ToString("F3") + " final scale " + (fixedScale * specialScale).ToString("F3"));
        }

        for (int i = 0; i < transforms.Count; i++)
        {
            GameObject emitterGameObject = Instantiate(model) as GameObject;
            KSPParticleEmitter childKSPParticleEmitter = emitterGameObject.GetComponentInChildren<KSPParticleEmitter>();

            if (shader != null)
            {
                childKSPParticleEmitter.material.shader = shader;
                childKSPParticleEmitter.pr.material.shader = shader;
            }

            if (childKSPParticleEmitter != null)
            {
                PersistentKSPParticleEmitter pkpe = new PersistentKSPParticleEmitter(
                    emitterGameObject,
                    childKSPParticleEmitter,
                    templateKspParticleEmitter);

                try
                {
                    childKSPParticleEmitter.particleRenderMode =
                        (ParticleRenderMode)Enum.Parse(typeof (ParticleRenderMode), renderMode);
                }
                catch (ArgumentException)
                {
                    Print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleRenderMode");
                }

                persistentEmitters.Add(pkpe);

                DisableCollider(pkpe.go);

                emitterGameObject.transform.SetParent(transforms[i]);

                emitterGameObject.transform.localPosition = localPosition;
                emitterGameObject.transform.localRotation = Quaternion.Euler(localRotation);
            }
        }

        Destroy(templateKspParticleEmitter);

        list.Add(this);

        // 1.0 don't seems to properly do this for engines.
        OnEvent(0);
    }