Region System

ExampleRegionSystem

Purpose

This example scene shows how to programmatically create regions of interest on the terrain, and track the movement of individuals and groups in and out of these regions using a Region Service.

How to Use

Maneuver the leader soldier in and out of the visualized region using the W-A-S-D keys on your keyboard, or right-click on a destination. On-screen messages will appear when either agent enters or exists the region, as well as messages when the group collectively enters or exists the region.

Scene Location & Name

Assets/Ride/Examples/Services/Region/ExampleRegionSystem.unity

Setup Requirements 

Region System

Utilize the RIDE Region System by adding the necessary code to the script that initializes your scene. Begin by creating a new RegionSystem object, then add this object as a System using RIDE’s system access system.

Inform the Region System about all of the regions of interest by adding them one at a time. Each polygonal region is defined as an ordered array of RideVector2 points, which represents each of the vertices of the polygon. Points can be ordered in either clockwise or counter clockwise directions around the polygon, but must not define edges that cross. Adding an array of points to the Region System returns a new RideID for the defined region.

Monitoring agents and groups

A Region System can be configured to dispatch RIDE world events whenever a specified agent or group enters or exists defined regions, using the MonitorAgent and MonitorGroup functions provided by the system with the corresponding RideID identifiers. The data dispatched in these events are “RegionChangeEvent” data types, and identified by the labels “agentEnterRegion”, “agentExitRegion”, “groupEnterRegion”, and “groupExitRegion”. Use the RIDE world state system to add specific listeners and functions for these events.

For groups, entry and exit of a region is determined by the group’s average location (centroid). Because of this, it is possible that world events will be dispatched when no member of the group is within the region bounds, e.g., when the groups is split into two subgroups that are in disparate places on the terrain, where the defined region lies between them.

Unity Region Visualizer

Create a new UnityRegionVisualizer object in your initialization script to draw the edges of a region in a Unity scene. Using the visualizers DrawRegion command, pass the RideID of the region and the region system, along with an (optional) color.