Code Customization

advanced scripting

Compass Navigator Pro 3 · Scripting Support (C#)

This guide covers the recommended approaches for customizing Compass Navigator Pro behavior through code, ordered from simplest to most advanced.

1. Events

The simplest way to react to compass activity. Subscribe to UnityEvents on the CompassPro instance to run your code when something happens, without modifying any source files.

UI Creation Events

These events fire when the compass creates UI elements for a POI. Use them to customize icons or indicators right after they are instantiated:

UnityEvent<CompassProPOI, GameObject> OnCompassBarIconCreated

Fired when a compass bar icon is created. Use this to add components, change sprites, or modify the icon hierarchy.

UnityEvent<CompassProPOI, GameObject> OnIndicatorCreated

Fired when an on-screen/off-screen indicator is created.

UnityEvent<CompassProPOI, GameObject> OnMiniMapIconCreated

Fired when a minimap icon is created.

Example: Add a pulsing effect to boss icons

void Start() {
    CompassPro compass = CompassPro.instance;
    compass.OnCompassBarIconCreated.AddListener(CustomizeIcon);
    compass.OnMiniMapIconCreated.AddListener(CustomizeIcon);
}

void CustomizeIcon(CompassProPOI poi, GameObject iconGO) {
    if (poi.CompareTag("Boss")) {
        iconGO.AddComponent<PulseAnimation>();
    }
}

See the Scripting Support page for the complete list of events.

2. Partial Classes

CompassPro is declared as a partial class, which means you can extend it by adding your own partial class file. This lets you add new methods, properties, or fields to the compass without modifying any existing source files.

How it works

  1. Create a new C# file anywhere in your project (outside the CompassNavigatorPro folder so updates don't overwrite it).
  2. Declare a partial class with the same namespace and class name.
  3. Add your custom methods or properties.

Example: Add a helper method

// File: MyCompassExtensions.cs (in your own scripts folder)
using UnityEngine;

namespace CompassNavigatorPro {

    public partial class CompassPro {

        public void HighlightNearestPOI(float radius, Color color) {
            foreach (var poi in activePOIs) {
                var state = poi.GetState(compassGroup);
                if (state.distanceToFollow < radius) {
                    poi.tintColor = color;
                }
            }
        }
    }
}

When to use partial classes: When you need to add new functionality that reads compass state or manages your own data alongside the compass. This approach cannot override existing behavior - for that, use virtual methods.

3. Virtual Methods & Subclassing

For full control over compass behavior, create a subclass of CompassPro. Key methods are marked protected virtual, allowing you to override them. Your subclass survives asset updates since it lives in your own scripts folder.

Setup

  1. Create a new script that inherits from CompassPro.
  2. Replace the CompassPro component on your compass GameObject with your subclass.
  3. The inspector works automatically with subclasses.

Factory Methods

Override these to control how UI elements are created:

protected virtual GameObject CreateCompassBarIcon(CompassProPOI poi)

Creates the compass bar icon for a POI. Override to use custom prefabs or per-POI type variations.

protected virtual GameObject CreateIndicator(CompassProPOI poi)

Creates the on-screen indicator for a POI.

protected virtual GameObject CreateMiniMapIcon(CompassProPOI poi)

Creates the minimap icon for a POI.

Update Methods

Override these to change how the compass updates each frame:

protected virtual void UpdateCompassBarIcons()

Updates all compass bar icons. Override to customize icon positioning, visibility, or appearance.

protected virtual void UpdateIndicators()

Updates all on-screen/off-screen indicators.

protected virtual void UpdateMiniMapIcons()

Updates all minimap icons.

protected virtual void UpdateMiniMap()

Updates the minimap rendering.

protected virtual void UpdateCompassBarAppearance()

Updates compass bar layout and styling (size, position, style).

protected virtual void UpdateCompassBarAlpha()

Updates compass bar transparency and auto-hide behavior.

Computation Methods

Override these to change how positions and compass points are calculated:

protected virtual void ComputePOIViewportPos(CompassProPOI poi)

Computes viewport position and distance for a POI. Override for custom distance calculations.

protected virtual void ComputeCompassPointsPositions()

Computes positions for cardinal and ordinal points.

protected virtual void UpdateCardinalPoints(float barMax)

Updates cardinal point rendering (N, S, E, W).

protected virtual void UpdateOrdinalPoints(float barMax)

Updates ordinal point rendering (NE, NW, SE, SW).

Visibility & Effects

protected virtual bool ToggleCompassBarIconVisibility(CompassProPOI poi, CompassProPOIState state, bool visible)

Toggles compass bar icon visibility. Returns true if state changed.

protected virtual bool ToggleIndicatorVisibility(CompassProPOI poi, CompassProPOIState state, bool visible)

Toggles on-screen indicator visibility.

protected virtual bool ToggleMiniMapIconVisibility(CompassProPOI poi, CompassProPOIState state, bool visible)

Toggles minimap icon visibility.

protected virtual bool ToggleMiniMapCircleVisibility(CompassProPOI poi, CompassProPOIState state, bool visible)

Toggles minimap circle (range indicator) visibility.

protected virtual void ShowPOIDiscoveredText(CompassProPOI poi)

Shows the animated discovery text when a POI is first visited.

Example: Full custom subclass

// File: MyCompass.cs (in your own scripts folder)
using UnityEngine;
using CompassNavigatorPro;

public class MyCompass : CompassPro {

    public GameObject bossIconPrefab;

    // Use different prefabs based on POI type
    protected override GameObject CreateCompassBarIcon(CompassProPOI poi) {
        if (poi.CompareTag("Boss") && bossIconPrefab != null) {
            return Instantiate(bossIconPrefab, transform);
        }
        return base.CreateCompassBarIcon(poi);
    }

    // Add fade animation on visibility change
    protected override bool ToggleCompassBarIconVisibility(
            CompassProPOI poi, CompassProPOIState state, bool visible) {
        bool changed = base.ToggleCompassBarIconVisibility(poi, state, visible);
        if (changed && state.compassIconRT != null) {
            var cg = state.compassIconRT.GetComponent<CanvasGroup>();
            if (cg != null) {
                StartCoroutine(FadeCanvasGroup(cg, visible ? 1f : 0f, 0.3f));
            }
        }
        return changed;
    }
}

Choosing the Right Approach

NeedApproach
React to compass activity (POI visited, icon created)Events - subscribe and respond
Add new methods or properties to CompassProPartial class - extend without modifying
Change how icons/indicators look or are createdEvents (simple) or Factory method overrides (advanced)
Change core behavior (positioning, visibility, layout)Subclass with virtual method overrides
Replace the entire update loop for a systemSubclass overriding Update methods

All three approaches keep your customizations in separate files that are not affected by asset updates.

Was this page helpful?