检查对象是否全部绘制

Check if object is all painted

我有一个棕色精灵,里面有一个三角形的洞。

我添加了一个轨迹渲染器(并设置它在图层中的顺序以显示在精灵后面),因此用户可以在不绘制精灵本身的情况下绘制精灵的洞。

我的问题是:如何检测孔何时全部涂漆?

我考虑过使用着色器来检查屏幕中是否有任何黑色像素,但我不知道是否可行,因为着色器不知道它占图像的百分比。

一种方法是使用 ScreenCapture.CaptureScreenshotAsTexture method and then loop through an array of pixel colors from Texture2D.GetPixels32 截取屏幕截图。然后您可以检查数组是否包含 'black' 像素。

我会在协程中执行此操作以获得更好的性能,因为每一帧都执行此操作可能会降低您的应用程序的速度。根据统一文档,对于 CaptureScreenshotAsTexture 来说,重要的是:

To get a reliable output from this method you must make sure it is called once the frame rendering has ended, and not during the rendering process. A simple way of ensuring this is to call it from a coroutine that yields on WaitForEndOfFrame. If you call this method during the rendering process you will get unpredictable and undefined results.