RegionPicker

Overview

Color‑picking hover detector. Performs a 3D raycast under the mouse, samples the albedo texture at the hit UV to read the pixel color, converts it to RGBA hex, and maps it to a Region via a static dictionary filled by Subscribe(...). Updates an internal currentRegion when the hovered color changes. fileciteturn15file1

API

public static void Subscribe(Region region, Color color); // registers color → region
public Region HoveredRegion { get; }                      // current region under cursor (or null)

On duplicate color registration, logs an error with the names of the colliding regions. fileciteturn15file1

How It Works

  • Update() casts a ray from Camera.main through Input.mousePosition and raycasts into the scene (10,000 units).
  • If a collider is hit:
    • Gets the hit renderer’s mainTexture as Texture2D and samples GetPixelBilinear(uv).
    • Converts the color to a hex string via ColorUtility.ToHtmlStringRGBA.
    • Looks up the region in the static dictionary and calls OnRegionHovered(...) with the result.
  • OnRegionHovered(...) early‑returns if unchanged, otherwise updates currentRegion. (Hooks for OnHoverEnter/Exit are included as comments.) fileciteturn15file1

Notes

  • Awake() clears the dictionary so each scene boot starts with a clean registry. fileciteturn15file1