예제 #1
0
    void ApplyGravity(GravityAffector affector, GravityEffected effected)
    {
        Rigidbody2D rb     = effected.GetComponent <Rigidbody2D>();
        float       distSq = Mathf.Pow(Vector2.Distance(affector.transform.position, effected.transform.position), 2);
        Vector2     dir    = affector.transform.position - effected.transform.position;

        dir = dir.normalized * (G * affector.GetMass() * effected.GetMass() / distSq);
        if (dir.magnitude > minimumForceThreshold)
        {
            rb.AddForce(dir);
        }
    }
    public void TestGravity() {
      GravityAffector<SimpleParticle> affector = new GravityAffector<SimpleParticle>(
        SimpleParticleModifier.Default
      );

      SimpleParticle[/*100*/] particles = new SimpleParticle[100];
      affector.Affect(particles, 25, 50, (int)affector.UpdatesPerSecond);

      for(int index = 0; index < 25; ++index) {
        Assert.AreEqual(Vector3.Zero, particles[index].Velocity);
      }
      for(int index = 25; index < 50; ++index) {
        Assert.AreEqual(affector.Gravity, particles[index].Velocity);
      }
      for(int index = 75; index < 100; ++index) {
        Assert.AreEqual(Vector3.Zero, particles[index].Velocity);
      }
    }
예제 #3
0
    private void HandleGravityProperties(GameObject gameObject, IDictionary <string, string> customProperties)
    {
        GravityAffector gravity = gameObject.AddComponent <GravityAffector>();

        // Jump Height
        if (customProperties.ContainsKey("jumpheight"))
        {
            float val = -1;
            try
            {
                val = (float)System.Convert.ToDouble(customProperties["jumpheight"]);
            }
            catch (System.FormatException)
            {
                val = -1;
                Debug.LogError("jumpheight property formatted improperly");
            }

            if (val >= 0)
            {
                gravity.jumpHeight = val;
            }
        }

        // Time to Apex
        if (customProperties.ContainsKey("timetoapex"))
        {
            float val = -1;
            try
            {
                val = (float)System.Convert.ToDouble(customProperties["timetoapex"]);
            }
            catch (System.FormatException)
            {
                val = -1;
                Debug.LogError("timetoapex property formatted improperly");
            }

            if (val >= 0)
            {
                gravity.timeToApex = val;
            }
        }
    }
예제 #4
0
 public void SetArractionAffectorGoal(Transform goal)
 {
     if (GravityAffectorEnable == false || GravityAftType == GAFTTYPE.Planar)
     {
         Debug.LogWarning(gameObject.name + "has no attraction affector, please check it");
         return;
     }
     foreach (EffectNode en in AvailableENodes)
     {
         List <Affector> affectorList = en.GetAffectorList();
         foreach (Affector aft in affectorList)
         {
             if (aft.Type == AFFECTORTYPE.GravityAffector)
             {
                 GravityAffector atft = (GravityAffector)aft;
                 atft.SetAttraction(goal);
             }
         }
     }
 }
