Ejemplo n.º 1
0
        protected override void GetDepsFromImpl(object obj, GetDepsFromContext context)
        {
            base.GetDepsFromImpl(obj, context);
            ParticleSystemForceField uo = (ParticleSystemForceField)obj;

            AddDep(uo.vectorField, context);
        }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        UnitFrame?.Move(this);
        if (UnitFrame.NextMove?.MoveType == MoveType.Extract)
        {
            ParticleSystem particleSource;

            Position from       = UnitFrame.NextMove.Positions[1];
            HexCell  sourceCell = UnitFrame.HexGrid.GroundCells[from];

            particleSource = UnitFrame.HexGrid.MakeParticleSource("ExtractSource");
            particleSource.transform.SetParent(sourceCell.Cell.transform, false);

            Position to         = UnitFrame.NextMove.Positions[0];
            HexCell  targetCell = UnitFrame.HexGrid.GroundCells[to];

            ParticleSystemForceField particleTarget = UnitFrame.HexGrid.MakeParticleTarget();
            particleTarget.transform.SetParent(targetCell.Cell.transform, false);

            Vector3 unitPos3 = particleTarget.transform.position;
            unitPos3.y += 0.1f;
            particleTarget.transform.position = unitPos3;

            particleSource.externalForces.SetInfluence(0, particleTarget);
            HexGrid.Destroy(particleTarget, 2.5f);

            particleSource.Play();

            UnitFrame.NextMove = null;
        }
    }
    public particleSystemFigure7(Vector3 particleSystemLocation, float startSpeed, float lifeTime, int maxParticles, ParticleSystemForceField repeller)
    {
        //Create the GameObject in the constructor
        particleSystemGameObject = new GameObject();
        //Move the GameObject to the right position
        particleSystemGameObject.transform.position = particleSystemLocation;
        //Add the particle system
        particleSystemComponent = particleSystemGameObject.AddComponent <ParticleSystem>();
        this.repeller           = repeller;

        //Now we need to gather the interfaces of our ParticleSystem
        //The main interface covers general properties
        var main = particleSystemComponent.main;
        //The colorOverLifetime interfaces manages the color of the objects over their lifetime.
        var colorOverLifetime = particleSystemComponent.colorOverLifetime;

        //In the Main Interface we'll sat the initial start LifeTime (how long a single particle will live)
        //And, of course, we'll set our Max Particles
        main.startLifetime = lifeTime;
        main.startSpeed    = startSpeed;
        main.maxParticles  = maxParticles;

        //Now we can simply turn gravity on
        main.gravityModifier = 1f;

        //Let's add external forces
        externalForceModule();
        colorModule();
    }
Ejemplo n.º 4
0
        override public void OnSceneViewGUI()
        {
            using (new Handles.DrawingScope(Handles.matrix))
            {
                ParticleSystemForceField[] forceFields = ParticleSystemForceField.FindAll();
                foreach (ParticleSystemForceField ff in forceFields)
                {
                    bool valid = false;
                    foreach (ParticleSystem ps in m_ParticleSystemUI.m_ParticleSystems)
                    {
                        if (ps.externalForces.IsAffectedBy(ff))
                        {
                            valid = true;
                            break;
                        }
                    }
                    if (!valid)
                    {
                        continue;
                    }

                    ParticleSystemForceFieldInspector.DrawHandle(ff);
                }
            }
        }
