Exemple #1
0
    public void EditorRepaintClouds()
    {
        int           i = 0;
        CloudParticle MyCloudParticle;

        if (MyCloudsParticles.Count == 0)
        {
            return;
        }
        for (i = 0; i < MaximunClouds; i++)
        {
            MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
            if (MyCloudParticle.IsActive())
            {
                // Define some main particle properties
                if (TypeClouds == Type.Nimbus1 || TypeClouds == Type.Nimbus2 ||
                    TypeClouds == Type.Nimbus3 || TypeClouds == Type.Nimbus4 ||
                    TypeClouds == Type.MixNimbus || TypeClouds == Type.MixAll)
                {
                    MyCloudParticle.DefineCloudProperties(i, MaxWithCloud, MaxTallCloud, MaxDepthCloud, 0, FixedSize, true, true);
                }
                else
                if (TypeClouds == Type.Cirrus1 || TypeClouds == Type.Cirrus2 || TypeClouds == Type.MixCirrus)
                {
                    MyCloudParticle.DefineCloudProperties(i, MaxWithCloud, MaxTallCloud, MaxDepthCloud, 1, FixedSize, true, true);
                }

                MyCloudParticle.UpdateCloudsPosition();
                if (CloudRender == TypeRender.Realistic)
                {
                    MyCloudParticle.SetMainColor(CloudColor);
                }
                PaintTheParticlesShadows(MyCloudParticle);
            }
        }
    }