예제 #5
0
    protected List <Affector> InitAffectors(EffectNode node)
    {
        List <Affector> AffectorList = new List <Affector>();

        if (UVAffectorEnable)
        {
            UVAnimation uvAnim = new UVAnimation();
            if (UVType == 1)
            {
                float   perWidth  = OriUVDimensions.x / Cols;
                float   perHeight = Mathf.Abs(OriUVDimensions.y / Rows);
                Vector2 cellSize  = new Vector2(perWidth, perHeight);
                uvAnim.BuildUVAnim(OriTopLeftUV, cellSize, Cols, Rows, Cols * Rows);
            }
            UVDimension = uvAnim.UVDimensions[0];
            UVTopLeft   = uvAnim.frames[0];

            if (uvAnim.frames.Length != 1)
            {
                uvAnim.loopCycles = LoopCircles;
                Affector aft = new UVAffector(uvAnim, UVTime, node, RandomStartFrame);
                AffectorList.Add(aft);
            }
        }
        else
        {
            UVDimension = OriUVDimensions;
            UVTopLeft   = OriTopLeftUV;
        }


        if (RotAffectorEnable && RotateType != RSTYPE.NONE)
        {
            Affector aft;
            if (RotateType == RSTYPE.CURVE)
            {
                aft = new RotateAffector(RotateCurve, node);
            }
            else
            {
                aft = new RotateAffector(DeltaRot, node);
            }
            AffectorList.Add(aft);
        }
        if (ScaleAffectorEnable && ScaleType != RSTYPE.NONE)
        {
            Affector aft;

            if (UseSameScaleCurve)
            {
                ScaleYCurve = ScaleXCurve;
            }

            if (ScaleType == RSTYPE.CURVE)
            {
                aft = new ScaleAffector(ScaleXCurve, ScaleYCurve, node);
            }
            else
            {
                aft = new ScaleAffector(DeltaScaleX, DeltaScaleY, node);
            }
            AffectorList.Add(aft);
        }
        if (ColorAffectorEnable /*&& ColorAffectType != 0*/)
        {
            ColorAffector aft = new ColorAffector(this, node);
            AffectorList.Add(aft);
        }
        if (JetAffectorEnable)
        {
            Affector aft = new JetAffector(JetMag, JetMagType, JetCurve, node);
            AffectorList.Add(aft);
        }
        if (VortexAffectorEnable)
        {
            Affector aft;
            aft = new VortexAffector(VortexObj, VortexMagType, VortexMag, VortexCurve, VortexDirection, VortexInheritRotation, node);

            AffectorList.Add(aft);
        }
        if (UVRotAffectorEnable)
        {
            Affector aft;

            float xscroll = UVRotXSpeed;
            float yscroll = UVRotYSpeed;
            if (RandomUVRotateSpeed)
            {
                xscroll = Random.Range(UVRotXSpeed, UVRotXSpeedMax);
                yscroll = Random.Range(UVRotYSpeed, UVRotYSpeedMax);
            }

            aft = new UVRotAffector(xscroll, yscroll, node);
            AffectorList.Add(aft);
        }


        if (GravityAffectorEnable)
        {
            Affector aft;
            aft = new GravityAffector(GravityObject, GravityAftType, GravityMagType, IsGravityAccelerate, GravityDirection, GravityMag, GravityCurve, node);
            AffectorList.Add(aft);

            if (GravityAftType == GAFTTYPE.Spherical && GravityObject == null)
            {
                Debug.LogWarning("Gravity Object is missing, automatically set to effect layer self:" + gameObject.name);
                GravityObject = transform;
            }
        }
        if (AirAffectorEnable)
        {
            Affector aft = new AirFieldAffector(AirObject, AirDirection, AirMagType, AirMagnitude, AirMagCurve, AirAttenuation, AirUseMaxDistance,
                                                AirMaxDistance, AirEnableSpread, AirSpread, AirInheritVelocity, AirInheritRotation, node);
            AffectorList.Add(aft);
        }
        if (BombAffectorEnable)
        {
            Affector aft = new BombAffector(BombObject, BombType, BombMagType, BombDecayType, BombMagnitude, BombMagCurve, BombDecay, BombAxis, node);
            AffectorList.Add(aft);
        }
        if (TurbulenceAffectorEnable)
        {
            Affector aft = new TurbulenceFieldAffector(TurbulenceObject, TurbulenceMagType, TurbulenceMagnitude, TurbulenceMagCurve, TurbulenceAttenuation, TurbulenceUseMaxDistance, TurbulenceMaxDistance, node);
            AffectorList.Add(aft);
        }
        if (DragAffectorEnable)
        {
            Affector aft = new DragAffector(DragObj, DragUseDir, DragDir, DragMag, DragUseMaxDist, DragMaxDist, DragAtten, node);
            AffectorList.Add(aft);
        }
        return(AffectorList);
    }
