Table of Contents

Class LayerManager

Manages all layers as separate RawImage GameObjects for high performance on mobile. Each layer is a LayerObject with its own texture and transform capabilities.

public class LayerManager : MonoBehaviour
Inheritance
LayerManager

Fields

OnActiveLayerChanged

public UnityEvent<int> OnActiveLayerChanged

Field Value

UnityEvent<int>

OnCanvasUpdated

public UnityEvent OnCanvasUpdated

Field Value

UnityEvent

OnLayerCreated

public UnityEvent<LayerObject> OnLayerCreated

Field Value

UnityEvent<LayerObject>

OnLayerDeleted

public UnityEvent<LayerObject> OnLayerDeleted

Field Value

UnityEvent<LayerObject>

OnLayersReordered

public UnityEvent OnLayersReordered

Field Value

UnityEvent

Properties

ActiveLayer

public LayerObject ActiveLayer { get; }

Property Value

LayerObject

ActiveLayerIndex

public int ActiveLayerIndex { get; }

Property Value

int

CanvasHeight

public int CanvasHeight { get; }

Property Value

int

CanvasWidth

public int CanvasWidth { get; }

Property Value

int

CompositeTexture

public Texture2D CompositeTexture { get; }

Property Value

Texture2D

LayerContainer

public RectTransform LayerContainer { get; }

Property Value

RectTransform

LayerCount

public int LayerCount { get; }

Property Value

int

Layers

public IReadOnlyList<LayerObject> Layers { get; }

Property Value

IReadOnlyList<LayerObject>

Methods

ClearAllLayers()

Clear all layers.

public void ClearAllLayers()

CreateLayer(string, Color?)

Create a new layer at the top.

public LayerObject CreateLayer(string name = null, Color? fillColor = null)

Parameters

name string
fillColor Color?

Returns

LayerObject

CreateLayerFromImage(Texture2D, string)

Create a new layer from an imported image as a separate RawImage.

public LayerObject CreateLayerFromImage(Texture2D image, string name = null)

Parameters

image Texture2D
name string

Returns

LayerObject

CropActiveLayer(RectInt)

Set crop on active layer.

public void CropActiveLayer(RectInt rect)

Parameters

rect RectInt

DeleteActiveLayer()

Delete the currently active layer.

public void DeleteActiveLayer()

DeleteLayer(int)

Delete a layer by index.

public void DeleteLayer(int index)

Parameters

index int

DuplicateLayer(int)

Duplicate a layer.

public LayerObject DuplicateLayer(int index)

Parameters

index int

Returns

LayerObject

ExportAsJPG(int)

Export the composite texture as JPG bytes.

public byte[] ExportAsJPG(int quality = 75)

Parameters

quality int

Returns

byte[]

ExportAsPNG()

Export the composite texture as PNG bytes.

public byte[] ExportAsPNG()

Returns

byte[]

Flatten()

Flatten all visible layers into one.

public LayerObject Flatten()

Returns

LayerObject

GetCompositeCopy()

Get a copy of the composite texture.

public Texture2D GetCompositeCopy()

Returns

Texture2D

GetLayer(int)

Get layer by index.

public LayerObject GetLayer(int index)

Parameters

index int

Returns

LayerObject

GetLayerIndex(LayerObject)

Find layer index by reference.

public int GetLayerIndex(LayerObject layer)

Parameters

layer LayerObject

Returns

int

InitializeCanvas(int, int, bool)

Initialize or resize the canvas.

public void InitializeCanvas(int width, int height, bool clearLayers = true)

Parameters

width int
height int
clearLayers bool

MergeDown(int)

Merge a layer with the one below it.

public void MergeDown(int index)

Parameters

index int

MergeVisible()

Merge all visible layers into one.

public LayerObject MergeVisible()

Returns

LayerObject

MoveActiveLayer(Vector2)

Move the active layer by delta.

public void MoveActiveLayer(Vector2 delta)

Parameters

delta Vector2

MoveLayerDown(int)

Move a layer down in the stack (towards back).

public void MoveLayerDown(int index)

Parameters

index int

MoveLayerUp(int)

Move a layer up in the stack (towards front).

public void MoveLayerUp(int index)

Parameters

index int

ResetActiveLayerCrop()

Reset crop on active layer.

public void ResetActiveLayerCrop()

ResizeActiveLayer(int, int)

Resize active layer.

public void ResizeActiveLayer(int width, int height)

Parameters

width int
height int

RotateActiveLayer(float)

Rotate the active layer.

public void RotateActiveLayer(float degrees)

Parameters

degrees float

ScaleActiveLayer(Vector2)

Scale the active layer.

public void ScaleActiveLayer(Vector2 scale)

Parameters

scale Vector2

SetActiveLayer(int)

Set the active layer by index.

public void SetActiveLayer(int index)

Parameters

index int

SetLayerContainer(RectTransform)

Set the layer container reference.

public void SetLayerContainer(RectTransform container)

Parameters

container RectTransform

UpdateComposite()

Update the composite texture from all layers. WARNING: This is expensive! Only call when needed (export, layer visibility change, etc.) During drawing, the individual layer RawImages display directly - no composite needed.

public void UpdateComposite()