Exemple #2
0
// Only we manage the changes of variables in the inspector of Unity, not be used in gametime when
// everything is setup.
    void  Update()
    {
        CloudParticle MyCloudParticle;
        int           i;

        // Create the procedural Texture Object of PT1 texture is selected in runtime.
        if (TypeClouds == Type.PT1 && !ProceduralTexture)
        {
            GameObject PText1 = new GameObject();
            PText1.name = "CloudsToyPT1";
            PText1.transform.position = Vector3.zero;
            PText1.transform.rotation = Quaternion.identity;
            PText1.transform.parent   = MyTransform;
            ProceduralTexture         = (ProceduralCloudTexture)PText1.AddComponent("ProceduralCloudTexture");
            PT1CopyInitialParameters();

            // Create the procedural materials to use in the clouds if PT1 had been selected.
            CloudsPTMatAdditive = new Material(Shader.Find("FX/CloudBright"));
            if (ProceduralTexture.IsInicialized())
            {
                CloudsPTMatAdditive.mainTexture = ProceduralTexture.MyTexture;
            }
            // Fourth type of Clouds. Procedural Blended textures
            CloudsPTMatBlended = new Material(Shader.Find("FX/CloudRealistic"));
            CloudsPTMatBlended.SetColor("_TintColor", CloudColor);
            if (ProceduralTexture.IsInicialized())
            {
                CloudsPTMatBlended.mainTexture = ProceduralTexture.MyAlphaTexture;
            }
        }

        // Trying to Assign a procedural txeture, once the texture is already created, not earlyer
        // PT1 needs time to be created and inicialized, that's why this code exits
        if (ProceduralTexture)
        {
            if (ProceduralTexture.IsInicialized() && !bAssignProcTexture)
            {
                // Procedural Additive textures
                CloudsPTMatAdditive.mainTexture = ProceduralTexture.MyTexture;
                // Procedural Blended textures
                CloudsPTMatBlended.SetColor("_TintColor", CloudColor);
                CloudsPTMatBlended.mainTexture = ProceduralTexture.MyAlphaTexture;

                if (TypeClouds == Type.PT1)
                {
                    for (i = 0; i < MaximunClouds; i++)
                    {
                        MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                        if (i < NumberClouds)
                        {
                            MyCloudParticle.SetActive(true);
                            MyCloudParticle.UpdateCloudsPosition();
                            if (CloudRender == TypeRender.Realistic)
                            {
                                MyCloudParticle.SetMainColor(CloudColor);
                            }
                            PaintTheParticlesShadows(MyCloudParticle);
                        }
                    }
                }
                bAssignProcTexture = true;
            }
        }

        // Change the number of visible clouds. Must activate the new particles and Update de position of the particles in the ellipse
        if (NumberCloudsAnt != NumberClouds)
        {
            for (i = 0; i < MaximunClouds; i++)
            {
                MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                if (i < NumberClouds && !MyCloudParticle.IsActive())
                {
                    MyCloudParticle.SetActive(true);
                    MyCloudParticle.UpdateCloudsPosition();
                    if (SoftClouds)
                    {
                        SoftCloudsAnt = !SoftClouds;
                    }
                }
                else
                if (i >= NumberClouds && MyCloudParticle.IsActive())
                {
                    MyCloudParticle.DesactivateRecursively();
                }
            }
            NumberCloudsAnt = NumberClouds;
        }
        // Actualize the particle emmitter if the density of particles emmited has changed by user
        if (CloudDetailAnt != CloudDetail)
        {
            if (CloudDetail == TypeDetail.Low)
            {
                EmissionMult   = 1;
                SizeFactorPart = 1;
            }
            else
            if (CloudDetail == TypeDetail.Normal)
            {
                EmissionMult   = 1.5f;
                SizeFactorPart = 1.2f;
            }
            else
            if (CloudDetail == TypeDetail.High)
            {
                EmissionMult   = 2.0f;
                SizeFactorPart = 1.3f;
            }
            for (i = 0; i < NumberClouds; i++)
            {
                MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                MyCloudParticle.SetCloudEmitter(i, SpreadDir, SoftClouds, SizeFactorPart, EmissionMult, MaximunVelocity, VelocityMultipier);
                MyCloudParticle.SetActive(true);
                MyCloudParticle.UpdateCloudsPosition();
                if (CloudRender == TypeRender.Realistic)
                {
                    MyCloudParticle.SetMainColor(CloudColor);
                }
                PaintTheParticlesShadows(MyCloudParticle);
            }
            CloudDetailAnt = CloudDetail;
        }
        // if change the Size or amount of particles emmitted by any Cloud, must update the partice emmitter and emit again.
        // after that, we ensure the particles are in the assigned ellipsoid of the cloud
        if (SizeFactorPartAnt != SizeFactorPart || EmissionMultAnt != EmissionMult)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                MyCloudParticle.SetCloudEmitter(i, SpreadDir, SoftClouds, SizeFactorPart, EmissionMult, MaximunVelocity, VelocityMultipier);
                MyCloudParticle.SetActive(true);
                MyCloudParticle.UpdateCloudsPosition();
            }
            SizeFactorPartAnt = SizeFactorPart;
            EmissionMultAnt   = EmissionMult;
        }
        // Are soft clouds? Update the particle emmitter and renderer to take care of the change
        if (SoftCloudsAnt != SoftClouds)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                MyCloudParticle.SetCloudEmitter(i, SpreadDir, SoftClouds, SizeFactorPart, EmissionMult, MaximunVelocity, VelocityMultipier);
                MyCloudParticle.SoftCloud(SoftClouds);
                MyCloudParticle.SetActive(true);
                MyCloudParticle.UpdateCloudsPosition();
            }
            SoftCloudsAnt = SoftClouds;
        }
        //  this two vars, only are visibles if softClouds are true, otherwise any change will not be advised
        if (SpreadDirAnt != SpreadDir || LengthSpreadAnt != LengthSpread)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                MyCloudParticle.SetLengthScale(LengthSpread);
                if (SpreadDirAnt != SpreadDir)
                {
                    MyCloudParticle.SetWorldVelocity(SpreadDir);
                    MyCloudParticle.SetActive(true);
                    MyCloudParticle.UpdateCloudsPosition();
                }
            }
            SpreadDirAnt    = SpreadDir;
            LengthSpreadAnt = LengthSpread;
        }
        // Changin the clouds width or tall. Must redefine all the cloud parameters, including his name
        if (MaxWithCloud != MaxWithCloudAnt || MaxTallCloud != MaxTallCloudAnt || MaxDepthCloud != MaxDepthCloudAnt)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                // Define some main particle properties
                if (TypeClouds == Type.Nimbus1 || TypeClouds == Type.Nimbus2 ||
                    TypeClouds == Type.Nimbus3 || TypeClouds == Type.Nimbus4 ||
                    TypeClouds == Type.MixNimbus || TypeClouds == Type.MixAll || TypeClouds == Type.PT1)
                {
                    MyCloudParticle.DefineCloudProperties(i, MaxWithCloud, MaxTallCloud, MaxDepthCloud, 0, FixedSize, true, true);
                }
                else
                if (TypeClouds == Type.Cirrus1 || TypeClouds == Type.Cirrus2 || TypeClouds == Type.MixCirrus)
                {
                    MyCloudParticle.DefineCloudProperties(i, MaxWithCloud, MaxTallCloud, MaxDepthCloud, 1, FixedSize, true, true);
                }
                // Change the emitter params of the cloud to adjust the new size.
                MyCloudParticle.SetCloudEmitter(i, SpreadDir, SoftClouds, SizeFactorPart, EmissionMult, MaximunVelocity, VelocityMultipier);
                // Start emit again, my friend.
                MyCloudParticle.SetActive(true);
                //  Update the position of the particles emmitted inside the ellipsoid
                MyCloudParticle.UpdateCloudsPosition();
                // Colorize the cloud
                if (CloudRender == TypeRender.Realistic)
                {
                    MyCloudParticle.SetMainColor(CloudColor);
                }
                PaintTheParticlesShadows(MyCloudParticle);
            }
            MaxWithCloudAnt  = MaxWithCloud;
            MaxTallCloudAnt  = MaxTallCloud;
            MaxDepthCloudAnt = MaxDepthCloud;
        }
        // If change the type of cloud just meaning i must change his material or render mode
        // also assign again the new texture if the procedural texture has changed.
        if (TypeCloudsAnt != TypeClouds || CloudRenderAnt != CloudRender /*|| ProceduralTexture.IsTextureUpdated()*/)
        {
            for (i = 0; i < MaximunClouds; i++)
            {
                MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                // Change the Material depending on the type defined by user
                AssignCloudMaterial(MyCloudParticle, CloudRender, TypeClouds);
            }
            TypeCloudsAnt  = TypeClouds;
            CloudRenderAnt = CloudRender;
        }
        // Actualize the velocity of the cloud and take care of the direccion of the mov for the LateUpdate proccess.
        if (MaximunVelocityAnt != MaximunVelocity || VelocityMultipierAnt != VelocityMultipier)
        {
            // Define the axis the clouds are moving on. (Only one value X or Y or Z, must be not equal Zero).
            // Used to determine the way the coulds are goig to dissapear when they move far away from the Box.
            if (MaximunVelocity.x > 0)
            {
                CloudsGenerateAxis = Axis.X;
            }
            else
            if (MaximunVelocity.x < 0)
            {
                CloudsGenerateAxis = Axis.XNeg;
            }
            else
            if (MaximunVelocity.y > 0)
            {
                CloudsGenerateAxis = Axis.Y;
            }
            else
            if (MaximunVelocity.y < 0)
            {
                CloudsGenerateAxis = Axis.YNeg;
            }
            else
            if (MaximunVelocity.z > 0)
            {
                CloudsGenerateAxis = Axis.Z;
            }
            else
            if (MaximunVelocity.z < 0)
            {
                CloudsGenerateAxis = Axis.ZNeg;
            }

            for (i = 0; i < MaximunClouds; i++)
            {
                ((CloudParticle)MyCloudsParticles[i]).SetCloudVelocity(MaximunVelocity, VelocityMultipier);
            }

            MaximunVelocityAnt   = MaximunVelocity;
            VelocityMultipierAnt = VelocityMultipier;
        }
        // All this just change one color or the system to colorize the cloud, just that.
        if (CloudColorAnt != CloudColor)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                ((CloudParticle)MyCloudsParticles[i]).SetMainColor(CloudColor);
            }
            CloudColorAnt = CloudColor;
        }

        if (MainColorAnt != MainColor)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                PaintTheParticlesShadows(((CloudParticle)MyCloudsParticles[i]));
            }
            MainColorAnt = MainColor;
        }

        if (SecondColorAnt != SecondColor || TintStrengthAnt != TintStrength)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                PaintTheParticlesShadows(((CloudParticle)MyCloudsParticles[i]));
            }
            SecondColorAnt  = SecondColor;
            TintStrengthAnt = TintStrength;
        }

        if (offsetAnt != offset)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                PaintTheParticlesShadows(((CloudParticle)MyCloudsParticles[i]));
            }
            offsetAnt = offset;
        }

        if (PaintTypeAnt != PaintType)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                PaintTheParticlesShadows(((CloudParticle)MyCloudsParticles[i]));
            }
            PaintTypeAnt = PaintType;
        }

        // Determine if cloud shadow must be active or not, depending on user choice
        if (NumberOfShadowsAnt != NumberOfShadows)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                ManageCloudShadow(MyCloudParticle);
            }
            NumberOfShadowsAnt = NumberOfShadows;
        }

        if (IsAnimate)
        {
            for (i = 0; i < NumberClouds; i++)
            {
                MyCloudParticle = (CloudParticle)MyCloudsParticles[i];
                MyCloudParticle.AnimateCloud(AnimationVelocity);
            }
        }
    }