예제 #6
0
    void Update()
    {
        layers = WeatherManager.getWeatherLayer(WeatherManager.Instance.checkCurrentWeather(gameObject)) | 1 << LayerMask.NameToLayer("Default");
        //LayerMask.
        //WeatherManager.WeatherType w = (WeatherManager.WeatherType)WeatherManager.Instance.checkCurrentWeather(gameObject);
        //string weatherString = "";
        //switch (w)
        //{
        //    case WeatherManager.WeatherType.sun:
        //        weatherString = "Sun";
        //        break;
        //    case WeatherManager.WeatherType.snow:
        //        weatherString = "Snow";
        //        break;
        //    case WeatherManager.WeatherType.rain:
        //        weatherString = "Rain";
        //        break;
        //}

        //layers = LayerMask.GetMask("Default", weatherString);

        Vector3    pos      = transform.position;
        Vector3    inc      = Vector2.one * 0.01f;
        Collider2D collider = GetComponent <Collider2D>();
        Vector2    topRight = collider.bounds.center - collider.bounds.extents; //pos - GetComponent<Collider2D>().bounds.extents - inc;
        Vector2    botLeft  = collider.bounds.center + collider.bounds.extents; //pos + GetComponent<Collider2D>().bounds.extents + inc;

        Collider2D[] colliders = Physics2D.OverlapAreaAll(topRight, botLeft, layers);

        // Forces of highest priority will be summed
        Force forces = new Force();

        forces.priority = -1;

        // Highest priority will be chosen
        FrictionAffector friction = null;

        GravityAffector gravity = null;

        foreach (Collider2D c in colliders)
        {
            ForceAffector foa = c.GetComponent <ForceAffector>();
            if (foa != null)
            {
                if (forces.priority == foa.priority)
                {
                    forces.force += foa.force;
                }
                else if (foa.priority > forces.priority)
                {
                    forces.priority = foa.priority;
                    forces.force    = foa.force;
                }
            }

            FrictionAffector fra = c.GetComponent <FrictionAffector>();
            if (fra != null)
            {
                if (friction == null || fra.priority > friction.priority)
                {
                    friction = fra;
                }
            }

            GravityAffector ga = c.GetComponent <GravityAffector>();
            if (ga != null)
            {
                if (gravity == null || ga.priority > gravity.priority)
                {
                    gravity = ga;
                }
            }
        }

        // Force
        externalForce = Vector3.zero;
        if (forces.priority > -1)
        {
            externalForce = forces.force;
        }

        // Friction
        if (GetComponent <Controller2D>().collisions.below)
        {
            moveSpeed  = moveSpeedDefault;
            sprintMult = sprintMultDefault;
            groundDrag = groundDragDefault;
            airDrag    = airDragDefault;

            if (friction != null)
            {
                if (friction.groundDrag >= 0)
                {
                    groundDrag = friction.groundDrag;
                }

                if (friction.airDrag >= 0)
                {
                    airDrag = friction.airDrag;
                }

                if (friction.maxMoveSpeed >= 0)
                {
                    moveSpeed = friction.maxMoveSpeed;
                }

                if (friction.sprintMult >= 1)
                {
                    sprintMult = friction.sprintMult;
                }
            }
        }

        // Air Drag
        //if (airDragAffect != null && airDragAffect.drag >= 0)
        //    airDrag = airDragAffect.drag;

        // Gravity
        jumpHeight = jumpHeightDefault;
        timeToApex = timeToApexDefault;
        if (gravity != null)
        {
            jumpHeight = gravity.jumpHeight;
            timeToApex = gravity.timeToApex;
        }
    }
 public void TestCoalescability() {
   GravityAffector<SimpleParticle> affector = new GravityAffector<SimpleParticle>(
     SimpleParticleModifier.Default
   );
   Assert.IsFalse(affector.IsCoalescable);
 }
 public void TestConstructor() {
   GravityAffector<SimpleParticle> affector = new GravityAffector<SimpleParticle>(
     SimpleParticleModifier.Default
   );
   Assert.IsNotNull(affector); // nonsense; avoids compiler warning
 }
    protected ArrayList InitAffectors(EffectNode node)
    {
        ArrayList AffectorList = new ArrayList();

        if (UVAffectorEnable)
        {
            UVAnimation uvAnim = new UVAnimation();
            if (UVType == 1)
            {
                float   perWidth  = OriUVDimensions.x / Cols;
                float   perHeight = Mathf.Abs(OriUVDimensions.y / Rows);
                Vector2 cellSize  = new Vector2(perWidth, perHeight);
                uvAnim.BuildUVAnim(OriTopLeftUV, cellSize, Cols, Rows, Cols * Rows);
            }
            UVDimension = uvAnim.UVDimensions[0];
            UVTopLeft   = uvAnim.frames[0];

            if (uvAnim.frames.Length != 1)
            {
                uvAnim.loopCycles = LoopCircles;
                Affector aft = new UVAffector(uvAnim, UVTime, node, RandomStartFrame);
                AffectorList.Add(aft);
            }
        }
        else
        {
            UVDimension = OriUVDimensions;
            UVTopLeft   = OriTopLeftUV;
        }


        if (RotAffectorEnable && RotateType != RSTYPE.NONE)
        {
            Affector aft;
            if (RotateType == RSTYPE.CURVE)
            {
                aft = new RotateAffector(RotateCurve, node);
            }
            else
            {
                aft = new RotateAffector(DeltaRot, node);
            }
            AffectorList.Add(aft);
        }
        if (ScaleAffectorEnable && ScaleType != RSTYPE.NONE)
        {
            Affector aft;
            if (ScaleType == RSTYPE.CURVE)
            {
                aft = new ScaleAffector(ScaleXCurve, ScaleYCurve, node);
            }
            else
            {
                aft = new ScaleAffector(DeltaScaleX, DeltaScaleY, node);
            }
            AffectorList.Add(aft);
        }
        if (ColorAffectorEnable && ColorAffectType != 0)
        {
            ColorAffector aft;
            if (ColorAffectType == 2)
            {
                Color[] carr = new Color[5];
                carr[0] = Color1; carr[1] = Color2; carr[2] = Color3; carr[3] = Color4; carr[4] = Color5;
                aft     = new ColorAffector(carr, ColorGradualTimeLength, ColorGradualType, node);
            }
            else
            {
                Color[] carr = new Color[2];
                carr[0] = Color1; carr[1] = Color2;
                aft     = new ColorAffector(carr, ColorGradualTimeLength, ColorGradualType, node);
            }
            AffectorList.Add(aft);
        }
        if (JetAffectorEnable)
        {
            Affector aft = new JetAffector(JetMin, JetMax, node);
            AffectorList.Add(aft);
        }
        if (VortexAffectorEnable)
        {
            Affector aft;
            aft = new VortexAffector(VortexObj, VortexMagType, VortexMag, VortexCurve, VortexDirection, VortexInheritRotation, node);

            AffectorList.Add(aft);
        }
        if (UVRotAffectorEnable)
        {
            Affector aft;
            aft = new UVRotAffector(UVRotXSpeed, UVRotYSpeed, node);
            AffectorList.Add(aft);
        }


        if (GravityAffectorEnable)
        {
            Affector aft;
            aft = new GravityAffector(GravityObject, GravityAftType, GravityMagType, IsGravityAccelerate, GravityDirection, GravityMag, GravityCurve, node);
            AffectorList.Add(aft);

            if (GravityAftType == GAFTTYPE.Spherical && GravityObject == null)
            {
                Debug.LogWarning("Gravity Object is missing, automatically set to effect layer self.");
                GravityObject = transform;
            }
        }
        if (AirAffectorEnable)
        {
            Affector aft = new AirFieldAffector(AirObject, AirDirection, AirMagType, AirMagnitude, AirMagCurve, AirAttenuation, AirUseMaxDistance,
                                                AirMaxDistance, AirEnableSpread, AirSpread, AirInheritVelocity, AirInheritRotation, node);
            AffectorList.Add(aft);
        }
        if (BombAffectorEnable)
        {
            Affector aft = new BombAffector(BombObject, BombType, BombMagType, BombDecayType, BombMagnitude, BombMagCurve, BombDecay, BombAxis, node);
            AffectorList.Add(aft);
        }
        if (TurbulenceAffectorEnable)
        {
            Affector aft = new TurbulenceFieldAffector(TurbulenceObject, TurbulenceMagType, TurbulenceMagnitude, TurbulenceMagCurve, TurbulenceAttenuation, TurbulenceUseMaxDistance, TurbulenceMaxDistance, node);
            AffectorList.Add(aft);
        }
        return(AffectorList);
    }
