コード例 #1
0
ファイル: Thing.cs プロジェクト: evianpyy/thing-thing-thing
    protected void Spark(Color particleColor, int numberOfParticles)
    {
        var particleMain = explodePS.main;

        particleMain.startColor = particleColor;
        var newBurst = new ParticleSystem.Burst(0f, numberOfParticles);

        explodePS.emission.SetBurst(0, newBurst);
        explodePS.Play();
        TTTEventsManager.main.SomeoneSparked(gameObject);
    }
コード例 #2
0
    public override void EmitParticles()
    {
        particle = GetComponent <ParticleSystem>();
        var emission = particle.emission;

        ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[emission.burstCount];
        emission.GetBursts(bursts);
        max = bursts[0].maxCount;
        min = bursts[0].minCount;
        particle.Emit(Random.Range(min, max));
    }
コード例 #3
0
    void SetArrowSize()
    {
        foreach (ParticleSystem ps in particleSystems)
        {
            var em = ps.emission;
            ParticleSystem.Burst mBurst = em.GetBurst(0);

            mBurst.count = Mathf.RoundToInt(mBurst.count.constant * EffectController.Instance.SizeMultiplier);
            em.SetBurst(0, mBurst);
            //em.burstCount = Mathf.RoundToInt(em.burstCount * EffectController.Instance.SizeMultiplier);
        }
    }
コード例 #4
0
    public void SpillBlood(Vector3 collisionPoint, Transform colliderHit, float hitMagnitude)
    {
        var   instance  = Instantiate(BloodSplatterEffect, collisionPoint, Quaternion.LookRotation(CalculateRotation(collisionPoint, colliderHit), Vector3.up), colliderHit);
        var   effect    = instance.GetComponent <ParticleSystem>();
        short minAmount = (short)(hitMagnitude * 50);
        short maxAmount = (short)(hitMagnitude * 500);
        var   burst     = new ParticleSystem.Burst(0, minAmount, maxAmount, 1, 0.01f);

        effect.emission.SetBurst(0, burst);
        effect.Play();
        Destroy(instance, 1);
    }
 protected override void ReadFromImpl(object obj)
 {
     base.ReadFromImpl(obj);
     ParticleSystem.Burst uo = (ParticleSystem.Burst)obj;
     time           = uo.time;
     count          = uo.count;
     minCount       = uo.minCount;
     maxCount       = uo.maxCount;
     cycleCount     = uo.cycleCount;
     repeatInterval = uo.repeatInterval;
     probability    = uo.probability;
 }
コード例 #6
0
        /**
         *获取生命周期内爆发的粒子总数
         */
        private int GetBurstTotal(ParticleSystem comp)
        {
            int total  = 0;
            var bursts = new ParticleSystem.Burst[comp.emission.burstCount];

            comp.emission.GetBursts(bursts);
            foreach (var burst in bursts)
            {
                total += burst.maxCount;
            }

            return(total);
        }
 protected override object WriteToImpl(object obj)
 {
     obj = base.WriteToImpl(obj);
     ParticleSystem.Burst uo = (ParticleSystem.Burst)obj;
     uo.time           = time;
     uo.count          = count;
     uo.minCount       = minCount;
     uo.maxCount       = maxCount;
     uo.cycleCount     = cycleCount;
     uo.repeatInterval = repeatInterval;
     uo.probability    = probability;
     return(uo);
 }
コード例 #8
0
 private void Start()
 {
     // copy components
     explosionMask = owner.m_EnemyStats.hitMask;
     damage        = owner.m_EnemyStats.attackValue;
     // get the particle burst info
     emission = thisParticle.emission;
     ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[emission.burstCount];
     emission.GetBursts(bursts);
     min = bursts[0].minCount;
     max = bursts[0].maxCount;
     transform.parent = null;
 }
コード例 #9
0
        /// <summary>
        /// Play particles at the given position.
        /// </summary>
        private void PlayParticles(Vector3 position, ParticleSystem selectedParticle)
        {
            ParticleSystem.Burst spawnBurst = selectedParticle.emission.GetBurst(0);
            int spawnCount = Random.Range(spawnBurst.minCount, spawnBurst.maxCount + 1);

            position.z = selectedParticle.transform.position.z;
            selectedParticle.transform.position = position;
            selectedParticle.Emit(new ParticleSystem.EmitParams
            {
                position             = position,
                applyShapeToPosition = true
            }, spawnCount);
        }
コード例 #10
0
ファイル: RFParticles.cs プロジェクト: ekruhliu/gamepack-test
        /// /////////////////////////////////////////////////////////
        /// Emission
        /// /////////////////////////////////////////////////////////

        // Set emission
        public static void SetEmission(ParticleSystem.EmissionModule emissionModule, float distanceRate, int burstAmount)
        {
            emissionModule.enabled = true;
            emissionModule.rateOverTimeMultiplier     = 0f;
            emissionModule.rateOverDistanceMultiplier = distanceRate;

            // Set burst
            if (burstAmount > 0)
            {
                ParticleSystem.Burst   burst  = new ParticleSystem.Burst(0.0f, (short)burstAmount, (short)burstAmount, 1, 999f);
                ParticleSystem.Burst[] bursts = new [] { burst };
                emissionModule.SetBursts(bursts);
            }
        }
コード例 #11
0
    void InstantiateParticleSystem()
    {
        GameObject     particleGO  = Instantiate <GameObject>(AsteraX.AsteroidsSO.GetAsteroidParticlePrefab(), transform.position, Quaternion.identity);
        ParticleSystem particleSys = particleGO.GetComponent <ParticleSystem>();

        ParticleSystem.MainModule main = particleSys.main;
        main.startLifetimeMultiplier = size * 0.5f;
        ParticleSystem.EmissionModule emitter    = particleSys.emission;
        ParticleSystem.Burst          burst      = emitter.GetBurst(0);
        ParticleSystem.MinMaxCurve    burstCount = burst.count;
        burstCount.constant = burstCount.constant * size;
        burst.count         = burstCount;
        emitter.SetBurst(0, burst);
    }
コード例 #12
0
    /// <summary>
    /// Shows sparks coming from the point of collision
    /// </summary>
    /// <param name="position">Position of collision</param>
    /// <param name="damagePercent">How much percent of total HP of damage was inflicted, between 0 and 100</param>
    public void collisionEffect(Vector2 position, float damagePercent = 100.0f)
    {
        if (!Managers.Camera.inView(position))
        {
            return;//don't display effect if it's not going to show
        }
        ParticleSystem chosenPS = null;

        //Find existing particle system
        foreach (ParticleSystem ps in collisionEffectList)
        {
            if (!ps.isPlaying)
            {
                chosenPS = ps;
                break;
            }
        }
        //Else make a new one
        if (chosenPS == null)
        {
            GameObject ce = GameObject.Instantiate(collisionEffectPrefab);
            ce.transform.parent = transform;
            ParticleSystem ceps = ce.GetComponent <ParticleSystem>();
            collisionEffectList.Add(ceps);
            chosenPS = ceps;
        }
        //Start Speed
        {
            ParticleSystem.MainModule  psmm  = chosenPS.main;
            ParticleSystem.MinMaxCurve psmmc = psmm.startSpeed;
            float speed = (damagePercent * particleStartSpeed) / 100;
            speed           = Mathf.Max(speed, 0.5f);//make speed at least 1.0f
            psmmc.constant  = speed;
            psmm.startSpeed = psmmc;
        }
        //Particle Amount
        {
            int amountOfParticles = (int)((damagePercent * particleAmount) / 100);
            amountOfParticles = Mathf.Max(amountOfParticles, 3);//make speed at least 1.0f
            ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[1]
            {
                new ParticleSystem.Burst(0, (short)amountOfParticles)
            };
            chosenPS.emission.SetBursts(bursts);
        }
        //
        chosenPS.gameObject.transform.position = position;
        chosenPS.Play();
    }
