Class LayerObject
- Namespace
- WitShells.CanvasDrawTool
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
Buffer
public FastTextureBuffer Buffer { get; }
Property Value
CropRect
public RectInt CropRect { get; }
Property Value
- RectInt
IsCropped
public bool IsCropped { get; }
Property Value
IsDirty
public bool IsDirty { get; }
Property Value
IsLocked
public bool IsLocked { get; set; }
Property Value
IsVisible
public bool IsVisible { get; set; }
Property Value
LayerName
public string LayerName { get; set; }
Property Value
Opacity
public float Opacity { get; set; }
Property Value
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
Scale
public Vector2 Scale { get; set; }
Property Value
- Vector2
Texture
public Texture2D Texture { get; }
Property Value
- Texture2D
TextureHeight
public int TextureHeight { get; }
Property Value
TextureWidth
public int TextureWidth { get; }
Property Value
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
colorColor
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
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
DrawPixel(int, int, Color, float)
Draw a pixel with blending (optimized).
public void DrawPixel(int x, int y, Color brushColor, float brushOpacity)
Parameters
Duplicate(Transform)
Create a copy of this layer.
public LayerObject Duplicate(Transform parent)
Parameters
parentTransform
Returns
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
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
ErasePixel(int, int, float)
Erase a pixel (optimized).
public void ErasePixel(int x, int y, float eraseStrength)
Parameters
ExportAsJPG(int)
Export this layer as JPG bytes.
public byte[] ExportAsJPG(int quality = 75)
Parameters
qualityint
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
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
Initialize(int, int, Color?)
Initialize the layer with a new texture.
public void Initialize(int width, int height, Color? fillColor = null)
Parameters
InitializeFromTexture(Texture2D, bool)
Initialize from an existing texture/image.
public void InitializeFromTexture(Texture2D source, bool preserveSize = true)
Parameters
sourceTexture2DpreserveSizebool
Move(Vector2)
Move the layer by delta.
public void Move(Vector2 delta)
Parameters
deltaVector2
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
SetCrop(RectInt)
Set crop rectangle.
public void SetCrop(RectInt rect)
Parameters
rectRectInt
SetPixel(int, int, Color)
Set a pixel color (uses fast buffer).
public void SetPixel(int x, int y, Color color)
Parameters
SetPixels(Color[])
Set all pixels.
public void SetPixels(Color[] pixels)
Parameters
pixelsColor[]
SetPosition(Vector2)
Set absolute position.
public void SetPosition(Vector2 position)
Parameters
positionVector2
SetRotation(float)
Rotate the layer.
public void SetRotation(float degrees)
Parameters
degreesfloat
SetScale(float)
Scale the layer uniformly.
public void SetScale(float scale)
Parameters
scalefloat
SetScale(Vector2)
Scale the layer non-uniformly.
public void SetScale(Vector2 scale)
Parameters
scaleVector2