예제 #10
0
    protected List<Affector> InitAffectors(EffectNode node)
    {
        List<Affector> AffectorList = new List<Affector>();

        if (UVAffectorEnable)
        {
            UVAnimation uvAnim = new UVAnimation();
            if (UVType == 1)
            {
                float perWidth = OriUVDimensions.x / Cols;
                float perHeight = Mathf.Abs(OriUVDimensions.y / Rows);
                Vector2 cellSize = new Vector2(perWidth, perHeight);
                uvAnim.BuildUVAnim(OriTopLeftUV, cellSize, Cols, Rows, Cols * Rows);
            }
            UVDimension = uvAnim.UVDimensions[0];
            UVTopLeft = uvAnim.frames[0];

            if (uvAnim.frames.Length != 1)
            {
                uvAnim.loopCycles = LoopCircles;
                Affector aft = new UVAffector(uvAnim, UVTime, node, RandomStartFrame);
                AffectorList.Add(aft);
            }
        }
        else
        {
            UVDimension = OriUVDimensions;
            UVTopLeft = OriTopLeftUV;
        }

        if (RotAffectorEnable && RotateType != RSTYPE.NONE)
        {
            Affector aft;
            if (RotateType == RSTYPE.CURVE)
                aft = new RotateAffector(RotateCurve, node);
            else
                aft = new RotateAffector(DeltaRot, node);
            AffectorList.Add(aft);
        }
        if (ScaleAffectorEnable && ScaleType != RSTYPE.NONE)
        {
            Affector aft;

            if (UseSameScaleCurve)
                ScaleYCurve = ScaleXCurve;

            if (ScaleType == RSTYPE.CURVE)
                aft = new ScaleAffector(ScaleXCurve, ScaleYCurve, node);
            else
                aft = new ScaleAffector(DeltaScaleX, DeltaScaleY, node);
            AffectorList.Add(aft);
        }
        if (ColorAffectorEnable /*&& ColorAffectType != 0*/)
        {
            ColorAffector aft = new ColorAffector(this, node);
            AffectorList.Add(aft);
        }
        if (JetAffectorEnable)
        {
            Affector aft = new JetAffector(JetMag,JetMagType,JetCurve,node);
            AffectorList.Add(aft);
        }
        if (VortexAffectorEnable)
        {
            Affector aft;
            aft = new VortexAffector(VortexObj, VortexMagType, VortexMag, VortexCurve, VortexDirection, VortexInheritRotation, node);

            AffectorList.Add(aft);
        }
        if (UVRotAffectorEnable)
        {
            Affector aft;

            float xscroll = UVRotXSpeed;
            float yscroll = UVRotYSpeed;
            if (RandomUVRotateSpeed)
            {
                xscroll = Random.Range(UVRotXSpeed,UVRotXSpeedMax);
                yscroll = Random.Range(UVRotYSpeed,UVRotYSpeedMax);
            }

            aft = new UVRotAffector(xscroll, yscroll, node);
            AffectorList.Add(aft);
        }

        if (GravityAffectorEnable)
        {
            Affector aft;
            aft = new GravityAffector(GravityObject, GravityAftType, GravityMagType, IsGravityAccelerate,GravityDirection, GravityMag, GravityCurve, node);
            AffectorList.Add(aft);

            if (GravityAftType == GAFTTYPE.Spherical && GravityObject == null)
            {
                Debug.LogWarning("Gravity Object is missing, automatically set to effect layer self:" + gameObject.name);
                GravityObject = transform;
            }

        }
        if (AirAffectorEnable)
        {
            Affector aft = new AirFieldAffector(AirObject, AirDirection, AirMagType, AirMagnitude, AirMagCurve, AirAttenuation, AirUseMaxDistance,
                AirMaxDistance, AirEnableSpread, AirSpread, AirInheritVelocity, AirInheritRotation, node);
            AffectorList.Add(aft);
        }
        if (BombAffectorEnable)
        {
            Affector aft = new BombAffector(BombObject, BombType, BombMagType, BombDecayType, BombMagnitude, BombMagCurve, BombDecay, BombAxis, node);
            AffectorList.Add(aft);
        }
        if (TurbulenceAffectorEnable)
        {
            Affector aft = new TurbulenceFieldAffector(TurbulenceObject, TurbulenceMagType, TurbulenceMagnitude, TurbulenceMagCurve, TurbulenceAttenuation, TurbulenceUseMaxDistance, TurbulenceMaxDistance, node);
            AffectorList.Add(aft);
        }
        if (DragAffectorEnable)
        {
            Affector aft = new DragAffector(DragObj,DragUseDir,DragDir,DragMag,DragUseMaxDist,DragMaxDist,DragAtten,node);
            AffectorList.Add(aft);
        }
        return AffectorList;
    }
