Beispiel #1
0
    void EmitAtLocation(ParticleCollisionEvent particleCollisionEvent)
    {
        Vector3    pos = particleCollisionEvent.intersection;
        Quaternion rot = Quaternion.LookRotation(particleCollisionEvent.normal);

        Instantiate(hitObject, pos, rot);
    }
Beispiel #2
0
    public void shot(ParticleCollisionEvent hit, Gradient colors)
    {
        Debug.Log(" shot is called ");
        SetDecaleData(hit, colors);

        display();
    }
 // TODO: this will affect particles from ANY system. Need to setup a link to the target particle system.
 // WARNING: For every particle collision in this frame, we check EVERY particle. Could be slow with 1000's of the things and lots of objects.
 // So that's 'number of particles that had a collision with this object in this frame' X 'number of particles' = number of loops.
 // In our case, we're train-lining particles so only one collision occurs at a time.
 // TODO: We use a hard-coded 0.2f in the below. What about units/scaling etc?
 // This value was chosen because 0.1f resulted in some particles not being detected as close enough to change their colour.
 void OnParticleCollision(GameObject fromThisParticleSystem)
 {
     if (fromThisParticleSystem)
     {
         ParticleSystem ps = fromThisParticleSystem.GetComponent <ParticleSystem>();
         //Get all collision events from the particle system that occurred with this sphere in this frame.
         int numCollisionEvents = ParticlePhysicsExtensions.GetCollisionEvents(ps, gameObject, collisionEvents);            //ps.GetCollisionEvents(sc, collisionEvents);
         for (int collisionEventCounter = 0; collisionEventCounter < numCollisionEvents; collisionEventCounter++)
         {
             ParticleCollisionEvent pce = collisionEvents [collisionEventCounter];
             // Now we have to find out which particles actually hit.
             // Get all the particles from this particle system that are 'in flight'.
             ParticleSystem.Particle[] inflightParticles = new ParticleSystem.Particle[ps.particleCount];
             int inflightParticleCount = ps.GetParticles(inflightParticles);
             // Find out which ones are close enough to the sphere to be considered a hit.
             for (int i = 0; i < inflightParticleCount; i++)
             {
                 //MUST use the 'transform' of the PS to get the particles position world space.
                 Vector3 particlePosWS = ps.transform.TransformPoint(inflightParticles [i].position);
                 double  distance      = Vector3.Distance(pce.intersection, particlePosWS);
                 if (distance < 0.2f)
                 {
                     inflightParticles[i].color = photonColor;
                 }
             }
             ps.SetParticles(inflightParticles, inflightParticleCount);                // Think, if multiple particles hit the same point vs hitting different points in this frame?
         }
     }
 }
Beispiel #4
0
 void OnParticleCollision(GameObject other)
 {
     if (collisionEvents == null)
     {
         return;
     }
     if (other.tag == "Barrel")
     {
         for (int i = 0; i < collisionEvents.Length; i++)
         {
             collisionEvents[i] = new ParticleCollisionEvent[sprinklers[i].GetSafeCollisionEventSize()];
         }
         for (int i = 0; i < collisionEvents.Length; i++)
         {
             sprinklers[i].GetCollisionEvents(gameObject, collisionEvents[i]);
         }
         for (int i = 0; i < collisionEvents.Length; i++)
         {
             for (int j = 0; j < collisionEvents[i].Length; j++)
             {
                 lid.AddForceAtPosition(Vector3.down * dropletForce, collisionEvents[i][j].intersection);
             }
         }
     }
 }
Beispiel #5
0
    void SetParticleData(ParticleCollisionEvent particleCollisionEvent, Gradient colorGradient)
    {
        if (particleDecalDataIndex >= maxDecals)
        {
            particleDecalDataIndex = 0;
        }

        particleData[particleDecalDataIndex].position = particleCollisionEvent.intersection;
        Vector3 particleRotationEuler = Quaternion.LookRotation(particleCollisionEvent.normal).eulerAngles;

        particleRotationEuler.z = Random.Range(0, 360);
        particleData[particleDecalDataIndex].rotation = particleRotationEuler;
        if (particleCollisionEvent.colliderComponent != null)
        {
            if (particleCollisionEvent.colliderComponent.CompareTag("Prop"))
            {
                particleData[particleDecalDataIndex].size = Random.Range(propDecalSizeMin, propDecalSizeMax);
            }
            else
            {
                particleData[particleDecalDataIndex].size = Random.Range(decalSizeMin, decalSizeMax);
            }
        }
        particleData[particleDecalDataIndex].color = colorGradient.Evaluate(Random.Range(0f, 1f));

        particleDecalDataIndex++;
    }
    void EmitAtLocation(ParticleCollisionEvent particleCollisionEvent)
    {
        ParticleSystem.MainModule psMain = SnowPieces.main;

        // Instantiate(Snow, particleCollisionEvent.intersection,Quaternion.identity);
        objectPooler.SpawnFromPool("Snow", particleCollisionEvent.intersection, Quaternion.identity);
    }
 void SplatterParticles(ParticleCollisionEvent collisionEvent)
 {
     splatterParticles.transform.position = collisionEvent.intersection;
     splatterParticles.transform.rotation = Quaternion.LookRotation(collisionEvent.normal);
     splatterParticles.Clear();
     splatterParticles.Play();
 }
