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

TileTrace Method (TileTraceDirection, Int32, Int32, TileTraceHit, TileTraceDelegate)

Trace through tiles horizontally or vertically to find first tile that is found using custom delegate.
public bool TileTrace(
	TileTraceDirection direction,
	int row,
	int column,
	out TileTraceHit hit,
	TileTraceDelegate fn
)
public function TileTrace(
	direction : TileTraceDirection,
	row : int,
	column : int,
	out hit : TileTraceHit,
	fn : TileTraceDelegate
) : boolean

Parameters

direction (TileTraceDirection)
Direction to search.
row (Int32)
Zero-based index of origin row.
column (Int32)
Zero-based index of origin column.
hit (TileTraceHit)
Details about hit. Check return value before using hit data.
fn (TileTraceDelegate)
Custom search function.

Return Value

A value of true if a tile was hit; otherwise false.

Remarks

Tile tracing functions are generally useful when performing line of sight type tests. These functions can be applied in wide range of different ways.

Examples

Perform custom tile trace to find first tile that has some required flags and does not have any disallowed flags.

using Rotorz.Tile;
using UnityEngine;

static class TileTraceExtensions {

    // Extension method for extended flag tile trace.

    public static bool TileTraceFlagEx(this TileSystem system,
        int requiredFlags,
        int excludeFlags,
        TileTraceDirection direction,
        int fromRow,
        int fromColumn,
        out TileTraceHit hit
    ) {
        return system.TileTraceCustom(direction, fromRow, fromColumn, out hit,
            delegate(TileData tile) {
                if (tile == null)
                    return false;

                int flags = tile.UserFlags;

                // Make sure that all required flags are set.
                if ((flags & requiredFlags) != requiredFlags)
                    return false;

                // Make sure that no disallowed flags are set!
                if ((flags & excludeFlags) != 0)
                    return false;

                return true;
            }
        );
    }

}

See Also

Reference