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. fileciteturn15file1
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. fileciteturn15file1
How It Works
Update()casts a ray fromCamera.mainthroughInput.mousePositionand raycasts into the scene (10,000 units).- If a collider is hit:
- Gets the hit renderer’s mainTexture as
Texture2Dand samplesGetPixelBilinear(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.
- Gets the hit renderer’s mainTexture as
OnRegionHovered(...)early‑returns if unchanged, otherwise updatescurrentRegion. (Hooks forOnHoverEnter/Exitare included as comments.) fileciteturn15file1
Notes
Awake()clears the dictionary so each scene boot starts with a clean registry. fileciteturn15file1