/// <summary>
        /// Generates the rain particles when a flood occurs. This stops at the next turn
        /// </summary>
        /// <param name="canvas"></param>
        public override void GenerateScene(GameObject canvas)
        {
            StoryManager.city.NextTurnEvent += StopRain;
            GameObject customParticleSystem = new GameObject("CustomParticleSystem");

            customParticleSystem.transform.SetParent(StoryManager.city.Map.gameObject.transform, false);
            customParticleSystem.transform.position = new Vector3(-10, 14, 32);

            Quaternion quaternion = Quaternion.Euler(0, 0, 20);

            customParticleSystem.transform.rotation = quaternion;
            ParticleSystem particles = customParticleSystem.AddComponent <ParticleSystem>();

            Particles.InitParticleSystem(particles);

            ParticleSystem.MainModule mainParticle = particles.main;
            mainParticle.startLifetime = 2f;
            mainParticle.startSpeed    = 80;
            mainParticle.startSize     = 0.1f;
            mainParticle.maxParticles  = 2000;

            ParticleSystem.EmissionModule emissionModule = particles.emission;
            emissionModule.rateOverTime = 1000;

            var trails = particles.trails;

            trails.lifetime = 0.01f;
            trails.enabled  = true;

            var renderer = particles.GetComponent <ParticleSystemRenderer>();

            renderer.sortingLayerName = "Terrain";
            renderer.trailMaterial    = new Material(renderer.material);

            ParticleSystem.ShapeModule shapeModule = particles.shape;
            shapeModule.shapeType = ParticleSystemShapeType.SingleSidedEdge;
            shapeModule.radius    = 25;
            shapeModule.rotation  = new Vector3(0, 0, 180);

            StoryManager.city.Weather.Stormy();
        }
