Exemplo n.º 1
0
        /// <summary>
        /// Called by weapon when initialize bullet
        /// </summary>
        public virtual void StartJourney()
        {
            if (LifeTime > 0)
            {
                _LifeTimeTW.Begin(LifeTime);
            }
            enabled = true;
            _IsDead = false;

            if (TrailParticle != null && TrailPosition != null)
            {
                _TrailInstance = Skill.Framework.Managers.Cache.Spawn(TrailParticle, TrailPosition.position, TrailPosition.rotation);
                _TrailLifTime  = _TrailInstance.GetComponent <Skill.Framework.Managers.CacheLifeTime>();
                if (_TrailLifTime != null)
                {
                    _TrailLifTime.enabled = false;
                }
                _TrailInstance.transform.parent = TrailPosition;
                _Particle = _TrailInstance.GetComponent <ParticleSystem>();
                _Particle.Clear(true);

                var emission = _Particle.emission;
                emission.enabled = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Call this when bullet reach end of range or hit something or out of life time
        /// </summary>
        protected virtual void OnDie(Collider collider)
        {
            if (_IsDead)
            {
                return;
            }

            Shooter = null;
            Damage  = 0;
            Target  = null;

            if (_Rigidbody != null && !_Rigidbody.isKinematic)
            {
                _Rigidbody.velocity = Vector3.zero;
            }

            _IsDead = true;

            var exp = GetExplosion(collider);

            if (exp != null)
            {
                Skill.Framework.Managers.Cache.Spawn(exp, (ExplosionPos != null) ? ExplosionPos.position : transform.position, exp.transform.rotation);
            }
            if (Events != null)
            {
                Events.RaiseDie(this, System.EventArgs.Empty);
            }
            Target = null;

            if (_TrailInstance != null)
            {
                _TrailInstance.transform.parent = null;
                if (_TrailLifTime != null)
                {
                    _TrailLifTime.enabled = true;
                }

                var emission = _Particle.emission;
                emission.enabled = false;
                _TrailLifTime    = null;
            }


            Cache.DestroyCache(gameObject);
        }