private void EventReportReceived(EventReportPDU eventReportPdu) { uint eventType = eventReportPdu.EventType; if (subscribersByEventType.ContainsKey(eventType) && subscribersByEventType[eventType].Count > 0) { if (eventReportsTypes.ContainsKey(eventType)) { Type eventReportType = eventReportsTypes[eventType]; BaseCustomEventReport o = (BaseCustomEventReport)Activator.CreateInstance(eventReportType); var eventReportData = new CustomEventReportEncoder(eventReportPdu, o); o.SenderId = eventReportData.SenderId; o.ReceiverId = eventReportData.ReceiverId; foreach (var field in eventReportType.GetFields()) { field.SetValue(o, eventReportData.Read(field.FieldType, field)); } foreach (var subscriber in subscribersByEventType[eventType]) { subscriber(o); } } } }
public CustomEventReportEncoder(uint eventType, object target) { EventReportPdu = new EventReportPDU(); EventReportPdu.EventType = eventType; this.target = target; }
public CustomEventReportEncoder(EventReportPDU pduToRead, object target) { readingFixedIndex = readingVarIndex = 0; EventReportPdu = pduToRead; this.target = target; }
void Update() { if (Input.GetKeyDown(KeyCode.Z)) { FirePDU fire = new FirePDU(); fire.EventId = new EventId(8, 9, 10); fire.BurstDescriptor.Munition = new EntityType(1, 2, 3, 4, 5, 6, 7); fire.Location = new Vector3Double(11, 22, 33); ExerciseConnection.Instance.SendPDU(fire); } if (Input.GetKeyDown(KeyCode.X)) { DetonationPDU detoantion = new DetonationPDU(); detoantion.EventId = new EventId(999, 888, 777); detoantion.BurstDescriptor.Munition = new EntityType(9, 8, 7, 6, 5, 4, 3); detoantion.Location = new Vector3Double(11, 22, 33); ExerciseConnection.Instance.SendPDU(detoantion); } if (Input.GetKeyDown(KeyCode.C)) { EventReportPDU eventReport = new EventReportPDU(); eventReport.EventType = 33; eventReport.FixedDatumRecords.Add(new FixedDatumRecord() { FixedDatumID = 12, FixedDatumValue = 34 }); eventReport.VariableDatumRecords.Add(new VariableDatumRecord() { VariableDatumID = 55, VariableDatumValue = new byte[] { 0x11, 0x22, 0x33, 0x44 } }); eventReport.VariableDatumRecords.Add(new VariableDatumRecord() { VariableDatumID = 70, VariableDatumValue = System.Text.Encoding.UTF8.GetBytes("Hello!") }); ExerciseConnection.Instance.SendPDU(eventReport); } if (Input.GetKeyDown(KeyCode.V)) { var sampleEventReport = new SampleEventReport(); sampleEventReport.A = 123.456f; sampleEventReport.B = 789; CustomEventReportsManager.Instance.Send(sampleEventReport); } if (Input.GetKeyDown(KeyCode.B)) { var damageState = (DamageState)UnityEngine.Random.Range(0, 4); var lifeformState = (LifeformState)UnityEngine.Random.Range(0, 10); var primaryWeaponState = (WeaponState)UnityEngine.Random.Range(0, 4); _publishedEntity.State.Appearance.DamageState = damageState; _publishedEntity.State.Appearance.LifeformState = lifeformState; _publishedEntity.State.Appearance.PrimaryWeaponState = primaryWeaponState; Debug.Log($"Set damageState={damageState} lifeformState={lifeformState} primaryWeaponState={primaryWeaponState}"); } if (Input.GetKeyDown(KeyCode.N)) { var reflectedEntity = FindObjectOfType <ReflectedEntity>(); var damageState = reflectedEntity.State.Appearance.DamageState; var lifeformState = reflectedEntity.State.Appearance.LifeformState; var primaryWeaponState = reflectedEntity.State.Appearance.PrimaryWeaponState; Debug.Log($"RefletedEntity damageState={damageState} lifeformState={lifeformState} primaryWeaponState={primaryWeaponState}"); } UpdateMovement(); }