public void Execute(JSONNode args) { var uid = args["uid"].Value; var waypoints = args["waypoints"].AsArray; var loop = args["loop"]; var api = ApiManager.Instance; if (waypoints.Count == 0) { api.SendError(this, $"Waypoint list is empty"); return; } if (api.Agents.TryGetValue(uid, out GameObject obj)) { var npc = obj.GetComponent <NPCController>(); if (npc == null) { api.SendError(this, $"Agent '{uid}' is not a NPC agent"); return; } var wp = new List <DriveWaypoint>(); for (int i = 0; i < waypoints.Count; i++) { var deactivate = waypoints[i]["deactivate"]; var ts = waypoints[i]["timestamp"]; wp.Add(new DriveWaypoint() { Position = waypoints[i]["position"].ReadVector3(), Speed = waypoints[i]["speed"].AsFloat, Angle = waypoints[i]["angle"].ReadVector3(), Idle = waypoints[i]["idle"].AsFloat, Deactivate = deactivate.IsBoolean ? deactivate.AsBool : false, TriggerDistance = waypoints[i]["trigger_distance"].AsFloat, TimeStamp = (ts == null) ? -1 : waypoints[i]["timestamp"].AsFloat, Trigger = WaypointTrigger.DeserializeTrigger(waypoints[i]["trigger"]) });; } var loopValue = loop.IsBoolean ? loop.AsBool : false; var waypointFollow = npc.SetBehaviour <NPCWaypointBehaviour>(); waypointFollow.SetFollowWaypoints(wp, loop); // TODO use NPCController to init waypoint data api.RegisterAgentWithWaypoints(npc.gameObject); api.SendResult(this); } else { api.SendError(this, $"Agent '{uid}' not found"); } }
public void Execute(JSONNode args) { var uid = args["uid"].Value; var waypoints = args["waypoints"].AsArray; var loop = args["loop"].AsBool; var api = ApiManager.Instance; if (waypoints.Count == 0) { api.SendError(this, $"Waypoint list is empty"); return; } if (api.Agents.TryGetValue(uid, out GameObject obj)) { var ped = obj.GetComponent <PedestrianController>(); if (ped == null) { api.SendError(this, $"Agent '{uid}' is not a pedestrian agent"); return; } var wp = new List <WalkWaypoint>(); for (int i = 0; i < waypoints.Count; i++) { wp.Add(new WalkWaypoint() { Position = waypoints[i]["position"].ReadVector3(), Speed = waypoints[i]["speed"].AsFloat, Idle = waypoints[i]["idle"].AsFloat, TriggerDistance = waypoints[i]["trigger_distance"].AsFloat, Trigger = WaypointTrigger.DeserializeTrigger(waypoints[i]["trigger"]) }); } ped.FollowWaypoints(wp, loop); api.RegisterAgentWithWaypoints(ped.gameObject); api.SendResult(this); } else { api.SendError(this, $"Agent '{uid}' not found"); } }
public void Execute(JSONNode args) { var api = ApiManager.Instance; var uid = args["uid"].Value; var waypoints = args["waypoints"].AsArray; // Try parse the path type, set linear as default var pathTypeNode = args["waypoints_path_type"]; WaypointsPathType waypointsPathType; if (pathTypeNode == null) { waypointsPathType = WaypointsPathType.Linear; } else if (!Enum.TryParse(pathTypeNode, true, out waypointsPathType)) { waypointsPathType = WaypointsPathType.Linear; api.SendError(this, $"Could not parse the waypoints path type \"{waypointsPathType}\"."); } var loop = args["loop"].AsBool; if (waypoints.Count == 0) { api.SendError(this, $"Waypoint list is empty"); return; } if (api.Agents.TryGetValue(uid, out GameObject obj)) { var ped = obj.GetComponent <PedestrianController>(); if (ped == null) { api.SendError(this, $"Agent '{uid}' is not a pedestrian agent"); return; } var wp = new List <WalkWaypoint>(); var previousPosition = ped.transform.position; for (int i = 0; i < waypoints.Count; i++) { var position = waypoints[i]["position"].ReadVector3(); var angle = waypoints[i].HasKey("angle") ? waypoints[i]["angle"].ReadVector3() : Quaternion.LookRotation((position - previousPosition).normalized).eulerAngles; wp.Add(new WalkWaypoint() { Position = position, Angle = angle, Speed = waypoints[i]["speed"].AsFloat, Idle = waypoints[i]["idle"].AsFloat, TriggerDistance = waypoints[i]["trigger_distance"].AsFloat, Trigger = WaypointTrigger.DeserializeTrigger(waypoints[i]["trigger"]) }); previousPosition = position; } var waypointBehaviour = ped.SetBehaviour <PedestrianWaypointBehaviour>(); waypointBehaviour.SetFollowWaypoints(wp, loop, waypointsPathType); api.RegisterAgentWithWaypoints(ped.gameObject); api.SendResult(this); } else { api.SendError(this, $"Agent '{uid}' not found"); } }
public void Execute(JSONNode args) { var api = ApiManager.Instance; var uid = args["uid"].Value; var waypoints = args["waypoints"].AsArray; // Try parse the path type, set linear as default var pathTypeNode = args["waypoints_path_type"]; WaypointsPathType waypointsPathType; if (pathTypeNode == null) { waypointsPathType = WaypointsPathType.Linear; } else if (!Enum.TryParse(pathTypeNode, true, out waypointsPathType)) { waypointsPathType = WaypointsPathType.Linear; api.SendError(this, $"Could not parse the waypoints path type \"{waypointsPathType}\"."); } var loop = args["loop"]; if (waypoints.Count == 0) { api.SendError(this, $"Waypoint list is empty"); return; } if (api.Agents.TryGetValue(uid, out GameObject obj)) { var npc = obj.GetComponent <NPCController>(); if (npc == null) { api.SendError(this, $"Agent '{uid}' is not a NPC agent"); return; } var wp = new List <DriveWaypoint>(); var previousPosition = npc.transform.position; for (int i = 0; i < waypoints.Count; i++) { var deactivate = waypoints[i]["deactivate"]; var ts = waypoints[i]["timestamp"]; var position = waypoints[i]["position"].ReadVector3(); var angle = waypoints[i].HasKey("angle") ? waypoints[i]["angle"].ReadVector3() : Quaternion.LookRotation((position - previousPosition).normalized).eulerAngles; wp.Add(new DriveWaypoint() { Position = position, Speed = waypoints[i]["speed"].AsFloat, Acceleration = waypoints[i]["acceleration"].AsFloat, Angle = angle, Idle = waypoints[i]["idle"].AsFloat, Deactivate = deactivate.IsBoolean ? deactivate.AsBool : false, TriggerDistance = waypoints[i]["trigger_distance"].AsFloat, TimeStamp = (ts == null) ? -1 : waypoints[i]["timestamp"].AsFloat, Trigger = WaypointTrigger.DeserializeTrigger(waypoints[i]["trigger"]) }); previousPosition = position; } var loopValue = loop.IsBoolean && loop.AsBool; var waypointFollow = npc.SetBehaviour <NPCWaypointBehaviour>(); waypointFollow.SetFollowWaypoints(wp, loopValue, waypointsPathType); // TODO use NPCController to init waypoint data api.RegisterAgentWithWaypoints(npc.gameObject); api.SendResult(this); } else { api.SendError(this, $"Agent '{uid}' not found"); } }
/// <summary> /// Deserializes a trigger from the json data /// </summary> /// <param name="trigger">Trigger object to fill with effectors</param> /// <param name="triggerNode">Json data with a trigger</param> private static void DeserializeTrigger(ScenarioTrigger trigger, JSONNode triggerNode) { trigger.Trigger = WaypointTrigger.DeserializeTrigger(triggerNode); }
/// <summary> /// Deserializes a trigger from the json data /// </summary> /// <param name="trigger">Trigger object to fill with effectors</param> /// <param name="triggerNode">Json data with a trigger</param> private void DeserializeTrigger(ScenarioTrigger trigger, JSONNode triggerNode) { trigger.Trigger = WaypointTrigger.DeserializeTrigger(triggerNode); trigger.TargetAgentType = ParentAgent.Type; }