コード例 #13
0
    public void SpawnVFX(GameObject VFXSourceGo, Vector3 pos, VFXType vfxType, Vector3 extraVel, float delayTime, float lifetime)
    {
        if (delayTime == 0)
        {
            //If same type of vfx happen too fast and multiple times in the same spot then only spawn one of them at this moment
            if (lastVFXSnapshots.ContainsKey(vfxType) && (lastVFXSnapshots[vfxType].pos - pos).magnitude < 0.05f && Time.time - lastVFXSnapshots[vfxType].time < smallestSameSpotVFXTimeInterval)
            {
                return;
            }

            //Record a specific vfx's snapshot
            if (lastVFXSnapshots.ContainsKey(vfxType))
            {
                lastVFXSnapshots[vfxType] = new VFXSnapshot()
                {
                    time = Time.time, pos = pos
                };
            }
            else
            {
                lastVFXSnapshots.Add(vfxType, new VFXSnapshot()
                {
                    time = Time.time, pos = pos
                });
            }

            var go        = GameObject.Instantiate(VFXSourceGo, pos, Quaternion.identity);
            var partSyses = go.GetComponentsInChildren <ParticleSystem>();
            foreach (var pSys in partSyses)
            {
                var emisModule = pSys.emission;
                var bursts     = new ParticleSystem.Burst[emisModule.burstCount];
                emisModule.GetBursts(bursts);
                for (int i = 0; i < bursts.Length; i++)
                {
                    bursts[i].maxCount = (short)((float)bursts[i].maxCount * (1f + extraVel.magnitude * 0.5f));
                    bursts[i].minCount = (short)((float)bursts[i].minCount * (1f + extraVel.magnitude * 0.5f));
                }
                var main = pSys.main;
                main.startSpeedMultiplier = 1f + extraVel.magnitude;
            }

            Destroy(go, lifetime);
        }
        else if (delayTime > 0)
        {
            StartCoroutine(SpawnVFX_Delay(VFXSourceGo, pos, vfxType, extraVel, delayTime, lifetime));
        }
    }
コード例 #14
0
    protected void Spark(Color particleColor, int numberOfParticles)
    {
        if (explodePS == null)
        {
            explodePS = GetComponentInChildren <ParticleSystem> ();
        }

        ParticleSystem.MainModule particleMain = explodePS.main;
        particleMain.startColor = particleColor;
        var newBurst = new ParticleSystem.Burst(0f, numberOfParticles);

        explodePS.emission.SetBurst(0, newBurst);
        explodePS.Play();
        TTTEventsManager.main.SomeoneSparked(gameObject);
    }
コード例 #15
0
    public void Set(float effort)
    {
        ParticleSystem.Burst b = particle.emission.GetBurst(0);
        if (effort < sweatThreshold)
        {
            b.count = 0;
        }
        else
        {
            b.count = Mathf.Floor(effort * maxDropCount);
        }

        b.repeatInterval = maxBurstInterval - (effort * (maxBurstInterval - minBurstInterval));
        particle.emission.SetBurst(0, b);
    }
コード例 #16
0
            public EmissionModuleLoader(ParticleSystem.EmissionModule module)
            {
                _value = module;
                bursts = new CallbackList <BurstLoader>(e =>
                {
                    _value.SetBursts(bursts.Select(b => b.Value).ToArray());
                });

                ParticleSystem.Burst[] burstArray = new ParticleSystem.Burst[module.burstCount];
                module.GetBursts(burstArray);
                for (Int32 i = 0; i < module.burstCount; i++)
                {
                    bursts.Add(burstArray[i], i + 1 == module.burstCount);
                }
            }
コード例 #17
0
    public void TriggerWave(int wave)
    {
        currentEnemy = 0;
        currentWave  = wave;
        int particleCount = Waves[currentWave].Enemies.Length;

        ParticleSystem.Burst[]        bursts    = new ParticleSystem.Burst[1];
        ParticleSystem.EmissionModule emissions = particlesystem.emission;
        emissions.GetBursts(bursts);
        bursts[0].minCount = (short)particleCount;
        bursts[0].maxCount = (short)particleCount;
        emissions.SetBursts(bursts);

        particlesystem.Play();
    }
