Scripting Support (C#)

advanced scripting

Hexasphere Grid System · Scripting Support (C#)

Class: All members on this page belong to the HexasphereGrid component (namespace HexasphereGrid). Access via GetComponent<HexasphereGrid>().
Tip: Use Hexasphere.GetInstance("name") if you have multiple hexaspheres, or access the tiles array directly for batch operations.

Getting Started

Add the namespace and get a reference to the component:

using HexasphereGrid;

Hexasphere hexa = GetComponent<Hexasphere>();
// Or by name:
Hexasphere hexa = Hexasphere.GetInstance("MyHexasphere");

Grid Configuration

int numDivisions { get; set; }
bool smartEdges

Enables smart edge rendering that adapts wireframe based on tile colors.

bool transparent

Enables transparency mode for the hexasphere.

bool transparencyZWrite

Enables Z-buffer writing in transparency mode.

float transparencyTiles

Tile transparency level (0–1).

bool transparencyCull

Enables back-face culling in transparency mode.

bool transparencyDoubleSided

Enables double-sided rendering in transparency mode.

bool bevel

Enables beveled edges on extruded tiles.

bool VREnabled

Enables Virtual Reality interaction mode.

Vector3 rotationShift

Rotation offset applied to the grid generation.

bool enableGridEditor

Enables grid editing tools in the Scene View.

int tileTextureSize

Resolution of individual tile textures in the texture array (default 256).

bool tileTextureStretch

Stretches tile textures to fill the tile area.

float gradientIntensity

Intensity of the gradient effect on tiles (0–1).

Texture2D[] textures

Array of user-defined textures available for tile customization and the Grid Editor.

IInputProxy input

Reference to the input system proxy. Reassign to override default input handling (e.g. for custom VR controllers).

const int ALL_TILES

Bitmask constant (~0) representing all tile groups. Used as the default groupMask for FindPath.

Level of tessellation/subdivision. Higher values create more tiles.

STYLE style { get; set; }

Visual style: Wireframe, Shaded, ShadedWireframe, or Invisible.

bool invertedMode { get; set; }

Inverts the grid for inside-out view (e.g., viewing from inside a planet).

bool extruded { get; set; }

Enable tile extrusion for 3D height effects.

float extrudeMultiplier { get; set; }

Global extrusion height multiplier (0–1).

Tile[] tiles

Array of all generated tiles. Access tiles directly for batch operations.

Appearance

Color defaultShadedColor { get; set; }
bool wireframeColorFromTile

When enabled, wireframe color follows each tile’s individual color.

bool castShadows

Enables shadow casting from the hexasphere.

bool receiveShadows

Enables shadow receiving on the hexasphere.

Color ambientColor

Ambient light color applied to the hexasphere (supports HDR).

float minimumLight

Minimum light intensity (0–1) to prevent fully dark tiles.

Color specularTint

Specular highlight tint color (supports HDR).

float smoothness

Specular smoothness/shininess value (0–16).

float highlightSpeed

Highlight animation speed (0.1–5).

HIGHLIGHT_STYLE highlightStyle

Highlight visual style: Default or TintBackground.

Default tile color when shaded.

Color wireframeColor { get; set; }

Wireframe line color.

float wireframeIntensity { get; set; }

Wireframe line intensity (0–2).

Color tileTintColor { get; set; }

Global tint color multiplier for all tiles.

bool lighting { get; set; }

Enable lighting calculations.

Color highlightColor { get; set; }

Color used when hovering over a tile.

bool highlightEnabled { get; set; }

Enable/disable tile highlighting on mouse over.

Interaction

bool rotationEnabled { get; set; }
Camera cameraMain

Reference to the main camera used for interaction and raycasting.

bool respectOtherUI

Prevents hexasphere interaction when the pointer is over a UI element.

float rotationAxisVerticalThreshold

Vertical angle threshold for switching rotation axis behavior (10–80 degrees).

float zoomSpeed

Zoom speed multiplier (0.1–5).

float zoomDamping

Zoom deceleration damping (0–1).

bool raycast3D

Enables 3D raycasting for more accurate tile detection on extruded tiles.

float dragThreshold

Minimum drag distance before a drag gesture is recognized.

float clickDuration

Maximum press duration (seconds) to register as a click rather than a drag.

bool rightButtonDrag

When enabled, the sphere is dragged with the right mouse button instead of the left.

bool rightClickRotates

Enables sphere rotation via right-click drag.

bool rightClickRotatingClockwise

Sets the direction of right-click rotation to clockwise.

bool isMouseOver

Returns true if the mouse cursor is currently over the hexasphere (read-only).

Tile lastHighlightedTile

Reference to the last highlighted Tile object.

Enable sphere rotation by mouse/touch.

float rotationSpeed { get; set; }

Rotation sensitivity (0.01–1).

ROTATION_AXIS_ALLOWED rotationAxisAllowed { get; set; }

Constrain rotation: BothAxis, XAxisOnly, YAxisOnly, or Straight.

bool zoomEnabled { get; set; }

Enable zoom via scroll wheel.

float zoomMinDistance { get; set; }

Minimum zoom distance.

float zoomMaxDistance { get; set; }

Maximum zoom distance.

int lastHighlightedTileIndex { get; }

Index of the last tile under the cursor (read-only).

int lastClickedTile { get; }

Index of the last clicked tile (read-only).

Events

event TileEvent OnTileClick(Hexasphere hexasphere, int tileIndex)

Fired when a tile is clicked. Receives Hexasphere and int tileIndex.

event HexasphereEvent OnGeneration(Hexasphere hexasphere)

Triggered when the grid is regenerated.

event TileEvent OnTileMouseOver(Hexasphere hexasphere, int tileIndex)

Fired when the mouse hovers over a tile.

event HexasphereEvent OnDragStart(Hexasphere hexasphere) / OnDragEnd

Fired when dragging starts/ends on the sphere.

event HexasphereEvent OnFlyStart(Hexasphere hexasphere) / OnFlyEnd

Fired when a FlyTo animation starts/ends.

event HexasphereEvent OnZoom(Hexasphere hexasphere)

Fired when the zoom level changes.

event PathFindingEvent OnPathFindingCrossTile(Hexasphere hexasphere, int toTileIndex, int fromTileIndex)

Fired during pathfinding for each tile. Return a custom cost value.

Navigation

void FlyTo(int destinationTileIndex, float duration)

Animates the camera to face a tile over the specified duration.

void FlyTo(Vector3 destination, float duration)

Animates the camera to face a local-space position.

float flyToTilt { get; set; }

Camera tilt angle during FlyTo (-90 to 90 degrees).

Tile Query Methods

int GetTileAtPosition(Vector3 position, bool worldSpace = true)
int GetTileIndex(Tile tile)

Returns the index of a Tile in the tiles array.

int GetTileAtPolarOpposite(int tileIndex)

Returns the tile index at the exact opposite pole of the given tile.

int GetTileAtUV(Vector2 uv)

Returns the tile index at the given UV coordinates. Inverse of GetTileUV.

Vector2 GetTileUV(int tileIndex)

Returns the UV texture coordinate of the tile center mapped to a 2D equirectangular projection.

Vector2 GetTileVertexLatLon(int tileIndex, int vertexIndex)

Returns the latitude and longitude of a specific tile vertex.

Vector3 GetTileVertexPosition(int tileIndex, int vertexIndex, bool worldSpace = true, bool includeExtrusion = true)

Returns the world or local position of a specific tile vertex.

Tile[] GetTileNeighborsTiles(int tileIndex)

Returns an array of Tile objects neighboring the given tile.

bool GetTileCanCross(int tileIndex)

Returns whether pathfinding can cross the given tile.

float GetTileCrossCost(int tileIndex)

Returns the pathfinding crossing cost of the given tile.

int GetTileGroup(int tileIndex)

Returns the pathfinding group of the given tile.

float GetTileVertex0Angle(int tileIndex)

Returns the angle (in radians) between vertex 0 and North for the given tile.

float GetTileVertexElevation(int tileIndex, int vertexIndex)

Returns the elevation of a specific vertex of a tile.

int GetTileTextureIndex(int tileIndex)

Returns the index of the tile’s texture in the textures array, or 0 if none.

float GetTileTextureRotation(int tileIndex)

Returns the texture rotation (in radians) of the given tile.

Vector3 GetExtrudedPosition(Vector3 position, bool worldSpace)

Adjusts a position to the surface of the tile underneath, accounting for extrusion.

static Hexasphere GetInstance(string gameObjectName)

Returns the Hexasphere component attached to a GameObject with the given name.

List<int> GetTilesWithinTwoTiles(int tileIndex1, int tileIndex2)

Returns all tiles found along the path between two tiles.

Returns the tile index at a world or local position.

int GetTileAtLatLon(float latitude, float longitude)

Returns the tile at latitude/longitude coordinates.

Vector3 GetTileCenter(int tileIndex, bool worldSpace = true, bool includeExtrusion = true)

Returns the center position of a tile.

Vector2 GetTileLatLon(int tileIndex)

Returns the latitude/longitude of a tile's center.

int GetTileVertexCount(int tileIndex)

Returns the vertex count (5 for pentagon, 6 for hexagon).

int[] GetTileNeighbors(int tileIndex)

Returns indices of neighboring tiles.

bool IsTileVisibleFromCamera(int tileIndex, Camera cam)

Checks if a tile is visible in the camera frustum.

Tile Styling

bool SetTileColor(int tileIndex, Color color, bool temporary = false)
bool SetTileTextureRotation(int tileIndex, float rotation)

Sets the texture rotation (in radians) for the given tile.

bool SetTileTextureRotationToNorth(int tileIndex)

Rotates the tile’s texture so its top edge points to North.

void ClearTile(int tileIndex, bool clearTemporaryColor = false, bool clearAllColors = true, bool clearObstacles = true)

Resets a specific tile to its default state.

void DestroyTile(int tileIndex)

Destroys a tile’s custom material and mesh renderer.

bool ToggleTile(int tileIndex, bool visible)

Toggles a tile’s visibility on or off.

void SetTileVisible(int tileIndex, bool visible)

Sets the visibility of a tile. Convenience wrapper for ToggleTile.

bool HideTile(int tileIndex)

Hides a tile from the grid.

bool ShowTile(int tileIndex)

Shows a previously hidden tile.

Sets the color of a tile. Temporary colors revert when deselected.

Color GetTileColor(int tileIndex)

Returns the current tile color.

bool SetTileTexture(int tileIndex, int textureIndex, Color tint, bool temporary = false)

Applies a texture from the textures array with a tint color.

bool SetTileMaterial(int tileIndex, Material mat, bool temporary = false)

Applies a custom material to a tile.

void ClearTiles()

Resets all tiles to their default state.

Tile Extrusion & Elevation

bool SetTileExtrudeAmount(int tileIndex, float extrudeAmount)
bool SetTileVertexElevation(int tileIndex, int vertexIndex, float elevation)

Sets the elevation of a specific vertex of a tile.

bool SetTileVerticesElevation(int tileIndex, float elevation)

Sets the elevation of all vertices of a tile.

void ApplyHeightMapToVertices(Texture2D heightMap, float elevationMultiplier = 1f)

Applies a height map to individual tile vertices for smooth terrain deformation.

void UpdateHeightMap(bool replaceColors, float seaLevel = 0.1f)

Reapplies the cached height map with new parameters without reloading the texture.

Sets the extrusion height (0–1) for a tile.

float GetTileExtrudeAmount(int tileIndex)

Returns the current extrusion height of a tile.

void ClearTilesExtrusion()

Removes all tile extrusions.

void ApplyHeightMap(Texture2D heightMap, float seaLevel = 0.1f, Texture2D rampColors = null)

Applies a height map texture. Tiles below seaLevel are marked as water.

void ApplyColors(Texture2D textureWithColors)

Maps texture colors to tiles based on position.

Tile Pathfinding

bool SetTileCanCross(int tileIndex, bool canCross)
HeuristicFormula pathFindingHeuristicFormula

Heuristic formula used for pathfinding: SphericalDistance, Euclidean, or EuclideanNoSQR.

int pathFindingSearchLimit

Maximum number of tiles evaluated during pathfinding (default 2000).

bool pathFindingUseExtrusion

When enabled, tile extrusion (altitude) is factored into pathfinding cost calculations.

int pathFindingExtrusionWeight

Weight multiplier applied to extrusion differences during pathfinding (default 10000).

Sets whether pathfinding can cross this tile.

bool SetTileCrossCost(int tileIndex, float crossCost)

Sets the crossing cost for pathfinding.

bool SetTileGroup(int tileIndex, int group)

Sets the tile group for pathfinding filtering.

List<int> FindPath(int tileIndexStart, int tileIndexEnd, int searchLimit = 0)

Finds the shortest path between two tiles. Returns a list of tile indices or null.

List<int> GetTilesWithinSteps(int tileIndex, int maxSteps, bool usePathFinding = true)

Returns tiles reachable within a number of steps.

List<int> GetTilesWithinDistance(int tileIndex, float distance)

Returns tiles within a spatial distance.

Tags & Metadata

bool SetTileTag(int tileIndex, int tag)
string GetTileTag(int tileIndex)

Returns the string tag of the given tile.

Sets an integer tag on a tile for custom identification.

int GetTileTagInt(int tileIndex)

Returns the integer tag of a tile.

Utilities

void ParentAndAlignToTile(GameObject go, int tileIndex, float altitude = 0)
bool Raycast(Ray ray, out Vector3 hitPosition)

Casts a ray against the hexasphere and returns the collision point on the tile surface.

GameObject Export()

Creates a permanent standalone copy of the hexasphere as a new GameObject in the scene.

Parents and positions a game object on a tile's surface.

GameObject GenerateTileGameObject(int tileIndex, Material material)

Creates a standalone game object from a tile's mesh.

string GetTilesConfigurationData()

Exports all tile data as JSON for save/load.

void SetTilesConfigurationData(string json)

Restores tile data from a JSON string.

Code Examples

using UnityEngine;
using HexasphereGrid;

public class HexaDemo : MonoBehaviour {
    Hexasphere hexa;

    void Start() {
        hexa = GetComponent<Hexasphere>();

        // Listen for tile clicks
        hexa.OnTileClick += (h, tileIndex) => {
            // Color the clicked tile
            h.SetTileColor(tileIndex, Color.cyan);

            // Extrude it
            h.SetTileExtrudeAmount(tileIndex, 0.3f);

            // Navigate camera to the tile
            h.FlyTo(tileIndex, 1.0f);
        };

        // Apply a height map
        Texture2D heightMap = Resources.Load<Texture2D>("EarthHeightMap");
        hexa.ApplyHeightMap(heightMap, 0.1f);

        // Set up pathfinding
        hexa.SetTileCanCross(100, false); // Block tile 100
        List<int> path = hexa.FindPath(0, 50);
        if (path != null) {
            foreach (int idx in path)
                hexa.SetTileColor(idx, Color.green, true);
        }
    }
}
Was this page helpful?