Table of Contents

Class LayerObject

Represents a single layer as a RawImage GameObject for high performance on mobile. Uses FastTextureBuffer for optimized pixel operations. Each layer can be independently positioned, scaled, rotated and cropped.

public class LayerObject : MonoBehaviour
Inheritance
LayerObject

Fields

OnLayerChanged

public UnityEvent OnLayerChanged

Field Value

UnityEvent

OnTransformChanged

public UnityEvent OnTransformChanged

Field Value

UnityEvent

OnVisibilityChanged

public UnityEvent OnVisibilityChanged

Field Value

UnityEvent

Properties

Blend

public LayerObject.BlendMode Blend { get; set; }

Property Value

LayerObject.BlendMode

Buffer

public FastTextureBuffer Buffer { get; }

Property Value

FastTextureBuffer

CropRect

public RectInt CropRect { get; }

Property Value

RectInt

IsCropped

public bool IsCropped { get; }

Property Value

bool

IsDirty

public bool IsDirty { get; }

Property Value

bool

IsLocked

public bool IsLocked { get; set; }

Property Value

bool

IsVisible

public bool IsVisible { get; set; }

Property Value

bool

LayerName

public string LayerName { get; set; }

Property Value

string

Opacity

public float Opacity { get; set; }

Property Value

float

Pivot

public Vector2 Pivot { get; set; }

Property Value

Vector2

Position

public Vector2 Position { get; set; }

Property Value

Vector2

RawImage

public RawImage RawImage { get; }

Property Value

RawImage

RectTransform

public RectTransform RectTransform { get; }

Property Value

RectTransform

Rotation

public float Rotation { get; set; }

Property Value

float

Scale

public Vector2 Scale { get; set; }

Property Value

Vector2

Texture

public Texture2D Texture { get; }

Property Value

Texture2D

TextureHeight

public int TextureHeight { get; }

Property Value

int

TextureWidth

public int TextureWidth { get; }

Property Value

int

Methods

ApplyChanges()

Apply pending pixel changes to texture (optimized).

public void ApplyChanges()

ApplyTransform()

Apply position, scale, rotation transforms.

public void ApplyTransform()

Clear(Color)

Clear the layer with a color.

public void Clear(Color color)

Parameters

color Color

Dispose()

Dispose and cleanup.

public void Dispose()

DrawBrushCircle(int, int, int, Color32, float, float)

Draw brush circle (high-performance).

public void DrawBrushCircle(int centerX, int centerY, int radius, Color32 color, float opacity, float hardness)

Parameters

centerX int
centerY int
radius int
color Color32
opacity float
hardness float

DrawBrushLine(int, int, int, int, Color32, int, float, float)

Draw line between two points (high-performance using Bresenham).

public void DrawBrushLine(int x0, int y0, int x1, int y1, Color32 color, int thickness, float opacity, float hardness)

Parameters

x0 int
y0 int
x1 int
y1 int
color Color32
thickness int
opacity float
hardness float

DrawPixel(int, int, Color, float)

Draw a pixel with blending (optimized).

public void DrawPixel(int x, int y, Color brushColor, float brushOpacity)

Parameters

x int
y int
brushColor Color
brushOpacity float

Duplicate(Transform)

Create a copy of this layer.

public LayerObject Duplicate(Transform parent)

Parameters

parent Transform

Returns

LayerObject

EraseBrushCircle(int, int, int, float, float)

Erase brush circle (high-performance).

public void EraseBrushCircle(int centerX, int centerY, int radius, float opacity, float hardness)

Parameters

centerX int
centerY int
radius int
opacity float
hardness float

EraseBrushLine(int, int, int, int, int, float, float)

Erase line between two points (high-performance).

public void EraseBrushLine(int x0, int y0, int x1, int y1, int thickness, float opacity, float hardness)

Parameters

x0 int
y0 int
x1 int
y1 int
thickness int
opacity float
hardness float

ErasePixel(int, int, float)

Erase a pixel (optimized).

public void ErasePixel(int x, int y, float eraseStrength)

Parameters

x int
y int
eraseStrength float

ExportAsJPG(int)

Export this layer as JPG bytes.

public byte[] ExportAsJPG(int quality = 75)

Parameters

quality int

Returns

byte[]

ExportAsPNG()

Export this layer as PNG bytes.

public byte[] ExportAsPNG()

Returns

byte[]

GetPixel(int, int)

Get pixel color (uses fast buffer).

public Color GetPixel(int x, int y)

Parameters

x int
y int

Returns

Color

GetPixels()

Get all pixels (creates copy - use sparingly).

public Color[] GetPixels()

Returns

Color[]

GetPixelsReadOnly()

Get pixels without cloning (read-only reference - use carefully).

public Color[] GetPixelsReadOnly()

Returns

Color[]

ImportImage(Texture2D, int, int)

Import an image into this layer.

public void ImportImage(Texture2D image, int offsetX = 0, int offsetY = 0)

Parameters

image Texture2D
offsetX int
offsetY int

Initialize(int, int, Color?)

Initialize the layer with a new texture.

public void Initialize(int width, int height, Color? fillColor = null)

Parameters

width int
height int
fillColor Color?

InitializeFromTexture(Texture2D, bool)

Initialize from an existing texture/image.

public void InitializeFromTexture(Texture2D source, bool preserveSize = true)

Parameters

source Texture2D
preserveSize bool

Move(Vector2)

Move the layer by delta.

public void Move(Vector2 delta)

Parameters

delta Vector2

ResetCrop()

Reset crop to full texture.

public void ResetCrop()

Resize(int, int)

Resize the layer texture (destructive - resamples content).

public void Resize(int newWidth, int newHeight)

Parameters

newWidth int
newHeight int

SetCrop(RectInt)

Set crop rectangle.

public void SetCrop(RectInt rect)

Parameters

rect RectInt

SetPixel(int, int, Color)

Set a pixel color (uses fast buffer).

public void SetPixel(int x, int y, Color color)

Parameters

x int
y int
color Color

SetPixels(Color[])

Set all pixels.

public void SetPixels(Color[] pixels)

Parameters

pixels Color[]

SetPosition(Vector2)

Set absolute position.

public void SetPosition(Vector2 position)

Parameters

position Vector2

SetRotation(float)

Rotate the layer.

public void SetRotation(float degrees)

Parameters

degrees float

SetScale(float)

Scale the layer uniformly.

public void SetScale(float scale)

Parameters

scale float

SetScale(Vector2)

Scale the layer non-uniformly.

public void SetScale(Vector2 scale)

Parameters

scale Vector2