コード例 #18
0
        private JSONObject ParseBurst(ParticleSystem.Burst burst)
        {
            JSONObject res = new JSONObject(JSONObject.Type.OBJECT);

            res.AddField("time", burst.time);
#if UNITY_2017_1_OR_NEWER
            res.AddField("count", ParseMinMaxCurve(burst.count));
            res.AddField("cycles", burst.cycleCount);
            res.AddField("interval", burst.repeatInterval);
#else
            res.AddField("count", ParseTwoConstants(burst.maxCount, burst.minCount));
#endif
            res.AddField("probability", 1);
            return(res);
        }
コード例 #19
0
    void ParticleEffect()
    {
        if (particleSystem)
        {
            var mainModule = particleSystem.main;

            var emissionModule = particleSystem.emission;
            var internalTime   = particleSystem.time;
            var thisBurst      = new ParticleSystem.Burst(Time.fixedDeltaTime, (short)particleCount, (short)particleCount, 1, 0f);
            emissionModule.burstCount = 1;
            emissionModule.SetBurst(0, thisBurst);
            //emissionModule.rateOverTime = 0.0f;

            particleSystem.Play();
        }
    }
コード例 #20
0
ファイル: TronWall.cs プロジェクト: w1198414795/color-wars
    public void PlayDestroyedParticleEffect()
    {
        float      magnitude    = (linePoints[1] - linePoints[0]).magnitude;
        GameObject instantiated = GameObject.Instantiate(team.resources.tronWallDestroyedPrefab,
                                                         (linePoints[1] + linePoints[0]) / 2, transform.rotation);
        ParticleSystem ps = instantiated.EnsureComponent <ParticleSystem>();

        ParticleSystem.MainModule main = ps.main;
        main.startColor = team.teamColor.color;
        ParticleSystem.ShapeModule shape = ps.shape;
        shape.radius = magnitude * .65f;
        ParticleSystem.EmissionModule emission = ps.emission;
        ParticleSystem.Burst          burst    = emission.GetBurst(0);
        burst.count = Mathf.Min(magnitude * burst.count.constant, maxParticlesOnDestroy);
        emission.SetBurst(0, burst);
        ps.Play();
    }
コード例 #21
0
ファイル: CurveUtil.cs プロジェクト: huijian142857/Dev_Tools
    public static int GetBurstMax(this ParticleSystem particleSystem)
    {
        int val = 0;

        ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[particleSystem.emission.burstCount];
        particleSystem.emission.GetBursts(bursts);
        foreach (ParticleSystem.Burst burst in bursts)
        {
            val = Mathf.Max(val, burst.maxCount);
            val = Mathf.Max(val, burst.minCount);
            if (burst.cycleCount == 0 && burst.repeatInterval > 0)
            {
                val = Mathf.Max(val, Mathf.CeilToInt(1f / burst.repeatInterval) * val);
            }
        }
        return(val);
    }
    public virtual void Start()
    {
        ParticleSystem myParticleSystem = this.GetComponent <ParticleSystem>();

        ParticleSystem.MainModule  mainModule        = myParticleSystem.main;
        ParticleSystem.MinMaxCurve origStartLifetime = mainModule.startLifetime;
        ParticleSystem.MinMaxCurve startLifetime     = new ParticleSystem.MinMaxCurve(0);
        startLifetime.constantMin = 0;
        startLifetime.constantMax = origStartLifetime.constantMax;
        mainModule.startLifetime  = startLifetime;
        ParticleSystem.EmissionModule emissionModule = myParticleSystem.emission;
        float burstSize = emissionModule.rateOverTime.constantMin * startLifetime.constantMax;

        ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[1];
        bursts[0] = new ParticleSystem.Burst(0f, (short)Mathf.RoundToInt(burstSize), (short)Mathf.RoundToInt(burstSize));
        emissionModule.SetBursts(bursts);
    }
コード例 #23
0
ファイル: Snowball.cs プロジェクト: JoshuaKey/GameStudioEP
    private void OnDestroy()
    {
        ParticleSystem.MainModule mainMod = ExplosionEffect.main;
        mainMod.maxParticles = (int)(this.transform.localScale.x * 10);
        //mainMod.startSpeed = this.transform.localScale.x;

        ParticleSystem.EmissionModule emissionModule;
        emissionModule = ExplosionEffect.emission;
        emissionModule.rateOverTime = 0;

        ParticleSystem.Burst burst = emissionModule.GetBurst(0);
        burst.count = mainMod.maxParticles;

        ExplosionEffect.transform.parent     = null;
        ExplosionEffect.transform.localScale = Vector3.one;
        ExplosionEffect.gameObject.SetActive(true);
        ExplosionEffect.Play();
    }
