Tanoda
ReflectPainter.cs
Go to the documentation of this file.
2using UnityEngine;
3
5{
6 public class ReflectPainter : MonoBehaviour
7 {
8 [SerializeField] private Brush brush;
9
10 [SerializeField] private GameObject camPref;
11
12 private RenderTexture rt;
13 private Camera cam;
14 private Vector2 uv;
15 private InkCanvas paintObject;
16
17 public void Awake()
18 {
19 rt = new RenderTexture(Screen.width, Screen.height, 16, RenderTextureFormat.ARGB32);
20 brush.ColorBlending = Brush.ColorBlendType.UseBrush;
21 }
22
23 public void OnGUI()
24 {
25 if (GUILayout.Button("Reset"))
26 {
27 if (paintObject != null)
28 paintObject.ResetPaint();
29 Destroy(cam);
30 cam = null;
31 }
32 }
33
34 private void Update()
35 {
36 if (cam == null && Input.GetMouseButtonDown(0))
37 {
38 var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
39 RaycastHit hitInfo;
40 if (Physics.Raycast(ray, out hitInfo))
41 {
42 paintObject = hitInfo.transform.GetComponent<InkCanvas>();
43 if (paintObject != null)
44 {
45 uv = hitInfo.textureCoord;
46 var camObj = Instantiate(camPref, hitInfo.point, Quaternion.LookRotation(hitInfo.normal),
47 hitInfo.transform);
48 cam = camObj.GetComponent<Camera>();
49 cam.targetTexture = rt;
50 camObj.SetActive(true);
51 }
52 }
53 }
54 else if (cam != null)
55 {
56 var buf = RenderTexture.GetTemporary(brush.BrushTexture.width, brush.BrushTexture.height);
57 GrabArea.Clip(brush.BrushTexture, brush.Scale, rt, Vector3.one * 0.5f, brush.RotateAngle,
58 GrabArea.GrabTextureWrapMode.Clip, buf);
59 ReverseUV.Horizontal(buf, buf);
60 var brushBuf = brush.BrushTexture;
61 brush.BrushTexture = buf;
62 if (paintObject != null)
63 paintObject.PaintUVDirect(brush, uv);
64 RenderTexture.ReleaseTemporary(buf);
65 brush.BrushTexture = brushBuf;
66 }
67 }
68 }
69}
Class managing brush information.
Definition: Brush.cs:11
float RotateAngle
Rotate angle of the brush.
Definition: Brush.cs:168
float Scale
The size of the brush. It takes a range from 0 to 1.
Definition: Brush.cs:159
ColorBlendType ColorBlending
Color synthesis method.
Definition: Brush.cs:206
ColorBlendType
Color synthesis method.
Definition: Brush.cs:16
Texture BrushTexture
Brush texture.
Definition: Brush.cs:131
Texture paint to canvas. To set the per-material.
Definition: InkCanvas.cs:23
bool PaintUVDirect(Brush brush, Vector2 uv, Func< PaintSet, bool > materialSelector=null)
Paint processing that UV coordinates to the specified.
Definition: InkCanvas.cs:687
void ResetPaint()
To reset the paint.
Definition: InkCanvas.cs:899
Definition: ClipPainter.cs:5