Exemplo n.º 1
0
            public void OnFire(BulletFireInfo info, bool detectCollisions)
            {
                // check
                Rigidpair bullet;

                if (deactiveQueue.Count > 1)
                {
                    bullet = deactiveQueue.Dequeue();
                }
                else
                {
                    var go = Instantiate(this.BulletObject, this.bulletParent);
                    bullet = new Rigidpair(go.GetComponent <Rigidbody>());
                }

                bullet.IsActive               = true;
                bullet.Rigid.useGravity       = true;
                bullet.Rigid.isKinematic      = false;
                bullet.Rigid.detectCollisions = detectCollisions;

                var pos = info.LaunchPosition.ToUnityVector();

                pos += Origin;
                bullet.Rigid.position           = pos;
                bullet.Rigid.transform.position = pos;

                var vec = info.InitialVelocity.ToUnityVector();;

                bullet.Rigid.transform.forward = vec.normalized;
                bullet.Rigid.velocity          = vec;
                bullet.Rigid.angularVelocity   = Vector3.zero;
                bullet.Fire.Value = new BulletInfo(info);

                // add
                var key = info.ShooterEntityId;
                var id  = info.BulletId;

                if (bulletsDic.ContainsKey(key))
                {
                    var dic = bulletsDic[key];
                    if (dic.ContainsKey(id))
                    {
                        dic[id] = bullet;
                    }
                    else
                    {
                        dic.Add(id, bullet);
                    }
                }
                else
                {
                    var dic = new Dictionary <ulong, Rigidpair>();
                    dic.Add(id, bullet);
                    bulletsDic.Add(key, dic);
                }
            }
Exemplo n.º 2
0
        public void OnFire(PosturePoint point)
        {
            if (this.SpatialComp == null || this.BulletWriter == null)
            {
                return;
            }

            var time = Time.time;

            if (time - fireTime <= interval)
            {
                return;
            }

            var muzzle = GetMuzzleTransform(point);

            if (muzzle == null)
            {
                return;
            }

            fireTime = time;

            var pos = muzzle.position - origin;
            var vec = muzzle.forward;

            vec *= bulletSpeed;

            var id   = this.BulletWriter.Data.CurrentId;
            var fire = new BulletFireInfo()
            {
                Power           = 1,
                Type            = 1,
                Alignment       = 3,
                LaunchPosition  = pos.ToFixedPointVector3(),
                InitialVelocity = vec.ToFixedPointVector3(),
                LaunchTime      = Time.time,
                LifeTime        = lifeTime,
                GunId           = 0,
                ShooterEntityId = SpatialComp.EntityId.Id,
                BulletId        = id,
            };

            this.BulletWriter.SendUpdate(new BulletComponent.Update
            {
                CurrentId = id + 1
            });
            this.BulletWriter.SendFiresEvent(fire);
        }
Exemplo n.º 3
0
 public BulletInfo(BulletFireInfo fire)
 {
     Power           = fire.Power;
     Type            = fire.Type;
     Alignment       = fire.Alignment;
     LaunchPosition  = fire.LaunchPosition;
     InitialVelocity = fire.InitialVelocity;
     CurrentVelocity = InitialVelocity;
     LaunchTime      = fire.LaunchTime;
     LifeTime        = fire.LifeTime();
     GunId           = fire.GunId;
     ShooterEntityId = fire.ShooterEntityId;
     BulletId        = fire.BulletId;
     active          = 1;
 }
 private void Fire(BulletFireInfo info)
 {
     base.Creator?.OnFire(info);
 }
Exemplo n.º 5
0
        public void OnFire(int bone, uint gunId)
        {
            if (this.SpatialComp == null || this.BulletWriter == null)
            {
                return;
            }

            var gun = GunDictionary.GetGunSettings(gunId);

            if (gun == null)
            {
                return;
            }

            var time = Time.time;

            fireTimeDic = fireTimeDic ?? new Dictionary <int, float>();

            float fireTime = 0.0f;

            fireTimeDic.TryGetValue(bone, out fireTime);

            if (time - fireTime <= gun.Inter)
            {
                return;
            }

            var cannon = GetMuzzleTransform(bone);

            if (cannon == null)
            {
                return;
            }

            fireTimeDic[bone] = time;

            var pos = cannon.Muzzle.position - origin;
            var vec = cannon.Forward;

            vec *= gun.BulletSpeed;

            var id   = this.BulletWriter.Data.CurrentId;
            var fire = new BulletFireInfo()
            {
                Power           = 1,
                Type            = gun.BulletTypeId,
                Alignment       = 3,
                LaunchPosition  = pos.ToFixedPointVector3(),
                InitialVelocity = vec.ToFixedPointVector3(),
                LaunchTime      = Time.time,
                GunId           = gunId,
                ShooterEntityId = SpatialComp.EntityId.Id,
                BulletId        = id,
            };

            this.BulletWriter.SendUpdate(new BulletComponent.Update
            {
                CurrentId = id + 1
            });
            this.BulletWriter.SendFiresEvent(fire);
        }