예제 #11
0
    protected ArrayList InitAffectors(EffectNode node)
    {
        ArrayList AffectorList = new ArrayList();

        if (UVAffectorEnable)
        {
            UVAnimation uvAnim = new UVAnimation();
            if (UVType == 1)
            {
                float perWidth = OriUVDimensions.x / Cols;
                float perHeight = Mathf.Abs(OriUVDimensions.y / Rows);
                Vector2 cellSize = new Vector2(perWidth, perHeight);
                uvAnim.BuildUVAnim(OriTopLeftUV, cellSize, Cols, Rows, Cols * Rows);
            }
            UVDimension = uvAnim.UVDimensions[0];
            UVTopLeft = uvAnim.frames[0];

            if (uvAnim.frames.Length != 1)
            {
                uvAnim.loopCycles = LoopCircles;
                Affector aft = new UVAffector(uvAnim, UVTime, node, RandomStartFrame);
                AffectorList.Add(aft);
            }
        }
        else
        {
            UVDimension = OriUVDimensions;
            UVTopLeft = OriTopLeftUV;
        }

        if (RotAffectorEnable && RotateType != RSTYPE.NONE)
        {
            Affector aft;
            if (RotateType == RSTYPE.CURVE)
                aft = new RotateAffector(RotateCurve, node);
            else
                aft = new RotateAffector(DeltaRot, node);
            AffectorList.Add(aft);
        }
        if (ScaleAffectorEnable && ScaleType != RSTYPE.NONE)
        {
            Affector aft;
            if (ScaleType == RSTYPE.CURVE)
                aft = new ScaleAffector(ScaleXCurve, ScaleYCurve, node);
            else
                aft = new ScaleAffector(DeltaScaleX, DeltaScaleY, node);
            AffectorList.Add(aft);
        }
        if (ColorAffectorEnable && ColorAffectType != 0)
        {
            ColorAffector aft;
            if (ColorAffectType == 2)
            {
                Color[] carr = new Color[5];
                carr[0] = Color1; carr[1] = Color2; carr[2] = Color3; carr[3] = Color4; carr[4] = Color5;
                aft = new ColorAffector(carr, ColorGradualTimeLength, ColorGradualType, node);
            }
            else
            {
                Color[] carr = new Color[2];
                carr[0] = Color1; carr[1] = Color2;
                aft = new ColorAffector(carr, ColorGradualTimeLength, ColorGradualType, node);
            }
            AffectorList.Add(aft);
        }
        if (JetAffectorEnable)
        {
            Affector aft = new JetAffector(JetMin, JetMax, node);
            AffectorList.Add(aft);
        }
        if (VortexAffectorEnable)
        {
            Affector aft;
            aft = new VortexAffector(VortexObj, VortexMagType, VortexMag, VortexCurve, VortexDirection, VortexInheritRotation, node);

            AffectorList.Add(aft);
        }
        if (UVRotAffectorEnable)
        {
            Affector aft;
            aft = new UVRotAffector(UVRotXSpeed, UVRotYSpeed, node);
            AffectorList.Add(aft);
        }

        if (GravityAffectorEnable)
        {
            Affector aft;
            aft = new GravityAffector(GravityObject, GravityAftType, GravityMagType, IsGravityAccelerate,GravityDirection, GravityMag, GravityCurve, node);
            AffectorList.Add(aft);

            if (GravityAftType == GAFTTYPE.Spherical && GravityObject == null)
            {
                Debug.LogWarning("Gravity Object is missing, automatically set to effect layer self.");
                GravityObject = transform;
            }

        }
        if (AirAffectorEnable)
        {
            Affector aft = new AirFieldAffector(AirObject, AirDirection, AirMagType, AirMagnitude, AirMagCurve, AirAttenuation, AirUseMaxDistance,
                AirMaxDistance, AirEnableSpread, AirSpread, AirInheritVelocity, AirInheritRotation, node);
            AffectorList.Add(aft);
        }
        if (BombAffectorEnable)
        {
            Affector aft = new BombAffector(BombObject, BombType, BombMagType, BombDecayType, BombMagnitude, BombMagCurve, BombDecay, BombAxis, node);
            AffectorList.Add(aft);
        }
        if (TurbulenceAffectorEnable)
        {
            Affector aft = new TurbulenceFieldAffector(TurbulenceObject, TurbulenceMagType, TurbulenceMagnitude, TurbulenceMagCurve, TurbulenceAttenuation, TurbulenceUseMaxDistance, TurbulenceMaxDistance, node);
            AffectorList.Add(aft);
        }
        return AffectorList;
    }