Beispiel #8
0
    void EmitAtLocation(ParticleCollisionEvent particleCollisionEvent)
    {
        splatter.transform.position = particleCollisionEvent.intersection;
        splatter.transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal);

        if (_flyScore % 150 == 0)
        {// 솜사탕
            SoundManager._uniqueinstance.PlayEffSound(SoundManager.eEffType.COMBO);
            _scoreEff[3].GetComponent <ParticleSystem>().Play();
            _scoreEff[3].transform.position = particleCollisionEvent.intersection;
            _scoreEff[3].transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal);
        }
        else if (_flyScore % 350 == 0)
        {// BAAM
            SoundManager._uniqueinstance.PlayEffSound(SoundManager.eEffType.COMBO_YEAHH);
            _scoreEff[2].GetComponent <ParticleSystem>().Play();
            _scoreEff[2].transform.position = particleCollisionEvent.intersection;
            _scoreEff[2].transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal);
        }
        else if (_flyScore % 800 == 0)
        {// 별
            SoundManager._uniqueinstance.PlayEffSound(SoundManager.eEffType.COMBO_SHINE);
            _scoreEff[1].GetComponent <ParticleSystem>().Play();
            _scoreEff[1].transform.position = particleCollisionEvent.intersection;
            _scoreEff[1].transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal);
        }

        ParticleSystem.MainModule psMain = splatter.main;
        psMain.startColor = particleGradient.Evaluate(Random.Range(0f, 1f));
        splatter.Emit(10);
    }
 private void EmitAtLocation(ParticleCollisionEvent particleCollisionEvent)
 {
     splatterParticle.transform.position = particleCollisionEvent.intersection;
     splatterParticle.transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal);
     print(particleCollisionEvent.intersection);
     splatterParticle.Emit(5);
 }
Beispiel #10
0
    private void SpawnDecalBloodDroplets(ParticleCollisionEvent particleCollisionEvent)
    {
        float randomAngle = Random.Range(0f, 360f);
        float randomScale = Random.Range(-0.2f, 0.2f);

        Ray        precise = new Ray();
        RaycastHit hit;

        //raising the collision height slightly makes the blood droplet positioning look better
        Vector3 rayOrigin = particleCollisionEvent.intersection;

        rayOrigin.y      += 0.1f;
        precise.origin    = rayOrigin;
        precise.direction = (particleCollisionEvent.intersection - transform.position).normalized;

        //Debug.DrawRay(precise.origin, precise.direction, Color.white, 5f);
        if (Physics.Raycast(precise, out hit, sprayDistance))
        {
            GameObject decal = Instantiate(decalPrefab, bucketFX.transform);
            decal.transform.position = hit.point;

            decal.transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal * -1f);
            decal.transform.Rotate(0f, 0f, randomAngle);

            decal.transform.localScale += new Vector3(randomScale, randomScale, randomScale);
        }
    }
 void EnemyDamage(ParticleCollisionEvent EnemeyHit)
 {
     if (gameObject.CompareTag("Enemy"))
     {
         EnemeyHealth--;
     }
 }
        void OnParticleCollision(GameObject obj)
        {
            if (ps == null)
            {
                Debug.LogError("ParticleSystemHelper: OnParticleCollision: null ps");
                return;
            }

            collisionObject   = obj;
            collisionCollider = obj.GetComponent <Collider>();
            if (collisionCollider == null)
            {
                return;
            }

            collisionEvents.Clear();
            collisionCount = ps.GetCollisionEvents(obj, collisionEvents);

            //Debug.Log("ParticleSystemHelper: OnParticleCollision: obj: " + obj + " ps: " + ps + " collisionCount: " + collisionCount + " collisionObject: " + collisionObject + " collisionCollider: " + collisionCollider);

            for (int i = 0; i < collisionCount; i++)
            {
                ParticleCollisionEvent collision = collisionEvents[i];
                //Debug.Log("ParticleSystemHelper: OnParticleCollision: i: " + i + " collision: " + collision + " colliderComponent: " + collision.colliderComponent + " intersection: " + collision.intersection.x + " " + collision.intersection.y + " " + collision.intersection.z + " " + " normal: " + collision.normal.x + " " + collision.normal.y + " " + collision.normal.x + " velocity: " + collision.velocity.x + " " + collision.velocity.y + " " + collision.velocity.z);
                float r = 0.1f;
                Debug.DrawLine(collision.intersection - (Vector3.up * r), collision.intersection + (Vector3.up * r), Color.red, 1.0f, false);
                Debug.DrawLine(collision.intersection - (Vector3.forward * r), collision.intersection + (Vector3.forward * r), Color.red, 1.0f, false);
                Debug.DrawLine(collision.intersection - (Vector3.right * r), collision.intersection + (Vector3.right * r), Color.red, 1.0f, false);
            }

            SendEventName("ParticleCollision");
        }
