public void SetGunIds(uint[] gunIds) { if (gunIds == null) { return; } var gunsList = gunIds.Select(id => GunDictionary.GetGunSettings(id)).ToArray(); Dictionary <PosturePoint, GunInfo> dic = new Dictionary <PosturePoint, GunInfo>(); ulong uid = 0; foreach (var gun in gunsList) { if (gun == null || dic.ContainsKey(gun.Attached)) { continue; } dic.Add(gun.Attached, gun.GetGunInfo(uid)); uid++; } gunWriter.SendUpdate(new GunComponent.Update { GunsDic = dic }); }
public void SetGunIds(GunIdPair[] gunIds) { if (gunIds == null) { return; } var gunsList = gunIds.Select(pair => GunDictionary.GetGunSettings(pair.Id)).ToArray(); Dictionary <int, GunInfo> dic = new Dictionary <int, GunInfo>(); ulong uid = 0; foreach (var pair in gunIds) { var gun = GunDictionary.GetGunSettings(pair.Id); if (gun == null || dic.ContainsKey(pair.bone)) { continue; } dic.Add(pair.bone, gun.GetGunInfo(uid, pair.bone)); uid++; } gunWriter.SendUpdate(new GunComponent.Update { GunsDic = dic }); }
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); }