42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Es.InkPainter
|
|
{
|
|
public static class GameObjectExtension
|
|
{
|
|
public static InkCanvas AddInkCanvas(this GameObject gameObject, List<InkCanvas.PaintSet> paintDatas)
|
|
{
|
|
if (paintDatas == null || paintDatas.Count == 0)
|
|
{
|
|
Debug.LogError("Parameter is null or empty.");
|
|
return null;
|
|
}
|
|
bool activeSelf = gameObject.activeSelf;
|
|
gameObject.SetActive(value: false);
|
|
InkCanvas inkCanvas = gameObject.AddComponent<InkCanvas>();
|
|
if (inkCanvas == null)
|
|
{
|
|
Debug.LogError("Could not attach InkCanvas to GameObject.");
|
|
return null;
|
|
}
|
|
inkCanvas.OnCanvasAttached += delegate(InkCanvas canvas)
|
|
{
|
|
canvas.PaintDatas = paintDatas;
|
|
};
|
|
gameObject.SetActive(activeSelf);
|
|
return inkCanvas;
|
|
}
|
|
|
|
public static InkCanvas AddInkCanvas(this GameObject gameObject, InkCanvas.PaintSet paintData)
|
|
{
|
|
if (paintData == null)
|
|
{
|
|
Debug.LogError("Parameter is null or empty.");
|
|
return null;
|
|
}
|
|
return gameObject.AddInkCanvas(new List<InkCanvas.PaintSet> { paintData });
|
|
}
|
|
}
|
|
}
|