Beispiel #13
0
    // OnParticleCollision在Collider所属游戏对象脚本上执行,other为ParticleSystem所属游戏对象
    void OnParticleCollision(GameObject other)
    {
        ParticleSystem ps         = other.GetComponent <ParticleSystem>();
        int            safeLength = ps.GetSafeCollisionEventSize();

        print("safe length = " + safeLength.ToString());
        if (collisionEvents.Length < safeLength)
        {
            collisionEvents = new ParticleCollisionEvent[safeLength];
        }
        int num = ps.GetCollisionEvents(gameObject, collisionEvents);

        print("received collision event number = " + num.ToString());
        for (int i = 0; i < num; ++i)
        {
            ParticleCollisionEvent ev = collisionEvents [i];
            Vector3 pos = ev.intersection;
            if (ev.colliderComponent.tag == "Cube")
            {
                print("hit cube at position : " + pos.Str());
            }
            else if (ev.colliderComponent.tag == "Capsule")
            {
                print("hit capsule at position : " + pos.Str());
            }
            else if (ev.colliderComponent.tag == "Cylinder")
            {
                print("hit cylinder at position : " + pos.Str());
            }
        }
    }
Beispiel #14
0
        void Start()
        {
            p11          = this.gameObject.GetComponent <ParticleSystem>();
            p11Transform = this.gameObject.transform;

            if (ParticlePOOL != null)
            {
                Propagator = ParticlePOOL.GetComponent(typeof(ParticlePropagationSKYMASTER)) as ParticlePropagationSKYMASTER;
            }

            collisionEvents = new ParticleCollisionEvent[1][];

            if (Gameobj_instances != null)
            {
                Gameobj_instances.Clear();
            }

            systems_To_override = new List <ParticlePropagationSKYMASTER>();

            if (Systems_To_override != null)
            {
                if (Systems_To_override.Count > 0)
                {
                    for (int i = 0; i < Systems_To_override.Count; i++)
                    {
                        systems_To_override.Add(Systems_To_override[i].GetComponent(typeof(ParticlePropagationSKYMASTER)) as ParticlePropagationSKYMASTER);
                    }
                }
            }
        }
Beispiel #15
0
    private void OnParticleCollisionManual(GameObject other, int aliveParticles = -1)
    {
        this.collisionEvents.Clear();
        int num  = this.initiatorPS.GetCollisionEvents(other, this.collisionEvents);
        int num2 = 0;

        while (true)
        {
            while (true)
            {
                if (num2 >= num)
                {
                    return;
                }
                ParticleCollisionEvent event2 = this.collisionEvents[num2];
                float num3 = Vector3.Angle(event2.normal, Vector3.up);
                if (num3 <= this.MaxGroundAngleDeviation)
                {
                    if (this.InstantiateWhenZeroSpeed)
                    {
                        if (this.collisionEvents[num2].velocity.sqrMagnitude > 0.1f)
                        {
                            break;
                        }
                        bool flag  = false;
                        int  index = 0;
                        while (true)
                        {
                            if (index < aliveParticles)
                            {
                                ParticleCollisionEvent event4 = this.collisionEvents[num2];
                                float num5 = Vector3.Distance(event4.intersection, this.particles[index].position);
                                if (num5 < this.MinDistanceBetweenDecals)
                                {
                                    flag = true;
                                }
                                index++;
                                continue;
                            }
                            if (!flag)
                            {
                                break;
                            }
                            break;
                        }
                    }
                    ParticleSystem.EmitParams emitParams = new ParticleSystem.EmitParams {
                        position = this.collisionEvents[num2].intersection + (this.collisionEvents[num2].normal * this.MinDistanceBetweenSurface)
                    };
                    Vector3 eulerAngles = Quaternion.LookRotation(-this.collisionEvents[num2].normal).eulerAngles;
                    eulerAngles.z         = Random.Range(0, 360);
                    emitParams.rotation3D = eulerAngles;
                    this.DecalParticles.Emit(emitParams, 1);
                }
                break;
            }
            num2++;
        }
    }
