예제 #1
0
 /// <summary>
 /// Handle a ray or somthing Hit this GameObject
 /// </summary>
 /// <param name="sender"> sender </param>
 /// <param name="args"> An HitEventArgs that contains hit event data. </param>
 public void RaiseHit(object sender, HitEventArgs args)
 {
     if (Hit != null)
     {
         Hit(sender, args);
     }
 }
예제 #2
0
 /// <summary>
 /// Handle a ray or somthing Hit this GameObject
 /// </summary>
 /// <param name="sender"> sender </param>
 /// <param name="args"> An HitEventArgs that contains hit event data. </param>
 protected virtual void Events_Hit(object sender, HitEventArgs args)
 {
     if (Hit && Health != null)
     {
         Health.RaiseHit(sender, args);
     }
 }
예제 #3
0
        /// <summary>
        /// Handle a ray or somthing Hit this GameObject
        /// </summary>
        /// <param name="sender"> sender </param>
        /// <param name="args"> An HitEventArgs that contains hit event data. </param>
        protected virtual void Events_Hit(object sender, HitEventArgs args)
        {
            LastHitPoint  = args.Point;
            LastHitNormal = args.Normal;

            if (Events != null)
            {
                Events.RaiseDamage(sender, new DamageEventArgs(args.Damage)
                {
                    UserData = args.UserData, DamageType = args.DamageType, Tag = args.Tag
                });
            }

            if (args.CauseParticle)
            {
                if (HitParticles != null)
                {
                    int selectedParticle = SelectHitParticleToSpawn(args);
                    if (selectedParticle >= 0 && selectedParticle < HitParticles.Length)
                    {
                        GameObject particle = HitParticles[selectedParticle];
                        if (particle != null)
                        {
                            Vector3 normal = InverseHit ? -args.Normal : args.Normal;
                            Cache.Spawn(particle, args.Point, Quaternion.LookRotation(normal));
                        }
                    }
                }
                if (Decals != null && args.Collider != null)
                {
                    int selectedDecale = SelectDecaleToSpawn(args);
                    if (selectedDecale >= 0 && selectedDecale < Decals.Length)
                    {
                        GameObject decal = Decals[selectedDecale];
                        if (decal != null)
                        {
                            //if (UseRaycastForDecal)
                            //{
                            //    _DecaleRay.origin = args.Point + 10 * args.Normal;
                            //    _DecaleRay.direction = -args.Normal;

                            //    if (args.Collider.Raycast(_DecaleRay, out _DecalHit, 12))
                            //    {
                            //        Cache.Spawn(decal, _DecalHit.point + (DecalOffset * _DecalHit.normal), Quaternion.LookRotation(_DecalHit.normal));
                            //    }
                            //}
                            //else
                            //{
                            Cache.Spawn(decal, args.Collider.ClosestPointOnBounds(args.Point) + (DecalOffset * args.Normal), Quaternion.LookRotation(args.Normal));
                            //}
                        }
                    }
                }
            }
        }
예제 #4
0
 /// <summary>
 /// Select Decale based on hit. ( default returns random index)
 /// </summary>
 /// <returns>Index of Decale ( 0 - (Decale.Length - 1) ) to spawn</returns>
 /// <remarks>
 /// It is possible to spawn decales based on incoming bulled. ( normal bullet, Laser bullet, ...)
 /// Type of hit can be specified by 'HitInfo.UserData', 'HitInfo.HitType' or inherit 'HitInfo' or 'HitEventArgs' class and provide custom data and properties
 /// </remarks>
 protected virtual int SelectDecaleToSpawn(HitEventArgs args)
 {
     if (Decals != null && Decals.Length > 0)
     {
         if (Decals.Length == 1)
         {
             return(0);
         }
         else
         {
             return(Random.Range(0, Decals.Length));
         }
     }
     return(-1);
 }
예제 #5
0
 /// <summary>
 /// Select HitParticle based on hit. ( default returns random index)
 /// </summary>
 /// <returns>Index of HitParticle ( 0 - (HitParticle.Length - 1) ) to spawn</returns>
 /// <remarks>
 /// It is possible to spawn hit particles based on incoming bulled. ( normal bullet, Laser bullet, ...)
 /// Type of hit can be specified by 'HitInfo.UserData', 'HitInfo.HitType' or inherit 'HitInfo' or 'HitEventArgs' class and provide custom data and properties
 /// </remarks>
 protected virtual int SelectHitParticleToSpawn(HitEventArgs args)
 {
     if (HitParticles != null && HitParticles.Length > 0)
     {
         if (HitParticles.Length == 1)
         {
             return(0);
         }
         else
         {
             return(Random.Range(0, HitParticles.Length));
         }
     }
     return(-1);
 }
예제 #6
0
 /// <summary>
 /// Handle a ray or somthing Hit this GameObject
 /// </summary>
 /// <param name="sender"> sender </param>
 /// <param name="args"> An HitEventArgs that contains hit event data. </param>
 protected virtual void Events_Hit(object sender, HitEventArgs args)
 {
 }