Advertisement
devomage

DynamicMagicProjectile.cs

May 16th, 2020
1,936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.41 KB | None | 0 0
  1. namespace UCCFocus.Objects.ItemAssist
  2. {
  3.     using Opsive.Shared.Game;
  4.     using UnityEngine;
  5.     using Opsive.UltimateCharacterController.Objects.ItemAssist;
  6.  
  7.     /// <summary>
  8.     /// Custom ricochet.
  9.     /// </summary>
  10.     public class DynamicMagicProjectile : MagicProjectile
  11.     {
  12.         [Tooltip("Should the projectile ricochet?")]
  13.         [SerializeField] protected bool m_Ricochet;
  14.         [Tooltip("Bounce Max.")]
  15.         [SerializeField] protected byte m_RicochetMax;
  16.         [Tooltip("Clip to play on impact.")]
  17.         [SerializeField] protected AudioClip m_RicochetClip;
  18.  
  19.         public AudioClip RicochetClip { get { return m_RicochetClip; } set { m_RicochetClip = value; } }
  20.         public bool Ricochet { get { return m_Ricochet; } set { m_Ricochet = value; } }
  21.         public byte RicochetMax { get { return m_RicochetMax; } set { m_RicochetMax = value; } }
  22.  
  23.         private byte m_RicochetCount;
  24.  
  25.  
  26.         /// <summary>
  27.         /// The object has collided with another object.
  28.         /// </summary>
  29.         /// <param name="hit">The RaycastHit of the object. Can be null.</param>
  30.         protected override void OnCollision(RaycastHit? hit)
  31.         {
  32.             if (Ricochet)
  33.             {
  34.  
  35.             }
  36.             else
  37.             {
  38.                 BaseOnCollision(hit);
  39.             }
  40.         }
  41.  
  42.         /// <summary>
  43.         /// MagicProjectile base code for OnCollision().
  44.         /// </summary>
  45.         private void BaseOnCollision(RaycastHit? hit)
  46.         {
  47.             base.OnCollision(hit);
  48.  
  49.             if (!hit.HasValue)
  50.             {
  51.                 return;
  52.             }
  53.  
  54.             m_MagicItem.PerformImpact(m_CastID, m_GameObject, hit.Value.transform.gameObject, hit.Value);
  55.  
  56.             // Destroys the projectile when it has collided with an object.
  57.             if (m_DestroyOnCollision)
  58.             {
  59.                 // The projectile can wait for any particles to stop emitting.
  60.                 var immediateDestroy = !m_WaitForParticleStop;
  61.                 if (!immediateDestroy)
  62.                 {
  63.                     var particleSystem = m_GameObject.GetCachedComponent<ParticleSystem>();
  64.                     if (particleSystem != null)
  65.                     {
  66.                         particleSystem.Stop(true, ParticleSystemStopBehavior.StopEmitting);
  67.                         Scheduler.Schedule(particleSystem.main.duration, ReturnToObjectPool);
  68.                         immediateDestroy = false;
  69.                     }
  70.                 }
  71.                 if (immediateDestroy)
  72.                 {
  73.                     ReturnToObjectPool();
  74.                 }
  75.                 else
  76.                 {
  77.                     // The projectile is waiting on the particles to be destroyed. Stop moving.
  78.                     Stop();
  79.                 }
  80.             }
  81.         }
  82.  
  83.         /// <summary>
  84.         /// Returns the projectile back to the object pool.
  85.         /// </summary>
  86.         private void ReturnToObjectPool()
  87.         {
  88. #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
  89.             if (NetworkObjectPool.IsNetworkActive()) {
  90.                 // The object may have already been destroyed over the network.
  91.                 if (!m_GameObject.activeSelf) {
  92.                     return;
  93.                 }
  94.                 NetworkObjectPool.Destroy(m_GameObject);
  95.                 return;
  96.             }
  97. #endif
  98.             ObjectPool.Destroy(m_GameObject);
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement