Tanoda
TriggerPainter.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3
5{
6 [RequireComponent(typeof(Collider), typeof(MeshRenderer))]
7 public class TriggerPainter : MonoBehaviour
8 {
9 [SerializeField] private Brush brush;
10
11 [SerializeField] private int wait = 3;
12
13 private int waitCount;
14
15 private bool cantPaint;
16
17 public void Awake()
18 {
19 GetComponent<MeshRenderer>().material.color = brush.Color;
20 }
21
22 public void FixedUpdate()
23 {
24 ++waitCount;
25 }
26
27 private void OnTriggerStay(Collider other)
28 {
29 if (other.gameObject.layer == /*PREVIEW_LAYER*/20)
30 return;
31
32 if (waitCount < wait)
33 return;
34 waitCount = 0;
35
36 if (cantPaint)
37 return;
38
39
40 var canvas = other.gameObject.GetComponent<InkCanvas>();
41 if (canvas != null)
42 try
43 {
44 canvas.Paint(brush, other.ClosestPoint(transform.position));
45 }
46 catch (Exception)
47 {
48 cantPaint = true;
49 }
50 }
51 }
52}
Class managing brush information.
Definition: Brush.cs:11
Color Color
The color of the brush.
Definition: Brush.cs:197
Texture paint to canvas. To set the per-material.
Definition: InkCanvas.cs:23
bool Paint(Brush brush, Vector3 worldPos, Func< PaintSet, bool > materialSelector=null, Camera renderCamera=null)
Paint processing that use world-space surface position.
Definition: InkCanvas.cs:793