Scripting Support (C#)
advanced scriptingHexasphere Grid System · Scripting Support (C#)
HexasphereGrid component (namespace HexasphereGrid). Access via GetComponent<HexasphereGrid>().
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 smartEdgesEnables smart edge rendering that adapts wireframe based on tile colors.
bool transparentEnables transparency mode for the hexasphere.
bool transparencyZWriteEnables Z-buffer writing in transparency mode.
float transparencyTilesTile transparency level (0–1).
bool transparencyCullEnables back-face culling in transparency mode.
bool transparencyDoubleSidedEnables double-sided rendering in transparency mode.
bool bevelEnables beveled edges on extruded tiles.
bool VREnabledEnables Virtual Reality interaction mode.
Vector3 rotationShiftRotation offset applied to the grid generation.
bool enableGridEditorEnables grid editing tools in the Scene View.
int tileTextureSizeResolution of individual tile textures in the texture array (default 256).
bool tileTextureStretchStretches tile textures to fill the tile area.
float gradientIntensityIntensity of the gradient effect on tiles (0–1).
Texture2D[] texturesArray of user-defined textures available for tile customization and the Grid Editor.
IInputProxy inputReference to the input system proxy. Reassign to override default input handling (e.g. for custom VR controllers).
const int ALL_TILESBitmask 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[] tilesArray of all generated tiles. Access tiles directly for batch operations.
Appearance
Color defaultShadedColor { get; set; }
bool wireframeColorFromTileWhen enabled, wireframe color follows each tile’s individual color.
bool castShadowsEnables shadow casting from the hexasphere.
bool receiveShadowsEnables shadow receiving on the hexasphere.
Color ambientColorAmbient light color applied to the hexasphere (supports HDR).
float minimumLightMinimum light intensity (0–1) to prevent fully dark tiles.
Color specularTintSpecular highlight tint color (supports HDR).
float smoothnessSpecular smoothness/shininess value (0–16).
float highlightSpeedHighlight animation speed (0.1–5).
HIGHLIGHT_STYLE highlightStyleHighlight 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 cameraMainReference to the main camera used for interaction and raycasting.
bool respectOtherUIPrevents hexasphere interaction when the pointer is over a UI element.
float rotationAxisVerticalThresholdVertical angle threshold for switching rotation axis behavior (10–80 degrees).
float zoomSpeedZoom speed multiplier (0.1–5).
float zoomDampingZoom deceleration damping (0–1).
bool raycast3DEnables 3D raycasting for more accurate tile detection on extruded tiles.
float dragThresholdMinimum drag distance before a drag gesture is recognized.
float clickDurationMaximum press duration (seconds) to register as a click rather than a drag.
bool rightButtonDragWhen enabled, the sphere is dragged with the right mouse button instead of the left.
bool rightClickRotatesEnables sphere rotation via right-click drag.
bool rightClickRotatingClockwiseSets the direction of right-click rotation to clockwise.
bool isMouseOverReturns true if the mouse cursor is currently over the hexasphere (read-only).
Tile lastHighlightedTileReference 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) / OnDragEndFired when dragging starts/ends on the sphere.
event HexasphereEvent OnFlyStart(Hexasphere hexasphere) / OnFlyEndFired 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 pathFindingHeuristicFormulaHeuristic formula used for pathfinding: SphericalDistance, Euclidean, or EuclideanNoSQR.
int pathFindingSearchLimitMaximum number of tiles evaluated during pathfinding (default 2000).
bool pathFindingUseExtrusionWhen enabled, tile extrusion (altitude) is factored into pathfinding cost calculations.
int pathFindingExtrusionWeightWeight 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);
}
}
}
Suggest an improvement
Help us improve this documentation page.