Ejemplo n.º 5
0
        protected override object WriteToImpl(object obj)
        {
            obj = base.WriteToImpl(obj);
            ParticleSystemForceField uo = (ParticleSystemForceField)obj;

            uo.shape                          = shape;
            uo.startRange                     = startRange;
            uo.endRange                       = endRange;
            uo.length                         = length;
            uo.gravityFocus                   = gravityFocus;
            uo.rotationRandomness             = rotationRandomness;
            uo.multiplyDragByParticleSize     = multiplyDragByParticleSize;
            uo.multiplyDragByParticleVelocity = multiplyDragByParticleVelocity;
            uo.vectorField                    = FromID(vectorField, uo.vectorField);
            uo.directionX                     = directionX;
            uo.directionY                     = directionY;
            uo.directionZ                     = directionZ;
            uo.gravity                        = gravity;
            uo.rotationSpeed                  = rotationSpeed;
            uo.rotationAttraction             = rotationAttraction;
            uo.drag                  = drag;
            uo.vectorFieldSpeed      = vectorFieldSpeed;
            uo.vectorFieldAttraction = vectorFieldAttraction;
            return(uo);
        }
    public repeller()
    {
        // Create the components required for the mover
        gameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        gameObject.transform.position = new Vector3(0, -6f, 0);
        body = gameObject.AddComponent <Rigidbody>();
        gameObject.GetComponent <SphereCollider>().enabled = false;
        Object.Destroy(gameObject.GetComponent <SphereCollider>());

        //We need to create a new material for WebGL
        Renderer r = body.GetComponent <Renderer>();

        r.material       = new Material(Shader.Find("Diffuse"));
        r.material.color = Color.red;

        //Turn off gravity for this object
        body.useGravity = false;

        //Now let's add our Particle System Force Field Component
        repelField       = gameObject.AddComponent <ParticleSystemForceField>();
        repelField.shape = ParticleSystemForceFieldShape.Sphere;
        //To repel the object away. We make the strength negative because unity doesn't differentiate the direction of a gravitational force
        //in the way we are doing it
        repelField.gravity = -repellerStrength;
        //We set a range for the field
        repelField.endRange = 2 * repelField.transform.localScale.x;
    }
Ejemplo n.º 7
0
 // Start is called before the first frame update
 protected override void Start()
 {
     name   = "FireFly";
     energy = 1000;
     minimumEnergySourceTemp = 0f;
     particleForceField      = GetComponent <ParticleSystemForceField>();
     base.Start();
 }
Ejemplo n.º 8
0
    public ParticleSystemForceField MakeParticleTarget()
    {
        ParticleSystemForceField extractPrefab = Resources.Load <ParticleSystemForceField>("Particles\\" + "ExtractTarget");
        ParticleSystemForceField extract;

        extract = Instantiate(extractPrefab);
        return(extract);
    }
Ejemplo n.º 9
0
        public override void Init()
        {
            _targetProvider = GetComponentInParent <ITargetProvider>();
            _targeter       = GetComponentInParent <ITargeter>();

            _beamStart          = transform.Find("BeamStart");
            _beam               = transform.Find("Beam").GetComponent <LineRenderer>();
            _particleForceField = GetComponentInChildren <ParticleSystemForceField>();
        }
Ejemplo n.º 10
0
 // Start is called before the first frame update
 void Start()
 {
     emissionModule = bladeTip.GetComponent <ParticleSystem>().emission;
     bladeSystem    = bladeTip.GetComponent <ParticleSystem>();
     Debug.Log("rate over time of emission module: " + emissionModule.rateOverTime.constant);
     charge = 0;
     //bladeBuffer = new ParticleSystem.Particle[bladeSystem.main.maxParticles];
     forceField = gameObject.GetComponent <ParticleSystemForceField>();
 }
Ejemplo n.º 11
0
 void Start()
 {
     rotationAxis  = new Vector3(0, 1, 0);
     myGravity     = GetComponentInChildren <ParticleSystemForceField>();
     myWorld       = GetComponentsInParent <UniverseUmpire>()[0];
     finalPosition = 150 * Random.insideUnitSphere;
     myWorld.finalStarDistances.Add(finalPosition.magnitude);
     myGravity.endRange = 0;
     InvokeRepeating("expandGravity", 8.5f, 20.0f);
 }
Ejemplo n.º 12
0
        private void Awake()
        {
            _forceField = GetComponentInChildren <ParticleSystemForceField>();
            var vField = _forceField.vectorField;

            _ffSizeX     = vField.width;
            _ffSizeY     = vField.height;
            _ffSizeZ     = vField.depth;
            _vectorField = vField.GetPixels();
        }
Ejemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        UnitFrame?.Move(this);

        if (UnitFrame?.NextMove?.MoveType == MoveType.Upgrade)
        {
            if (UnitFrame.NextMove?.MoveType == MoveType.Upgrade &&
                UnitFrame.NextMove?.Stats != null)
            {
                UnitFrame.MoveUpdateStats = UnitFrame.NextMove.Stats;
                UnitFrame.Assemble();
            }

            if (particleSource == null)
            {
                Position from       = UnitFrame.NextMove.Positions[0];
                HexCell  sourceCell = UnitFrame.HexGrid.GroundCells[from];

                particleSource = UnitFrame.HexGrid.MakeParticleSource("ExtractSource");
                particleSource.transform.SetParent(sourceCell.Cell.transform, false);
            }

            Position to         = UnitFrame.NextMove.Positions[UnitFrame.NextMove.Positions.Count - 1];
            HexCell  targetCell = UnitFrame.HexGrid.GroundCells[to];

            ParticleSystemForceField particleTarget = UnitFrame.HexGrid.MakeParticleTarget();
            particleTarget.transform.SetParent(targetCell.Cell.transform, false);

            Vector3 unitPos3 = particleTarget.transform.position;
            unitPos3.y += 0.1f;
            particleTarget.transform.position = unitPos3;

            particleSource.externalForces.SetInfluence(0, particleTarget);
            HexGrid.Destroy(particleTarget, 2.5f);

            particleSource.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
            var main = particleSource.main;
            main.duration = particleSource.main.duration * UnitFrame.HexGrid.GameSpeed;

            //particleSource.main.duration = particleSource.main.duration * UnitFrame.HexGrid.GameSpeed;
            particleSource.Play();

            ParticleSystem particleDust = UnitFrame.HexGrid.MakeParticleSource("Build");
            particleDust.transform.SetParent(targetCell.Cell.transform, false);
            particleDust.transform.position = particleTarget.transform.position;

            particleDust.Play();
            HexGrid.Destroy(particleDust, 2.5f);

            UnitFrame.NextMove = null;
        }
    }
Ejemplo n.º 14
0
 // Start is called before the first frame update
 void Awake()
 {
     Segments = new List <BirdhouseSegment>(GetComponentsInChildren <BirdhouseSegment>());
     foreach (BirdhouseSegment segment in Segments)
     {
         segment.Birdhouse = this;
     }
     AudioSource       = GetComponent <AudioSource>();
     Light             = GetComponentInChildren <Light>();
     ForceField        = GetComponentInChildren <ParticleSystemForceField>();
     Animator          = GetComponentInChildren <Animator>();
     OriginalTransform = new CachedTransform(transform);
 }
Ejemplo n.º 15
0
        private static void DrawHemisphere(PropertyInfo radiusProp, ParticleSystemForceField target, float multiplyByRadius = 1.0f)
        {
            EditorGUI.BeginChangeCheck();

            float oldRadius = (float)radiusProp.GetValue(target, null) * multiplyByRadius;
            float newRadius = Handles.DoSimpleRadiusHandle(Quaternion.Euler(-90, 0, 0), Vector3.zero, oldRadius, true);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, string.Format(s_UndoString, ObjectNames.NicifyVariableName(target.GetType().Name)));
                radiusProp.SetValue(target, newRadius / multiplyByRadius, null);
            }
        }
        void OnSceneGUI()
        {
            EditorGUI.BeginChangeCheck();

            ParticleSystemForceField ff = (ParticleSystemForceField)target;

            DrawHandle(ff);

            if (EditorGUI.EndChangeCheck())
            {
                Repaint();
            }
        }