Beispiel #2
0
        /// <summary>
        /// Generates the particle effect when a demolision occurs
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        IEnumerator GenerateDestructionParticles(MapTile tile)
        {
            GameObject copyOfGameObject = GameObject.Instantiate(tile.Structure.GameObject);

            copyOfGameObject.name = "CopyStructures";
            copyOfGameObject.transform.SetParent(tile.Structure.GameObject.transform.parent.gameObject.transform);
            GameObject customParticleSystem = new GameObject("CustomDemolishParticle");

            customParticleSystem.transform.SetParent(copyOfGameObject.transform.parent, false);
            customParticleSystem.transform.position = copyOfGameObject.transform.position;
            ParticleSystem particles = customParticleSystem.AddComponent <ParticleSystem>();

            Particles.InitParticleSystem(particles);
            particles.Stop();

            copyOfGameObject.AddComponent <ShakerBehaviour>();

            ParticleSystem.MainModule mainModule = particles.main;
            mainModule.startColor    = Color.white;
            mainModule.startLifetime = 1;
            mainModule.startSize     = new ParticleSystem.MinMaxCurve(0.3f, 0.5f);
            mainModule.startSpeed    = 0.6f;
            mainModule.maxParticles  = 100;
            mainModule.loop          = false;
            mainModule.duration      = 1;

            ParticleSystem.ShapeModule shapeModule = particles.shape;
            shapeModule.shapeType = ParticleSystemShapeType.Sphere;
            shapeModule.angle     = 25;
            shapeModule.radius    = 0.8f;
            shapeModule.scale     = new Vector3(0.3f, 0.1f, 1);
            shapeModule.position  = new Vector3(0, -0.4f, 0);

            var emission = particles.emission;

            emission.rateOverTime = 30;
            emission.enabled      = true;

            var      colorOverLifetime = particles.colorOverLifetime;
            Gradient gradientLifetime  = new Gradient();

            GradientColorKey[] colorKeys = new GradientColorKey[2];
            colorKeys[0].color = Color.white;
            colorKeys[0].time  = 0.0f;
            colorKeys[1].color = Color.white;
            colorKeys[1].time  = 1.0f;
            GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2];
            alphaKeys[0].alpha = 1;
            alphaKeys[0].time  = 0.5f;
            alphaKeys[1].alpha = 0;
            alphaKeys[1].time  = 1.0f;
            gradientLifetime.SetKeys(colorKeys, alphaKeys);
            colorOverLifetime.color   = gradientLifetime;
            colorOverLifetime.enabled = true;

            var sizeOverLifetime = particles.sizeOverLifetime;

            sizeOverLifetime.size = new ParticleSystem.MinMaxCurve(1,
                                                                   new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(0.5f, 1.0f, 0, 0)));
            sizeOverLifetime.enabled = true;

            var limit = particles.limitVelocityOverLifetime;

            limit.separateAxes = true;
            limit.limitX       = 1;
            limit.limitY       = 0;
            limit.limitZ       = 0;
            limit.dampen       = 1;
            limit.enabled      = true;

            ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule = particles.textureSheetAnimation;
            textureSheetAnimationModule.enabled = true;
            textureSheetAnimationModule.mode    = ParticleSystemAnimationMode.Sprites;
            textureSheetAnimationModule.SetSprite(0, Resources.Load <Sprite>("Textures/CloudParticle"));

            Renderer renderer = particles.GetComponent <Renderer>();

            renderer.sortingLayerName = "Structure";
            renderer.sortingOrder     = 100;

            particles.Play();

            var existingSmoker = tile.Structure.GameObject.GetComponentInChildren <ParticleSystem>();

            if (existingSmoker != null)
            {
                var position = existingSmoker.transform.localPosition;
                var scale    = existingSmoker.transform.localScale;

                // Wait until structure does its unrendering.
                yield return(new WaitForEndOfFrame());

                // Copy over existing smoker and make them stay at their place relative to the world even when the building is falling.
                existingSmoker.transform.SetParent(copyOfGameObject.transform);
                existingSmoker.transform.localScale    = scale;
                existingSmoker.transform.localPosition = position;

                // Stop any existing smokers. Let their trail stay though.
                foreach (var smoker in copyOfGameObject.GetComponentsInChildren <ParticleSystem>())
                {
                    smoker.Stop();
                }
            }

            yield return(new WaitForSeconds(10));

            GameObject.Destroy(copyOfGameObject);
            GameObject.Destroy(customParticleSystem);
        }
        /// <summary>
        /// Creates the wind particles
        /// </summary>
        /// <param name="canvas"></param>
        public override void GenerateScene(GameObject canvas)
        {
            StoryManager.city.NextTurnEvent += StopWind;
            GameObject customParticleSystem = new GameObject("HurricaneParticle");

            customParticleSystem.transform.SetParent(StoryManager.city.Map.gameObject.transform, false);
            customParticleSystem.transform.position = new Vector3(0, 0, -2);

            Quaternion quaternion = Quaternion.Euler(0, 0, 0);

            customParticleSystem.transform.rotation = quaternion;
            ParticleSystem particles = customParticleSystem.AddComponent <ParticleSystem>();

            Particles.InitParticleSystem(particles);

            ParticleSystem.MainModule mainParticle = particles.main;
            mainParticle.startLifetime = 2f;
            mainParticle.startSpeed    = 0;
            mainParticle.startSize     = 0.5f;
            mainParticle.maxParticles  = 20;

            ParticleSystem.TrailModule trailMode = particles.trails;
            trailMode.enabled  = true;
            trailMode.lifetime = new ParticleSystem.MinMaxCurve(0.6f);
            AnimationCurve trailCurve = new AnimationCurve();

            trailCurve.AddKey(0, 0);
            trailCurve.AddKey(0.5f, 1);
            trailCurve.AddKey(1, 0);
            trailMode.widthOverTrail = new ParticleSystem.MinMaxCurve(1, trailCurve);


            ParticleSystem.EmissionModule emissionModule = particles.emission;
            emissionModule.rateOverTime = 3;
            ParticleSystemRenderer particleRenderer = particles.GetComponent <ParticleSystemRenderer>();

            particleRenderer.sortingLayerName = "Terrain";
            particleRenderer.trailMaterial    = Resources.Load <Material>("Wind");

            ParticleSystem.ShapeModule shapeModule = particles.shape;
            shapeModule.shapeType = ParticleSystemShapeType.Cone;
            shapeModule.radius    = 20;
            shapeModule.rotation  = new Vector3(0, 0, 180);

            ParticleSystem.VelocityOverLifetimeModule velocityOverLifetimeModule = particles.velocityOverLifetime;
            velocityOverLifetimeModule.enabled = true;

            // The below animation curves cause the loop effect
            AnimationCurve curveX = new AnimationCurve();

            curveX.AddKey(0, 10);
            curveX.AddKey(0.3f, 10);
            curveX.AddKey(0.5f, -10);
            curveX.AddKey(0.7f, 10);
            curveX.AddKey(1, 10);

            AnimationCurve curveY = new AnimationCurve();

            curveY.AddKey(0, 0);
            curveY.AddKey(0.3f, 0);
            curveY.AddKey(0.35f, 10);
            curveY.AddKey(0.65f, -10);
            curveY.AddKey(0.7f, 0);
            curveY.AddKey(1, 0);

            AnimationCurve curveZ = new AnimationCurve();

            curveZ.AddKey(0, 0);
            curveZ.AddKey(1.0f, 0);

            velocityOverLifetimeModule.x = new ParticleSystem.MinMaxCurve(1, curveX);
            velocityOverLifetimeModule.y = new ParticleSystem.MinMaxCurve(1, curveY);
            velocityOverLifetimeModule.z = new ParticleSystem.MinMaxCurve(0, curveZ);

            ParticleSystem.ColorOverLifetimeModule colorOverLifetimeModule = particles.colorOverLifetime;
            colorOverLifetimeModule.enabled = true;
            Gradient gradient = new Gradient();

            gradient.SetKeys(new [] { new GradientColorKey(Color.white, 0.0f),
                                      new GradientColorKey(Color.white, 1.0f) },
                             new [] { new GradientAlphaKey(1.0f, 0.0f),
                                      new GradientAlphaKey(0.0f, 1.0f) });
            colorOverLifetimeModule.color = gradient;

            ParticleSystem.SizeOverLifetimeModule sizeOverLifetimeModule = particles.sizeOverLifetime;
            sizeOverLifetimeModule.enabled = true;
            AnimationCurve velocityCurveX = new AnimationCurve();

            velocityCurveX.AddKey(0, 0);
            velocityCurveX.AddKey(0.4f, 0.3f);
            velocityCurveX.AddKey(0.55f, 0.85f);
            velocityCurveX.AddKey(0.75f, 0.85f);
            velocityCurveX.AddKey(0.85f, 0.6f);
            velocityCurveX.AddKey(1, 0);
            AnimationCurve velocityCurveY = new AnimationCurve();

            velocityCurveY.AddKey(0, 0);
            velocityCurveY.AddKey(1, 0);
            AnimationCurve velocityCurveZ = new AnimationCurve();

            velocityCurveZ.AddKey(0, 0);
            velocityCurveZ.AddKey(1, 0);

            sizeOverLifetimeModule.x = new ParticleSystem.MinMaxCurve(1, velocityCurveX);
            sizeOverLifetimeModule.y = new ParticleSystem.MinMaxCurve(0, velocityCurveY);
            sizeOverLifetimeModule.z = new ParticleSystem.MinMaxCurve(0, velocityCurveZ);

            StoryManager.city.Weather.Windy();
        }
