直接将代码放在RawImage上(不能放在Image上面)
包含了撤销和清除功能,两个功能也可以联动
需要注意revocations变量不能等于1或者0,否则会进入死循环
用起来如果有卡顿,就改变RawImage的Scale值,Scale越大绘画越流畅
文中用到的GameManager在这篇文章:Unity学习笔记:在GameManager里记录手游操作框架_努力长头发的程序猿的博客-CSDN博客
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class PaintingGraffiti : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
{
public Color color;
//radius的值不能等于1和0,不然会进入死循环
public int radius = 5;
private Canvas canvas;
private RawImage mainImage;
private RectTransform mainRect;
private Texture2D texture;
private bool handIn;
private Vector2 lastPos;
private Color backgroundColor = Color.white;
List> revocations = new List>();
void Start()
{
canvas = transform.root.GetComponent