57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using Es.InkPainter.Effective;
|
|
using UnityEngine;
|
|
|
|
namespace Es.InkPainter.Sample
|
|
{
|
|
public class ClipPainter : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private bool grab = true;
|
|
|
|
[SerializeField]
|
|
private Brush brush;
|
|
|
|
[SerializeField]
|
|
private GrabArea.GrabTextureWrapMode wrapMode = GrabArea.GrabTextureWrapMode.Repeat;
|
|
|
|
private RenderTexture t;
|
|
|
|
private RaycastHit hitInfo;
|
|
|
|
private void OnGUI()
|
|
{
|
|
GUI.Box(new Rect(0f, 0f, 300f, 320f), "");
|
|
GUI.Box(new Rect(0f, 0f, 300f, 300f), "Grab Texture");
|
|
if (t != null)
|
|
{
|
|
GUI.DrawTexture(new Rect(0f, 0f, 300f, 300f), t);
|
|
}
|
|
grab = GUI.Toggle(new Rect(0f, 300f, 300f, 20f), grab, "Grab");
|
|
}
|
|
|
|
public void Awake()
|
|
{
|
|
t = new RenderTexture(brush.BrushTexture.width, brush.BrushTexture.height, 0);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0) && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo))
|
|
{
|
|
InkCanvas component = hitInfo.transform.GetComponent<InkCanvas>();
|
|
if (component != null && !grab)
|
|
{
|
|
component.Paint(brush, hitInfo);
|
|
}
|
|
if (grab)
|
|
{
|
|
GrabArea.Clip(brush.BrushTexture, brush.Scale, hitInfo.transform.GetComponent<MeshRenderer>().sharedMaterial.mainTexture, hitInfo.textureCoord, brush.RotateAngle, wrapMode, t);
|
|
brush.BrushTexture = t;
|
|
brush.ColorBlending = Brush.ColorBlendType.UseBrush;
|
|
grab = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|