public void RenderCanvas(PaintableObject paintableObject, bool withCursor) { brushCursor.SetActive(false); Transform brushContainer = paintableObject.GetBrushContainer(); brushContainer.gameObject.SetActive(true); baseMaterial.mainTexture = paintableObject.GetBaseTex(); canvasCam.targetTexture = paintableObject.GetCanvas(); canvasCam.Render(); brushContainer.gameObject.SetActive(false); if (withCursor) { brushCursor.SetActive(true); baseMaterial.mainTexture = blackTex; canvasCam.targetTexture = paintableObject.m_cursorTex; canvasCam.Render(); } else { baseMaterial.mainTexture = blackTex; canvasCam.targetTexture = paintableObject.m_cursorTex; canvasCam.Render(); } }
public void SaveTexture(PaintableObject paintableObject) { brushCursor.SetActive(false); baseMaterial.mainTexture = paintableObject.GetCanvas(); canvasCam.targetTexture = paintableObject.GetBaseTex(); canvasCam.Render(); baseMaterial.mainTexture = paintableObject.GetBaseTex(); Transform brushContainer = paintableObject.GetBrushContainer(); Transform brushes = brushContainer.GetChild(0); Transform drips = brushContainer.GetChild(1); while (brushes.childCount > 0) { dotPool.FreeDot(brushes.GetChild(0).gameObject); } for (int i = 0; i < drips.childCount - 1; i++) { GameObject.Destroy(drips.GetChild(i).gameObject); } ShowCursor(); }
public void EyeDrop() { // disable cursor RenderCanvas(lastPaintableObject, false); RenderTexture canvas = lastPaintableObject.GetCanvas(); Texture2D eyeDropTex = new Texture2D(1, 1); Vector2 pixelPos = new Vector2(); pixelPos.x = (brushPos.x + canvasCam.orthographicSize) * canvas.width; pixelPos.y = (brushPos.y + canvasCam.orthographicSize) * canvas.height; Rect pixelRect = new Rect(pixelPos, Vector2.one); RenderTexture.active = canvas; eyeDropTex.ReadPixels(pixelRect, 0, 0); RenderTexture.active = null; ColorSelector.SetColor(eyeDropTex.GetPixel(0, 0)); }