Rotorz Tile System Icon
Rotorz Tile System for Unity
API Reference
Available on the Unity Asset Store
TOC

ChunkCreated Event

Occurs when new chunk is created.
public static event ChunkCreatedEventHandler ChunkCreated
public static event ChunkCreated : ChunkCreatedEventHandler

Value

Remarks

This event can be consumed by both editor and runtime scripts to manipulate new chunks as they are created. This can be used to automatically add new components on creation.

Do not forget to remove event handlers when they are no longer required to avoid memory related issues.

Examples

The following example demonstrates how to add a new component to chunks as they are created.

using Rotorz.Tile;
using UnityEngine;

public class ExampleBehaviour : MonoBehaviour {

    private void Awake() {
        PaintingUtility.ChunkCreated += OnChunkCreated;
    }

    private void OnDestroy() {
        PaintingUtility.ChunkCreated -= OnChunkCreated;
    }

    private void OnChunkCreated(ChunkCreatedEventArgs args) {
        args.GameObject.AddComponent<CustomBehaviour>();
    }

}
// Assets/ExampleBehaviour.js
#pragma strict
import Rotorz.Tile;

function Awake() {
    PaintingUtility.ChunkCreated += OnChunkCreated;
}

function OnDestroy() {
    PaintingUtility.ChunkCreated -= OnChunkCreated;
}

function OnChunkCreated(args:ChunkCreatedEventArgs) {
    args.GameObject.AddComponent.<CustomBehaviour>();
}

This event can also be utilised by custom editor scripts:

using Rotorz.Tile;
using UnityEditor;
using UnityEngine;

[InitializeOnLoad]
static class MyCustomEditor {

    static MyCustomEditor() {
        PaintingUtility.ChunkCreated += OnChunkCreated;
    }

    private static void OnChunkCreated(ChunkCreatedEventArgs args) {
        args.GameObject.AddComponent<CustomBehaviour>();
    }

}
#pragma strict
import Rotorz.Tile;

@InitializeOnLoad
class MyCustomEditor {

    static function MyCustomEditor() {
        PaintingUtility.ChunkCreated += OnChunkCreated;
    }

    static function OnChunkCreated(args:ChunkCreatedEventArgs) {
        args.GameObject.AddComponent.<CustomBehaviour>();
    }

}

See Also

Reference