public override void Define() { DistanceEvent @event = null; When() .Match(() => @event); Then() .Do(ctx => ctx.Event(@event)); }
public static DistanceEvent Create(GameObject gameObject, float distance) { DistanceEvent e = new DistanceEvent(); e.Type = QuarkEventType.Distance; e.Id = gameObject.GetInstanceID(); e.Tag = gameObject.tag; e.Distance = distance; return(e); }
public override void AddReward(BaseAgent agent, float[] vectorActions) { if (TagAGameObject == null || TagBGameObject == null) { FindTags(agent); } else { float sqrmag = (TagAGameObject.transform.position - TagBGameObject.transform.position).sqrMagnitude; float byMaxDist = sqrmag / (MaxDistance * MaxDistance); float scaledReward = Mathf.Max((1 - byMaxDist) * Reward, 0) / Mathf.Max((float)agent.agentParameters.maxStep, 1); agent.AddReward(scaledReward); if (agent.area.EventSystem != null) { agent.area.EventSystem.RaiseEvent(DistanceEvent.Create(agent.gameObject, sqrmag)); } } }
/// <summary> /// Sets up the notifications; /// Will call Status /// </summary> /// <param name="notifyType"></param> /// <returns>true if the notify was set up. </returns> public async Task <bool> NotifyDistanceAsync(GattClientCharacteristicConfigurationDescriptorValue notifyType = GattClientCharacteristicConfigurationDescriptorValue.Notify) { if (!await EnsureCharacteristicAsync()) { return(false); } var ch = Characteristics[6]; if (ch == null) { return(false); } GattCommunicationStatus result = GattCommunicationStatus.ProtocolError; try { result = await ch.WriteClientCharacteristicConfigurationDescriptorAsync(notifyType); if (!NotifyDistance_ValueChanged_Set) { // Only set the event callback once NotifyDistance_ValueChanged_Set = true; ch.ValueChanged += (sender, args) => { var datameaning = "U8^20_/_2.54_*|HEX|Distance|cm"; var parseResult = BluetoothDeviceController.BleEditor.ValueParser.Parse(args.CharacteristicValue, datameaning); Distance = parseResult.ValueList.GetValue("Distance").AsDouble; DistanceEvent?.Invoke(parseResult); }; } } catch (Exception e) { Status.ReportStatus($"NotifyDistance: {e.Message}", result); return(false); } Status.ReportStatus($"NotifyDistance: set notification", result); return(true); }