Ejemplo n.º 17
0
        private static void DrawBox(PropertyInfo extentProp, ParticleSystemForceField target, float multiplyByRadius = 1.0f)
        {
            s_BoxBoundsHandle.axes   = PrimitiveBoundsHandle.Axes.All;
            s_BoxBoundsHandle.center = Vector3.zero;
            s_BoxBoundsHandle.radius = (float)extentProp.GetValue(target, null) * multiplyByRadius;

            EditorGUI.BeginChangeCheck();
            s_BoxBoundsHandle.DrawHandle();
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, string.Format(s_UndoString, ObjectNames.NicifyVariableName(target.GetType().Name)));
                extentProp.SetValue(target, s_BoxBoundsHandle.radius / multiplyByRadius, null);
            }
        }
        public override void ReadFrom(object obj)
        {
            base.ReadFrom(obj);
            if (obj == null)
            {
                return;
            }

            ParticleSystem.ExternalForcesModule o = (ParticleSystem.ExternalForcesModule)obj;
            m_influences = new long[o.influenceCount];
            for (int i = 0; i < m_influences.Length; ++i)
            {
                ParticleSystemForceField forceField = o.GetInfluence(i);
                m_influences[i] = ToID(forceField);
            }
        }
    protected override void OnStartRunning()
    {
        manager    = GameObject.Find("Manager").GetComponent <Manager>();
        cellsCount = manager.CellsCount;
        mapSize    = new int2(manager.MapWidth, manager.MapHeight);
        weatherMat = manager.WeatherMat;

        temperatureColors  = manager.TemperatureColors;
        co2Colors          = manager.Co2Colors;
        temperatureTexture = new Texture2D(mapSize.x, mapSize.y, TextureFormat.RGBAFloat, true);

        temperatureDisplay = manager.TemperatureDisplay;
        temperatureDisplay.transform.localScale = new Vector3(mapSize.x, mapSize.y, 1f);
        temperatureDisplayRenderer = temperatureDisplay.GetComponent <Renderer>();

        co2Display = manager.Co2Display;
        co2Display.transform.localScale = new Vector3(mapSize.x, mapSize.y, 1f);
        co2DisplayRenderer = co2Display.GetComponent <Renderer>();

        particlesFF          = manager.ParticlesFF;
        particlesFF.endRange = mapSize.x / 2;

        motionVector2dTexture = new Texture2D(mapSize.x, mapSize.x, TextureFormat.RGBAFloat, true);
        firstIndex            = ((mapSize.x - mapSize.y) / 2) * mapSize.x;

        temperatureColorLookup = new NativeArray <Color>(256, Allocator.Persistent);
        for (int i = 0; i < 256; i++)
        {
            float val = i / 256.00f;
            Color c   = temperatureColors.Evaluate(val);

            temperatureColorLookup[i] = new Color(c.r, c.g, c.b, 1f);
        }
        co2ColorLookup = new NativeArray <Color>(256, Allocator.Persistent);
        for (int i = 0; i < 256; i++)
        {
            float val = i / 256.00f;
            Color c   = co2Colors.Evaluate(val);

            co2ColorLookup[i] = new Color(c.r, c.g, c.b, 1f);
        }
    }
Ejemplo n.º 20
0
    void Start()
    {
        // Create a Force Field
        var go = new GameObject("ForceField", typeof(ParticleSystemForceField));

        go.transform.position = new Vector3(0, 2, 0);
        go.transform.rotation = Quaternion.Euler(new Vector3(90.0f, 0.0f, 0.0f));

        m_ForceField = go.GetComponent <ParticleSystemForceField>();

        // Configure Particle System
        transform.position = new Vector3(0, -4, 0);
        transform.rotation = Quaternion.identity;
        var ps = GetComponent <ParticleSystem>();

        var main = ps.main;

        main.startSize    = new ParticleSystem.MinMaxCurve(0.05f, 0.2f);
        main.startSpeed   = new ParticleSystem.MinMaxCurve(1.5f, 2.5f);
        main.maxParticles = 100000;

        var emission = ps.emission;

        emission.rateOverTime = 0.0f;
        emission.burstCount   = 1;
        emission.SetBurst(0, new ParticleSystem.Burst(0.0f, 200, 200, -1, 0.1f));

        var shape = ps.shape;

        shape.shapeType             = ParticleSystemShapeType.SingleSidedEdge;
        shape.radius                = 5.0f;
        shape.radiusMode            = ParticleSystemShapeMultiModeValue.BurstSpread;
        shape.randomPositionAmount  = 0.1f;
        shape.randomDirectionAmount = 0.05f;

        var forces = ps.externalForces;

        forces.enabled = true;
    }
        public override object WriteTo(object obj)
        {
            obj = base.WriteTo(obj);
            if (obj == null)
            {
                return(null);
            }

            ParticleSystem.ExternalForcesModule o = (ParticleSystem.ExternalForcesModule)obj;
            if (m_influences != null)
            {
                for (int i = 0; i < m_influences.Length; ++i)
                {
                    ParticleSystemForceField forceField = FromID <ParticleSystemForceField>(m_influences[i]);
                    if (forceField != null)
                    {
                        o.AddInfluence(forceField);
                    }
                }
            }

            return(obj);
        }
