Code and your own UI

Nothing here is needed for the main jobs. Everything is in the RareGeometry.Bearing namespace.

Waypoints from code #

var w = gameObject.AddComponent<Waypoint>();
w.Label = "Old Mill";
w.Icon = WaypointIcon.Flag;
w.IsObjective = true;
w.Reached += wp => Debug.Log("Reached " + wp.Label);

w.Hide();   // switch off (markers disappear)
w.Show();   // switch on

A waypoint with no object of yours (a quest coordinate):

var drop = Waypoint.CreateAt(new Vector3(120f, 0f, 40f), "Drop Zone", WaypointIcon.Pin);
drop.Position = newPosition;
drop.SetAsCurrentObjective();   // the only objective now
drop.Remove();                  // gone

Useful: WaypointRegistry.Waypoints, WaypointRegistry.CurrentObjective, WaypointRegistry.FindById(id), WaypointRegistry.FindAll(label, list), WaypointRegistry.SetGroupVisible(group, visible), the Added and Removed events, and ResetReached() for pooled objects.

The HUD from code #

var hud = WaypointHud.Main;
hud.UsePreset(WaypointPreset.Tactical);
hud.ShowRadar = false;
hud.Units = WaypointUnits.Feet;
hud.RadarZoom = 2f;            // closer
hud.SetCamera(vehicleCamera);  // camera switches (null = Main Camera)
hud.SetPlayer(newCharacter);   // null = the object tagged Player
hud.SetVisible(false);         // cutscenes and menus
float ms = hud.LastDrawMilliseconds; // the HUD's own cost last frame
hud.Style.Marker.iconSize = 40f;
hud.Style.Touch();             // after changing style fields from code

Your own UI #

Each frame the HUD works out, for every waypoint: distance, height, whether it's on screen, its screen position and edge angle, its compass bearing and its radar point. Read it after the Drawn event:

hud.Drawn += h =>
{
    if (h.TryGetView(myWaypoint, out var v) && !v.IsOnScreen)
        myArrow.SetPositionAndAngle(v.ScreenPosition, v.ScreenAngle);
};

Switch off the parts you replace (ShowMarkers, ShowEdgeArrows, ShowCompass, ShowRadar) and keep the rest. WaypointView.Reason says why a waypoint isn't drawn.

Your own part, drawn every frame #

Turn Bearing's part off (the HUD's Show switches), then add your own display:

sealed class MyCompass : IWaypointDisplay
{
    public void Draw(WaypointHud hud, IReadOnlyList<WaypointView> views)
    {
        foreach (var v in views)
            if (v.CompassShown || v.Waypoint.IsObjective) PlaceIcon(v.Waypoint, v.Bearing);
    }
}
hud.ShowCompass = false;
hud.AddDisplay(new MyCompass());

Each view has the screen position and angle (markers, edge arrows), Bearing (a compass), RadarPoint (a minimap), Distance, Height and what Bearing itself showed. The list is for this frame only.

Words for other languages #

Every word Bearing shows (the style's words, the controls bar, the place card, the player options, place, region and area names) goes through one place, WaypointText:

  • Text Table (Create > Bearing > Text Table): press Collect Words to list every word (from your styles, the places in the open scenes, and the words shown while you played), write yours next to each, then set it on the HUD (More > Language) or with WaypointText.Table = table;.
  • Unity Localization: add Waypoint Localization (it appears when the Localization package is installed) and pick a String Table whose keys are Bearing's English words. When the player changes language, the HUD changes with it.
  • Your own system: WaypointText.Translator = english => MyLocalisation.Get(english); and call WaypointText.Refresh() when the language changes.

Format words keep their {0}, {name}, {found} and {total}. Player marks keep the names players typed. Units: DistanceText.MetreSuffix, KilometreSuffix, FootSuffix, MileSuffix.

Your own banners #

hud.ShowBanner("Bridge repaired", "Chapter 2"); shows your own banner in the style's banner look, queued behind any showing now. WaypointSaveKeys uses it to say "Saved" and "Loaded".

Your own input #

Bearing reads only the map key (M), the debug overlay key (F8) and, with the Input System package, the gamepad on the open map. To drive it from your own input code (Rewired, your own actions), set the two hooks in BearingInput:

BearingInput.KeyDownOverride = key => myInput.WasPressed(key);
BearingInput.PadOverride = () => new WaypointPadState { Move = myInput.MapMove, Place = myInput.Confirm };

Or turn the keys off (Map key None on the HUD) and call hud.ToggleMap(), ZoomMap and PanMap yourself.

Saving #

WaypointSave.Capture() and WaypointSave.Restore(text); see Objective trails, events and saving. Or let Bearing save itself: RareGeometry.Core.SaveService.Save("slot1") and Load("slot1") store every waypoint, fog, region and the player's pin under the key bearing.waypoints (one JSON file per slot, or your save product when one is installed). Every waypoint and region carries a StableId, so the same object is found again.

Explaining #

WaypointDiagnostics.Explain(waypoint) returns the same plain sentence as the debugger.

Something unclear or wrong? Tell us · Get help