コード例 #24
0
    public void DiamondsPopUpfunction(int numberofdiamonds)  //  Yeh particle system wala hai
    {
        ParticleSystem ps = diamondsPop.GetComponent <ParticleSystem>();

        //ps.emission.SetBurst(0, new ParticleSystem.Burst(0, numberofdiamonds));
        ParticleSystem.Burst bursttt = ps.emission.GetBurst(0);
        if (numberofdiamonds < 5)
        {
            bursttt.count = numberofdiamonds;
        }
        else
        {
            bursttt.count = 5;
        }
        ps.emission.SetBurst(0, bursttt);
        GameObject popUpGameObject = (GameObject)Instantiate(diamondsPop, transform.position, transform.rotation);
        // Destroy(popUpGameObject, 0.7f);
    }
コード例 #25
0
    // パーティクルエミッション格納
    void SetEmission()
    {
        SetParam(ref m_saveData.emission.rateOverTime, m_particle.emission.rateOverTime);
        int burstsNum = m_particle.emission.burstCount;

        if (burstsNum != 0)
        {
            m_saveData.emission.bursts = new Burst[burstsNum];
            ParticleSystem.Burst[] burst = new ParticleSystem.Burst[burstsNum];
            m_particle.emission.GetBursts(burst);
            for (int i = 0; i < burstsNum; ++i)
            {
                m_saveData.emission.bursts[i].minCount = burst[i].minCount;
                m_saveData.emission.bursts[i].maxCount = burst[i].maxCount;
                m_saveData.emission.bursts[i].time     = burst[i].time;
            }
        }
    }
コード例 #26
0
    public void OnCollisionEnter(Collision collision)
    {
        PlayerState.CollisionEnter(collision);
        float force = 20f;
        ////float forceOffset = 0.1f;
        // If we hit the floor
        float dotProduct = Vector3.Dot(collision.contacts[0].normal, Vector3.up);

        if (dotProduct > 0.9f && dotProduct < 1.1f)
        {
            ParticleSystem         ps     = transform.GetChild((int)PlayerChildren.LandingParticles).GetComponent <ParticleSystem>();
            ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[ps.emission.burstCount];
            ps.emission.GetBursts(bursts);

            bursts[0].minCount = (short)Mathf.Lerp(2.0f, 6.0f, (collision.relativeVelocity.magnitude / 150.0f));
            bursts[0].maxCount = (short)Mathf.Lerp(3.0f, 8.0f, (collision.relativeVelocity.magnitude / 150.0f));
            ps.emission.SetBursts(bursts);
            ps.Play();
        }
        if (deformer)
        {
            float vibforce = collision.relativeVelocity.magnitude / 150.0f;
            //GamePad.VibrateForSeconds(playerIndex, vibforce, vibforce, 0.1f);

            float vel = collision.relativeVelocity.magnitude / collision.contacts.Length;
            for (int i = 0; i < collision.contacts.Length; i++)
            {
                Vector3 point = collision.contacts[i].point;
                deformer.AddDeformingForce(point, vel * force);
            }
        }

        if (!collision.transform.GetComponent <Player>() && !IsUnderWater)
        {
            if (Physics.Raycast(transform.position + Vector3.up * 0.5f + raycastOffsetPlayer * transform.forward, Vector3.down, raycastDist) ||
                Physics.Raycast(transform.position + Vector3.up * 0.5f - raycastOffsetPlayer * transform.forward, Vector3.down, raycastDist) ||
                Physics.Raycast(transform.position + Vector3.up * 0.5f + raycastOffsetPlayer * transform.right, Vector3.down, raycastDist) ||
                Physics.Raycast(transform.position + Vector3.up * 0.5f - raycastOffsetPlayer * transform.right, Vector3.down, raycastDist))
            {
                IsGrounded = true;
            }
        }
    }