Ejemplo n.º 22
0
        protected override void ReadFromImpl(object obj)
        {
            base.ReadFromImpl(obj);
            ParticleSystemForceField uo = (ParticleSystemForceField)obj;

            shape                          = uo.shape;
            startRange                     = uo.startRange;
            endRange                       = uo.endRange;
            length                         = uo.length;
            gravityFocus                   = uo.gravityFocus;
            rotationRandomness             = uo.rotationRandomness;
            multiplyDragByParticleSize     = uo.multiplyDragByParticleSize;
            multiplyDragByParticleVelocity = uo.multiplyDragByParticleVelocity;
            vectorField                    = ToID(uo.vectorField);
            directionX                     = uo.directionX;
            directionY                     = uo.directionY;
            directionZ                     = uo.directionZ;
            gravity                        = uo.gravity;
            rotationSpeed                  = uo.rotationSpeed;
            rotationAttraction             = uo.rotationAttraction;
            drag                  = uo.drag;
            vectorFieldSpeed      = uo.vectorFieldSpeed;
            vectorFieldAttraction = uo.vectorFieldAttraction;
        }
Ejemplo n.º 23
0
 public static Tween TweenRotationRandomness(this ParticleSystemForceField forceField, Vector2 to, float duration) =>
 Tweening.To(getter: () => forceField.rotationRandomness,
             setter: rotationRandomness => forceField.rotationRandomness = rotationRandomness,
             to, duration).SetTarget(forceField);
Ejemplo n.º 24
0
 public static Tween TweenEndRange(this ParticleSystemForceField forceField, float to, float duration) =>
 Tweening.To(getter: () => forceField.endRange,
             setter: endRange => forceField.endRange = endRange,
             to, duration).SetTarget(forceField);
Ejemplo n.º 25
0
 public static Tween TweenLength(this ParticleSystemForceField forceField, float to, float duration) =>
 Tweening.To(getter: () => forceField.length,
             setter: length => forceField.length = length,
             to, duration).SetTarget(forceField);
Ejemplo n.º 26
0
 public static Tween TweenGravityFocus(this ParticleSystemForceField forceField, float to, float duration) =>
 Tweening.To(getter: () => forceField.gravityFocus,
             setter: gravityFocus => forceField.gravityFocus = gravityFocus,
             to, duration).SetTarget(forceField);
 private void Awake()
 {
     particleSystem           = GetComponent <ParticleSystem>();
     particleSystemForceField = GetComponent <ParticleSystemForceField>();
 }
