Table of Contents

Class SpiralLayoutContainer

A MonoBehaviour that procedurally arranges ISpiralNode GameObjects in a spiral pattern using an ObjectPool<T> for efficient instantiation and reuse.

public class SpiralLayoutContainer : MonoBehaviour
Inheritance
SpiralLayoutContainer

Remarks

Attach this component to a parent GameObject in your UI or world space. Assign a spiralNodePrefab that implements ISpiralNode. Call GenerateSpiralLayout(int) at runtime to build (or rebuild) the spiral. The spiral can operate in either world space or canvas (RectTransform) space depending on the canvasSpace setting.

Fields

canvasSpace

protected bool canvasSpace

Field Value

bool

head

protected ISpiralNode head

Field Value

ISpiralNode

maxCount

protected int maxCount

Field Value

int

nodes

protected List<ISpiralNode> nodes

Field Value

List<ISpiralNode>

spacing

protected float spacing

Field Value

float

spiralDirection

protected SpiralDirection spiralDirection

Field Value

SpiralDirection

spiralGrowthRate

protected float spiralGrowthRate

Field Value

float

spiralNodePrefab

protected GameObject spiralNodePrefab

Field Value

GameObject

tail

protected ISpiralNode tail

Field Value

ISpiralNode

Properties

Head

The first node in the spiral chain (closest to the centre).

public ISpiralNode Head { get; }

Property Value

ISpiralNode

NodePool

public ObjectPool<GameObject> NodePool { get; }

Property Value

ObjectPool<GameObject>

Tail

The last node added to the spiral chain.

public ISpiralNode Tail { get; }

Property Value

ISpiralNode

Methods

AddNodeToSpiral()

protected virtual void AddNodeToSpiral()

Awake()

protected virtual void Awake()

CalculateSpiralPosition(int)

protected virtual Vector3 CalculateSpiralPosition(int index)

Parameters

index int

Returns

Vector3

ClearLayout()

protected virtual void ClearLayout()

ConnectNodes()

protected virtual void ConnectNodes()

CreateFirstNode()

protected virtual void CreateFirstNode()

GenerateSpiral(Vector2Int, int)

public IEnumerable<Vector2Int> GenerateSpiral(Vector2Int center, int totalTiles)

Parameters

center Vector2Int
totalTiles int

Returns

IEnumerable<Vector2Int>

GenerateSpiralLayout(int)

Clears any existing spiral and generates a new one with count nodes. Node GameObjects are obtained from NodePool and placed according to a square spiral algorithm. Clamped to maxCount.

public virtual void GenerateSpiralLayout(int count)

Parameters

count int

Desired number of nodes. Clamped to maxCount.

SetHeadCoordinate(Vector2Int)

Moves the head node to coordinate and propagates the offset to all subsequent nodes in the chain.

public void SetHeadCoordinate(Vector2Int coordinate)

Parameters

coordinate Vector2Int

New 2D grid coordinate for the head node.