Beispiel #16
0
 void EmitAtLocation(ParticleCollisionEvent particleCollisionEvent)
 {
     splatterParticles.transform.position = particleCollisionEvent.intersection;
     splatterParticles.transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal);
     ParticleSystem.MainModule psMain = splatterParticles.main;
     psMain.startColor = particleColorGradient.Evaluate(Random.Range(0f, 1f));
     splatterParticles.Emit(1);
 }
Beispiel #17
0
 void SetParticleData(ParticleCollisionEvent particleCollisionEvent, Gradient colorGradient)
 {
     if (DecalDataIndex >= maxDecals)
     {
         DecalDataIndex = 0;
     }
     DecalDataIndex++;
 }
Beispiel #18
0
    void OnParticleCollision(GameObject other)
    {
        if (counter > limit && (other.tag == "Floor"))
        {
            ParticleSystem            ps           = GetComponent <ParticleSystem>();
            ParticleSystem.Particle[] particleList = new ParticleSystem.Particle[ps.particleCount];
            ps.GetParticles(particleList);
            ParticleCollisionEvent[] collisions = new ParticleCollisionEvent[ps.GetSafeCollisionEventSize()];
            int noOfCollisions = ps.GetCollisionEvents(other, collisions);

            Instantiate(instantiateObject, new Vector3(collisions[0].intersection.x, collisions[0].intersection.y + 0.01f, collisions[0].intersection.z), Quaternion.Euler(90, Random.Range(0, 360), 0));

            for (int i = 0; i < collisions.Length; i++)
            {
                Instantiate(instantiateObject, new Vector3(collisions[i].intersection.x, collisions[i].intersection.y + 0.01f, collisions[i].intersection.z), Quaternion.Euler(90, Random.Range(0, 360), 0));
            }

            counter = 0;
        }

        if (counter > limit && (other.tag == "Platform"))
        {
            if (privateColor == 0)
            {
                foreach (Renderer childRenderer in other.transform.GetChild(1).GetComponentsInChildren <Renderer>())
                {
                    childRenderer.material.color = Color.blue;
                }
            }
            if (privateColor == 1)
            {
                foreach (Renderer childRenderer in other.transform.GetChild(1).GetComponentsInChildren <Renderer>())
                {
                    childRenderer.material.color = Color.green;
                }
            }
        }
        if (counter > limit && (other.tag == "Enemy"))
        {
            other.GetComponent <EnemyAi2> ().AdDamage(damage, 0);
        }
        if (counter > limit && (other.tag == "EnemySkull"))
        {
            other.GetComponent <EnemyAI3> ().AdDamage(damage, 0);
        }
        if (counter > limit && (other.tag == "Boss"))
        {
            Debug.Log("dsadsa");

            other.GetComponent <EnemyAiBoos> ().AdDamage(damage);
        }
        if ((other.tag == "Boss2"))
        {
            Debug.Log("dsadsa");

            other.GetComponent <EnemyAiBos2> ().AdDamage(damage);
        }
    }
        public void HittedByParticle(ParticleCollisionEvent collisionEvent)
        {
            var decalInstance  = SpawnController.SpawnDecal();
            var decalTransform = decalInstance.transform;

            ApplyDecalTransform(decalTransform, collisionEvent);

            OnHitted(decalInstance, collisionEvent);
        }
Beispiel #20
0
    //particleSystem is the particle system whose particles cause the collision
    void OnParticleCollision(GameObject other)
    {
        ParticleSystem part = other.GetComponent <ParticleSystem>();

        ParticleCollisionEvent[] collisionEvents = new ParticleCollisionEvent[100];
        int numParticles = ParticlePhysicsExtensions.GetCollisionEvents(part, gameObject, collisionEvents);

        this.hp -= numParticles;
    }