Ejemplo n.º 28
0
        private static void DrawCylinder(PropertyInfo radiusProp, PropertyInfo lengthProp, ParticleSystemForceField target, float multiplyByRadius = 1.0f)
        {
            float lengthHalf = (float)lengthProp.GetValue(target, null) * 0.5f;

            // Circle at each end
            for (int i = 0; i < 2; i++)
            {
                s_SphereBoundsHandle.axes   = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Z;
                s_SphereBoundsHandle.center = new Vector3(0.0f, (i > 0) ? -lengthHalf : lengthHalf, 0.0f);
                s_SphereBoundsHandle.radius = (float)radiusProp.GetValue(target, null) * multiplyByRadius;

                EditorGUI.BeginChangeCheck();
                s_SphereBoundsHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(target, string.Format(s_UndoString, ObjectNames.NicifyVariableName(target.GetType().Name)));
                    radiusProp.SetValue(target, s_SphereBoundsHandle.radius / multiplyByRadius, null);
                }
            }

            // Handle at each end for controlling the length
            EditorGUI.BeginChangeCheck();
            lengthHalf = Handles.SizeSlider(Vector3.zero, Vector3.up, lengthHalf);
            lengthHalf = Handles.SizeSlider(Vector3.zero, -Vector3.up, lengthHalf);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, string.Format(s_UndoString, ObjectNames.NicifyVariableName(target.GetType().Name)));
                lengthProp.SetValue(target, Mathf.Max(0.0f, lengthHalf * 2.0f), null);
            }

            // Connecting lines
            float lineRadius = (float)radiusProp.GetValue(target, null) * multiplyByRadius;

            Handles.DrawLine(new Vector3(lineRadius, lengthHalf, 0.0f), new Vector3(lineRadius, -lengthHalf, 0.0f));
            Handles.DrawLine(new Vector3(-lineRadius, lengthHalf, 0.0f), new Vector3(-lineRadius, -lengthHalf, 0.0f));
            Handles.DrawLine(new Vector3(0.0f, lengthHalf, lineRadius), new Vector3(0.0f, -lengthHalf, lineRadius));
            Handles.DrawLine(new Vector3(0.0f, lengthHalf, -lineRadius), new Vector3(0.0f, -lengthHalf, -lineRadius));
        }
 private void Start()
 {
     forceField = GetComponent <ParticleSystemForceField>();
 }
Ejemplo n.º 30
0
        public static void DrawHandle(ParticleSystemForceField ff)
        {
            using (new Handles.DrawingScope(s_GizmoColor, ff.transform.localToWorldMatrix))
            {
                ParticleSystemForceFieldShape forceShape = ff.shape;
                if (forceShape == ParticleSystemForceFieldShape.Sphere)
                {
                    DrawSphere(s_EndRangeProperty, ff);

                    if (ff.startRange > 0.0f)
                    {
                        DrawSphere(s_StartRangeProperty, ff);
                    }

                    if (ff.gravityFocus > 0.0f)
                    {
                        using (new Handles.DrawingScope(s_GizmoColor * s_GizmoFocusTint))
                            DrawSphere(s_GravityFocusProperty, ff, ff.endRange);
                    }
                }
                else if (forceShape == ParticleSystemForceFieldShape.Hemisphere)
                {
                    DrawHemisphere(s_EndRangeProperty, ff);

                    if (ff.startRange > 0.0f)
                    {
                        DrawHemisphere(s_StartRangeProperty, ff);
                    }

                    if (ff.gravityFocus > 0.0f)
                    {
                        using (new Handles.DrawingScope(s_GizmoColor * s_GizmoFocusTint))
                            DrawHemisphere(s_GravityFocusProperty, ff, ff.endRange);
                    }
                }
                else if (forceShape == ParticleSystemForceFieldShape.Cylinder)
                {
                    DrawCylinder(s_EndRangeProperty, s_LengthProperty, ff);

                    if (ff.startRange > 0.0f)
                    {
                        DrawCylinder(s_StartRangeProperty, s_LengthProperty, ff);
                    }

                    if (ff.gravityFocus > 0.0f)
                    {
                        using (new Handles.DrawingScope(s_GizmoColor * s_GizmoFocusTint))
                            DrawCylinder(s_GravityFocusProperty, s_LengthProperty, ff, ff.endRange);
                    }
                }
                else if (forceShape == ParticleSystemForceFieldShape.Box)
                {
                    DrawBox(s_EndRangeProperty, ff);

                    if (ff.startRange > 0.0f)
                    {
                        DrawBox(s_StartRangeProperty, ff);
                    }

                    if (ff.gravityFocus > 0.0f)
                    {
                        using (new Handles.DrawingScope(s_GizmoColor * s_GizmoFocusTint))
                            DrawBox(s_GravityFocusProperty, ff, ff.endRange);
                    }
                }
            }
        }