Class LayerManager
- Namespace
- WitShells.CanvasDrawTool
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
ActiveLayerIndex
public int ActiveLayerIndex { get; }
Property Value
CanvasHeight
public int CanvasHeight { get; }
Property Value
CanvasWidth
public int CanvasWidth { get; }
Property Value
CompositeTexture
public Texture2D CompositeTexture { get; }
Property Value
- Texture2D
LayerContainer
public RectTransform LayerContainer { get; }
Property Value
- RectTransform
LayerCount
public int LayerCount { get; }
Property Value
Layers
public IReadOnlyList<LayerObject> Layers { get; }
Property Value
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
namestringfillColorColor?
Returns
CreateLayerFromImage(Texture2D, string)
Create a new layer from an imported image as a separate RawImage.
public LayerObject CreateLayerFromImage(Texture2D image, string name = null)
Parameters
imageTexture2Dnamestring
Returns
CropActiveLayer(RectInt)
Set crop on active layer.
public void CropActiveLayer(RectInt rect)
Parameters
rectRectInt
DeleteActiveLayer()
Delete the currently active layer.
public void DeleteActiveLayer()
DeleteLayer(int)
Delete a layer by index.
public void DeleteLayer(int index)
Parameters
indexint
DuplicateLayer(int)
Duplicate a layer.
public LayerObject DuplicateLayer(int index)
Parameters
indexint
Returns
ExportAsJPG(int)
Export the composite texture as JPG bytes.
public byte[] ExportAsJPG(int quality = 75)
Parameters
qualityint
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
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
indexint
Returns
GetLayerIndex(LayerObject)
Find layer index by reference.
public int GetLayerIndex(LayerObject layer)
Parameters
layerLayerObject
Returns
InitializeCanvas(int, int, bool)
Initialize or resize the canvas.
public void InitializeCanvas(int width, int height, bool clearLayers = true)
Parameters
MergeDown(int)
Merge a layer with the one below it.
public void MergeDown(int index)
Parameters
indexint
MergeVisible()
Merge all visible layers into one.
public LayerObject MergeVisible()
Returns
MoveActiveLayer(Vector2)
Move the active layer by delta.
public void MoveActiveLayer(Vector2 delta)
Parameters
deltaVector2
MoveLayerDown(int)
Move a layer down in the stack (towards back).
public void MoveLayerDown(int index)
Parameters
indexint
MoveLayerUp(int)
Move a layer up in the stack (towards front).
public void MoveLayerUp(int index)
Parameters
indexint
ResetActiveLayerCrop()
Reset crop on active layer.
public void ResetActiveLayerCrop()
ResizeActiveLayer(int, int)
Resize active layer.
public void ResizeActiveLayer(int width, int height)
Parameters
RotateActiveLayer(float)
Rotate the active layer.
public void RotateActiveLayer(float degrees)
Parameters
degreesfloat
ScaleActiveLayer(Vector2)
Scale the active layer.
public void ScaleActiveLayer(Vector2 scale)
Parameters
scaleVector2
SetActiveLayer(int)
Set the active layer by index.
public void SetActiveLayer(int index)
Parameters
indexint
SetLayerContainer(RectTransform)
Set the layer container reference.
public void SetLayerContainer(RectTransform container)
Parameters
containerRectTransform
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()