Beispiel #4
0
        private void GenerateWindEffect(MapTile tile)
        {
            GameObject air = new GameObject();

            air.transform.SetParent(tile.Structure.GameObject.transform);
            air.transform.localPosition = new Vector3(1f, -0.5f, -4.5f);
            air.transform.localScale    = new Vector3(0.5f, 0.5f, 1);

            ParticleSystem particles = air.AddComponent <ParticleSystem>();

            Particles.InitParticleSystem(particles);

            ParticleSystem.MainModule mainParticle = particles.main;
            mainParticle.startLifetime = 1.5f;
            mainParticle.startSpeed    = 0;
            mainParticle.startSize     = 0.1f;
            mainParticle.maxParticles  = 5;


            ParticleSystem.TrailModule trailMode = particles.trails;
            trailMode.enabled          = true;
            trailMode.lifetime         = new ParticleSystem.MinMaxCurve(0.8f);
            trailMode.dieWithParticles = false;
            AnimationCurve trailCurve = new AnimationCurve();

            trailCurve.AddKey(0, 0);
            trailCurve.AddKey(0.5f, 1);
            trailCurve.AddKey(1, 0);
            trailMode.widthOverTrail = new ParticleSystem.MinMaxCurve(1, trailCurve);


            ParticleSystem.EmissionModule emissionModule = particles.emission;
            emissionModule.rateOverTime = 3;
            ParticleSystemRenderer particleRenderer = particles.GetComponent <ParticleSystemRenderer>();

            particleRenderer.trailMaterial = Resources.Load <Material>("Wind");


            ParticleSystem.ShapeModule shapeModule = particles.shape;
            shapeModule.shapeType = ParticleSystemShapeType.Box;
            shapeModule.rotation  = new Vector3(0, 0, 180);
            shapeModule.scale     = new Vector3(0.1f, 1, 1);

            ParticleSystem.VelocityOverLifetimeModule velocityOverLifetimeModule = particles.velocityOverLifetime;
            velocityOverLifetimeModule.enabled = true;

            AnimationCurve curveX = new AnimationCurve();

            curveX.AddKey(0, 1);
            curveX.AddKey(1, 1);

            AnimationCurve curveY = new AnimationCurve();

            curveY.AddKey(0, 0);
            curveY.AddKey(0.33f, 1);
            curveY.AddKey(0.66f, -1);
            curveY.AddKey(1, 0);

            AnimationCurve curveZ = new AnimationCurve();

            curveZ.AddKey(0, 0);
            curveZ.AddKey(1.0f, 0);

            //velocityOverLifetimeModule.space = ParticleSystemSimulationSpace.Local;
            velocityOverLifetimeModule.x = new ParticleSystem.MinMaxCurve(1, curveX);
            velocityOverLifetimeModule.y = new ParticleSystem.MinMaxCurve(1, curveY);
            velocityOverLifetimeModule.z = new ParticleSystem.MinMaxCurve(0, curveZ);

            ParticleSystem.ColorOverLifetimeModule colorOverLifetimeModule = particles.colorOverLifetime;
            colorOverLifetimeModule.enabled = true;
            Gradient gradient = new Gradient();

            gradient.SetKeys(new [] { new GradientColorKey(new Color32(167, 232, 242, 255), 0.0f),
                                      new GradientColorKey(Color.white, 1.0f) },
                             new [] { new GradientAlphaKey(1.0f, 0.0f),
                                      new GradientAlphaKey(0.0f, 1.0f) });
            colorOverLifetimeModule.color = gradient;
        }
        public override void RenderOnto(GameObject canvas, Vector3 position)
        {
            if (Tile.Terrain.TerrainType == Terrain.TerrainTypes.DesertHill ||
                Tile.Terrain.TerrainType == Terrain.TerrainTypes.GrassHill)
            {
                Vector3 positionNew = new Vector3(position.x, position.y + 0.3f, position.z);
                RenderOntoSprite(canvas, positionNew, "Textures/structures/powerPlant", new Vector2(1, 1.5f));
            }
            else
            {
                Vector3 positionNew = new Vector3(position.x, position.y + 0.15f, position.z);
                RenderOntoSprite(canvas, positionNew, "Textures/structures/powerPlant", new Vector2(1, 1.5f));
            }

            // Render smoke.
            if (smoke != null)
            {
                // Reuse existing smoke.
                smoke.transform.SetParent(GameObject.transform);
                smoke.transform.localPosition = new Vector3(-0.23f, 0.55f);
                smoke.transform.localScale    = new Vector3(1, 1, 1);
            }
            else
            {
                smoke = new GameObject();
                smoke.transform.SetParent(GameObject.transform);
                smoke.transform.localPosition = new Vector3(-0.23f, 0.55f);
                smoke.transform.localScale    = new Vector3(1, 1, 1);

                ParticleSystem particles = smoke.AddComponent <ParticleSystem>();
                Particles.InitParticleSystem(particles);

                var main = particles.main;
                main.startLifetime = 5;
                main.startSize     = 1;
                main.startSpeed    = 1;
                main.startColor    = new Color(221, 221, 221);
                main.maxParticles  = 40;

                var emission = particles.emission;
                emission.rateOverTime = 3;
                emission.enabled      = true;

                var shape = particles.shape;
                shape.angle    = 10;
                shape.radius   = 0.0001f;
                shape.rotation = new Vector3(-90, 90, 0);
                shape.scale    = new Vector3(0.05f, 0.05f, 0.05f);
                shape.enabled  = true;

                var limit = particles.limitVelocityOverLifetime;
                limit.limit  = 1;
                limit.dampen = 1;
                limit.multiplyDragByParticleSize     = false;
                limit.multiplyDragByParticleVelocity = true;
                limit.drag    = 4;
                limit.enabled = true;

                var force = particles.forceOverLifetime;
                force.x          = new ParticleSystem.MinMaxCurve(0.15f, 0.2f);
                force.y          = new ParticleSystem.MinMaxCurve(-0.45f, 0.5f);
                force.randomized = true;
                force.enabled    = true;

                var                colorOverLifetime = particles.colorOverLifetime;
                Gradient           gradientLifetime  = new Gradient();
                GradientColorKey[] colorKeys         = new GradientColorKey[2];
                colorKeys[0].color = new Color(178, 178, 178);
                colorKeys[0].time  = 0.0f;
                colorKeys[1].color = Color.white;
                colorKeys[1].time  = 0.1f;
                GradientAlphaKey[] alphaKeys = new GradientAlphaKey[4];
                alphaKeys[0].alpha = 0;
                alphaKeys[0].time  = 0;
                alphaKeys[1].alpha = 1;
                alphaKeys[1].time  = 0.15f;
                alphaKeys[2].alpha = 1;
                alphaKeys[2].time  = 0.5f;
                alphaKeys[3].alpha = 0;
                alphaKeys[3].time  = 1.0f;
                gradientLifetime.SetKeys(colorKeys, alphaKeys);
                colorOverLifetime.color   = gradientLifetime;
                colorOverLifetime.enabled = true;

                var sizeOverLifetime = particles.sizeOverLifetime;
                sizeOverLifetime.size = new ParticleSystem.MinMaxCurve(1,
                                                                       new AnimationCurve(new Keyframe(0.0f, 0.12f), new Keyframe(0.025f, 0.45f, 5, 5), new Keyframe(0.2f, 0.7f)));
                sizeOverLifetime.enabled = true;

                var renderer = smoke.GetComponent <ParticleSystemRenderer>();
                renderer.sortingLayerName = "Structure";
                renderer.sortingOrder     = 1000;
                Material material = new Material(renderer.material);
                material.mainTexture = Resources.Load <Texture>("Textures/CloudParticle");
                renderer.material    = material;
            }
        }