Beispiel #21
0
 void EmitAtPos(ParticleCollisionEvent hit)
 {
     splatter.transform.position = hit.intersection;
     splatter.transform.rotation = Quaternion.LookRotation(hit.normal);
     ParticleSystem.MainModule splatterMain;
     splatterMain            = splatter.main;
     splatterMain.startColor = colorsGradient.Evaluate(Random.Range(0f, 1.1f));
     splatter.Emit(1);
 }
 private void EmitAtLocation(ParticleCollisionEvent particleCollisionEvent)
 {
     foreach (var fx in _collisionFX)
     {
         fx.transform.position = particleCollisionEvent.intersection;
         fx.transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal);
         fx.Play();
     }
 }
Beispiel #23
0
    private void EmitAtLocation(ParticleCollisionEvent particleCollisionEvent)
    {
        splashDroplets.transform.position = particleCollisionEvent.intersection;
        splashDroplets.transform.rotation = Quaternion.LookRotation(particleCollisionEvent.normal);
        splashDroplets.Emit(1);
        var coll = oilDroplets.collision;

        coll.enabled = false;
    }
Beispiel #24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="particleCollisionEvent"></param>
 public void ParticleHit(ParticleCollisionEvent particleCollisionEvent)
 {
     _particleHitCallCount++;
     if (_particleHitCallCount > _countOfDecals)
     {
         return;
     }
     SetParticleData(particleCollisionEvent);
     SpawnPrefabs();
 }
Beispiel #25
0
        protected override bool ShouldSpawn(ParticleCollisionEvent particleCollisionEvent)
        {
            var normal = particleCollisionEvent.normal;

            float angle = Vector3.Angle(normal, planeNormal);

            bool shouldSpawn = angle >= minAngle && angle <= maxAngle;

            return(shouldSpawn);
        }
Beispiel #26
0
 void EmitAtLocation(ParticleCollisionEvent pCE)
 {
     /*
      * To set the particle to spawn at the POI (point of intersection) use the following statement
      * collisionParticle.transform.position = pCE.intersection;
      * To calculate rotation
      * collisionParticle.transform.rotation = Quaternion.LookRotation (particleCollisionEvent.normal)
      */
     collisionParticle.Emit(1);
 }
        void ApplyDecalTransform(Transform decalTransform, ParticleCollisionEvent collisionEvent)
        {
            decalTransform.position = collisionEvent.intersection + collisionEvent.normal * Offset;
            ApplyDecalRotationByNormal(decalTransform, collisionEvent.normal);

            if (ParentOnHit)
            {
                decalTransform.SetParent(collisionEvent.colliderComponent.transform);
            }
        }
Beispiel #28
0
 public void OnParticleSplat(ParticleCollisionEvent particleCollisionEvent, float size, Gradient colorGradient)
 {
     if (decalContainer != null)
     {
         Vector3 position = particleCollisionEvent.intersection;
         Vector3 particleRotationEuler = Quaternion.LookRotation(particleCollisionEvent.normal).eulerAngles;
         particleRotationEuler.z = Random.Range(0, 360);
         Color color = colorGradient.Evaluate(Random.Range(0f, 1f));
         decalContainer.AddDecal(position, size, particleRotationEuler, color);
     }
 }
Beispiel #29
0
    private void SpawnBlood(ParticleCollisionEvent particleCollision)
    {
        // Clear the list so it's ready for the next collision
        _collisionEvents.Clear();

        // Get the position of where the collision happened
        Vector3 intersectionPosition = new Vector3(particleCollision.intersection.x, 0.0001f, particleCollision.intersection.z);

        // We spawn a blood quad from the object pool
        _objectPooler.SpawnFromPool("Blood", intersectionPosition, Quaternion.Euler(90, 0, 0));
    }
Beispiel #30
0
    void EmitAtLocation(ParticleCollisionEvent e)
    {
        var emitParams = new ParticleSystem.EmitParams();

        emitParams.position = e.intersection;
        for (var i = 0; i < 3; i++)
        {
            emitParams.velocity = new Vector3(Random.value, Random.value, 0);
            splasher.Emit(emitParams, 1);
        }
    }
 /// <summary>
 ///   <para>Get the particle collision events for a GameObject. Returns the number of events written to the array.</para>
 /// </summary>
 /// <param name="go">The GameObject for which to retrieve collision events.</param>
 /// <param name="collisionEvents">Array to write collision events to.</param>
 /// <param name="ps"></param>
 public static int GetCollisionEvents(this ParticleSystem ps, GameObject go, ParticleCollisionEvent[] collisionEvents)
 {
   return ParticleSystemExtensionsImpl.GetCollisionEvents(ps, go, collisionEvents);
 }