using System; using UnityEngine; namespace Es.InkPainter.Sample { public class MousePainter : MonoBehaviour { [Serializable] private enum UseMethodType { RaycastHitInfo = 0, WorldPoint = 1, NearestSurfacePoint = 2, DirectUV = 3 } [SerializeField] private Brush brush; [SerializeField] private UseMethodType useMethodType; [SerializeField] private bool erase; private void Update() { if (!Input.GetMouseButton(0)) { return; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); bool flag = true; if (!Physics.Raycast(ray, out var hitInfo)) { return; } InkCanvas component = hitInfo.transform.GetComponent(); if (component != null) { switch (useMethodType) { case UseMethodType.RaycastHitInfo: flag = (erase ? component.Erase(brush, hitInfo) : component.Paint(brush, hitInfo)); break; case UseMethodType.WorldPoint: flag = (erase ? component.Erase(brush, hitInfo.point) : component.Paint(brush, hitInfo.point)); break; case UseMethodType.NearestSurfacePoint: flag = (erase ? component.EraseNearestTriangleSurface(brush, hitInfo.point) : component.PaintNearestTriangleSurface(brush, hitInfo.point)); break; case UseMethodType.DirectUV: if (!(hitInfo.collider is MeshCollider)) { Debug.LogWarning("Raycast may be unexpected if you do not use MeshCollider."); } flag = (erase ? component.EraseUVDirect(brush, hitInfo.textureCoord) : component.PaintUVDirect(brush, hitInfo.textureCoord)); break; } } if (!flag) { Debug.LogError("Failed to paint."); } } public void OnGUI() { if (GUILayout.Button("Reset")) { InkCanvas[] array = UnityEngine.Object.FindObjectsOfType(); for (int i = 0; i < array.Length; i++) { array[i].ResetPaint(); } } } } }