Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace UCCFocus.Objects.ItemAssist
- {
- using Opsive.Shared.Game;
- using UnityEngine;
- using Opsive.UltimateCharacterController.Objects.ItemAssist;
- /// <summary>
- /// Custom ricochet.
- /// </summary>
- public class DynamicMagicProjectile : MagicProjectile
- {
- [Tooltip("Should the projectile ricochet?")]
- [SerializeField] protected bool m_Ricochet;
- [Tooltip("Bounce Max.")]
- [SerializeField] protected byte m_RicochetMax;
- [Tooltip("Clip to play on impact.")]
- [SerializeField] protected AudioClip m_RicochetClip;
- public AudioClip RicochetClip { get { return m_RicochetClip; } set { m_RicochetClip = value; } }
- public bool Ricochet { get { return m_Ricochet; } set { m_Ricochet = value; } }
- public byte RicochetMax { get { return m_RicochetMax; } set { m_RicochetMax = value; } }
- private byte m_RicochetCount;
- /// <summary>
- /// The object has collided with another object.
- /// </summary>
- /// <param name="hit">The RaycastHit of the object. Can be null.</param>
- protected override void OnCollision(RaycastHit? hit)
- {
- if (Ricochet)
- {
- }
- else
- {
- BaseOnCollision(hit);
- }
- }
- /// <summary>
- /// MagicProjectile base code for OnCollision().
- /// </summary>
- private void BaseOnCollision(RaycastHit? hit)
- {
- base.OnCollision(hit);
- if (!hit.HasValue)
- {
- return;
- }
- m_MagicItem.PerformImpact(m_CastID, m_GameObject, hit.Value.transform.gameObject, hit.Value);
- // Destroys the projectile when it has collided with an object.
- if (m_DestroyOnCollision)
- {
- // The projectile can wait for any particles to stop emitting.
- var immediateDestroy = !m_WaitForParticleStop;
- if (!immediateDestroy)
- {
- var particleSystem = m_GameObject.GetCachedComponent<ParticleSystem>();
- if (particleSystem != null)
- {
- particleSystem.Stop(true, ParticleSystemStopBehavior.StopEmitting);
- Scheduler.Schedule(particleSystem.main.duration, ReturnToObjectPool);
- immediateDestroy = false;
- }
- }
- if (immediateDestroy)
- {
- ReturnToObjectPool();
- }
- else
- {
- // The projectile is waiting on the particles to be destroyed. Stop moving.
- Stop();
- }
- }
- }
- /// <summary>
- /// Returns the projectile back to the object pool.
- /// </summary>
- private void ReturnToObjectPool()
- {
- #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
- if (NetworkObjectPool.IsNetworkActive()) {
- // The object may have already been destroyed over the network.
- if (!m_GameObject.activeSelf) {
- return;
- }
- NetworkObjectPool.Destroy(m_GameObject);
- return;
- }
- #endif
- ObjectPool.Destroy(m_GameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement