internal static PhysicalEntity TryGet(IntPtr IPhysicalEntityHandle) { #if !(RELEASE && RELEASE_DISABLE_CHECKS) if (IPhysicalEntityHandle == IntPtr.Zero) { throw new NullPointerException(); } #endif var physicalEntity = PhysicalEntities.FirstOrDefault(x => x.Handle == IPhysicalEntityHandle); if (physicalEntity == null) { switch (NativePhysicsMethods.GetPhysicalEntityType(IPhysicalEntityHandle)) { case PhysicalizationType.Static: case PhysicalizationType.Rigid: case PhysicalizationType.WheeledVehicle: case PhysicalizationType.Articulated: case PhysicalizationType.Soft: case PhysicalizationType.Rope: physicalEntity = new PhysicalEntity(IPhysicalEntityHandle); break; case PhysicalizationType.Living: physicalEntity = new PhysicalEntityLiving(IPhysicalEntityHandle); break; case PhysicalizationType.Particle: physicalEntity = new PhysicalEntityParticle(IPhysicalEntityHandle); break; case PhysicalizationType.Area: physicalEntity = new PhysicalEntityArea(IPhysicalEntityHandle); break; } if (physicalEntity != null) { PhysicalEntities.Add(physicalEntity); } } return(physicalEntity); }
void OnTriggerEnter2D(Collider2D other) { bool destroy = false; // Block Mask if (TagName.BlockMask.Contains(other.tag)) { destroy = true; } // Mortality Mortality mortality = other.GetComponent <Mortality>(); if (mortality != null) { if (other.gameObject != sender) { // Si projectile AMI if (tag.Equals(TagName.FriendlyProjectiles)) { PhysicalEntities physics = other.GetComponent <PhysicalEntities>(); //Ne recherche que les collisions avec les ennemys if (other.tag.Equals(TagName.Enemy)) { destroy = true; mortality.DecrementHealth(damage); if (physics != null && physics.bumpSensible) { Vector2 direction = other.transform.position - transform.position; //direction entre this and target direction.Normalize(); physics.ApplyForce(direction * bumpForce); } } if (TagName.BlockMask.Contains(other.tag)) { destroy = true; mortality.DecrementHealth(damage); } } // Si projectile ENEMY if (tag.Equals(TagName.EnemyProjectiles)) { //Ne recherche que les collisions avec les friendly if (other.tag.Equals(TagName.Friendly)) { PhysicalEntities physics = other.GetComponent <PhysicalEntities>(); destroy = true; mortality.DecrementHealth(damage); if (physics != null && physics.bumpSensible) { Vector2 direction = other.transform.position - transform.position; //direction entre this and target direction.Normalize(); physics.ApplyForce(direction * bumpForce); } } } } } // Destroy if (destroy) { gameObject.SetActive(false); // Explosion if (explosion != null) { for (int i = 0; i < 3; i++) { Vector3 p = new Vector3(Random.Range(-0.2f, 0.2f), Random.Range(-0.2f, 0.2f), 0); GameObject g = ObjectPool.instance.GetPooledObject(explosion); g.GetComponent <Explosion>().Init(); g.transform.position = new Vector2(transform.position.x + p.x, transform.position.y + p.y); //Instantiate(explosion, new Vector2(transform.position.x + p.x, transform.position.y + p.y), Quaternion.identity); } } } }