コード例 #27
0
    private void Awake()
    {
        cutingWind   = GetComponentInChildren <ParticleSystem>();
        _audioSource = GetComponent <AudioSource>();
        //Ball = GetComponentInChildren<ParticleSystem>();
        _pointLigth    = GetComponentInChildren <Light>();
        trBall         = GetComponentInChildren <TrailRenderer>();
        cutingWindMain = cutingWind.main;
        BallMain       = Ball.main;
        shapeWInd      = cutingWind.shape;
        emissionWind   = cutingWind.emission;
        _burstWind     = emissionWind.GetBurst(1);

        cutingWindMain.startColor = grColor;
        BallMain.startColor       = grColor;
        trBall.colorGradient      = grColor;
        _pointLigth.intensity     = 0;
        _audioSource.loop         = true;
    }
コード例 #28
0
        private void ProcessEffect(ContactPoint2D contact)
        {
            var minThresholdImpulse = 20f;
            var maxImpulse          = 100f;

            if (contact.normalImpulse > minThresholdImpulse || health <= 0f)
            {
                var ruble    = Instantiate(rubleParticlePrefab, contact.point, Quaternion.identity);
                var rotation = Quaternion.LookRotation(ruble.transform.forward, contact.normal * -1);
                ruble.transform.rotation = rotation;
                var rubleParticle  = ruble.GetComponent <ParticleSystem>();
                var mainModule     = rubleParticle.main;
                var emissionModule = rubleParticle.emission;
                var burst          = new ParticleSystem.Burst(0, contact.normalImpulse / maxImpulse * mainModule.maxParticles);
                emissionModule.SetBurst(0, burst);
                Destroy(ruble, 1f);
                cameraShake.Shake(contact.normalImpulse / maxImpulse * cameraShake.maxAmplitude);
            }
        }
コード例 #29
0
    // Start is called before the first frame update
    void Start()
    {
        var BlockComponent = GetComponent <DataBlockComponent>();

        if (LookIntoParent)
        {
            BlockComponent = transform.parent.gameObject.GetComponent <DataBlockComponent>();
        }
        if (BlockComponent == null)
        {
            return;
        }
        var particleObject = gameObject;

        Target = particleObject.GetComponent <ParticleSystem>();
        var tBurst = Target.emission.GetBurst(0);

        if (BlockComponent.DataBlock == null)
        {
            return;
        }
        if (BlockComponent.DataBlock.GetParameterByName("ParticleMaterial", out var param))
        {
            var material = particleObject.GetComponent <ParticleSystemRenderer>().material;
            if (!material.name.StartsWith(param.Value))
            {
                var nMaterial = (Material)Resources.Load("Particles/" + param.Value);
                if (nMaterial != default)
                {
                    particleObject.GetComponent <ParticleSystemRenderer>().material = nMaterial;
                }
                else
                {
                    Debug.LogWarning($"The GameObject: {gameObject.name} is asking for ParticleMaterial: {param.Value} which does not exist. Using default material...");
                }
            }
        }
        if (BlockComponent.DataBlock.GetParameterByName <int>("Particle_BurstCount", out var tParam))
        {
            var nBurst = new ParticleSystem.Burst(tBurst.time, tParam.Value);
            Target.emission.SetBurst(0, nBurst);
        }
    }
コード例 #30
0
    void InstantiateParticleSystem(int ndx)
    {
        if (particleSystems.Length <= ndx)
        {
            return;
        }
        GameObject     particleGO  = Instantiate <GameObject>(particleSystems[ndx], transform.position, Quaternion.identity);
        ParticleSystem particleSys = particleGO.GetComponent <ParticleSystem>();

        ParticleSystem.MainModule main = particleSys.main;
        main.startLifetimeMultiplier = size * 0.5f;
        ParticleSystem.EmissionModule emitter    = particleSys.emission;
        ParticleSystem.Burst          burst      = emitter.GetBurst(0);
        ParticleSystem.MinMaxCurve    burstCount = burst.count;
        burstCount.constant = burstCount.constant * size;
        burst.count         = burstCount;
        emitter.SetBurst(0, burst);
        Destroy(particleGO, 4f);
    }