예제 #12
0
        // Check if a particle is inside any collider on a weather layer that's currently in affect
        private void handleForces(WeatherManager.WeatherType t, ref ParticleSystem.Particle p, out bool inForceAccector, out bool inGravityAffector)
        {
            inForceAccector   = false;
            inGravityAffector = false;

            Force externalForce = new Force();

            externalForce.priority = -1;

            Collider2D[] col = Physics2D.OverlapPointAll(p.position, WeatherManager.getWeatherLayer(t));

            foreach (Collider2D c in col)
            {
                ForceAffector foa = c.GetComponent <ForceAffector>();

                if (foa != null)
                {
                    inForceAccector = true;

                    if (externalForce.priority == foa.priority)
                    {
                        externalForce.force += foa.force;
                        p.velocity           = externalForce.force;
                    }
                    else if (foa.priority > externalForce.priority)
                    {
                        externalForce.priority = foa.priority;
                        externalForce.force    = foa.force;
                    }
                }

                GravityAffector ga = c.GetComponent <GravityAffector>();

                if (ga != null)
                {
                    inGravityAffector = true;

                    jumpHeight     = ga.jumpHeight;
                    timeToJumpApex = ga.timeToApex;
                }
                else
                {
                    jumpHeight     = pal.jumpHeightDefault;
                    timeToJumpApex = pal.timeToApexDefault;
                }
            }

            if (jumpHeight == 0 && timeToJumpApex == 0)
            {
                jumpHeight     = pal.jumpHeightDefault;
                timeToJumpApex = pal.timeToApexDefault;
            }

            float gravityMod = 1;

            switch (t)
            {
            case WeatherManager.WeatherType.sun:
                gravityMod = dandyFall;
                break;

            case WeatherManager.WeatherType.rain:
                gravityMod = rainFall;
                break;

            case WeatherManager.WeatherType.snow:
                gravityMod = snowFall;
                break;
            }

            Vector3 velocity = p.velocity;

            gravity = -(2 * jumpHeight) / Mathf.Pow(timeToJumpApex, 2) * gravityMod;

            velocity.x = externalForce.force.x;

            // Reduce or increase gravity depending on the magnitude and direction of the external force
            float forceDiff = gravity + externalForce.force.y;
            float m         = 0.05f;
            float forceMod  = forceDiff > 0 ?
                              Mathf.Pow(2, m * -forceDiff) :
                              -Mathf.Pow(2, m * forceDiff) + 2;

            velocity.y = gravity * forceMod;

            p.velocity = velocity;
        }
예제 #13
0
 public void AddToSources(GravityAffector source)
 {
     sources.Add(source);
 }