Unity3D在C#中寻找使用纹理绘制的setPixels示例

我需要找到一种方法,允许我使用纹理绘制一个gameObject,目标是克隆这个游戏

我已经认为我可以通过使用我在这里解释的depthMask解决方案伪造绘画function,但是,经过数小时的研究后,似乎可以使用setPixels,setPixel和setPixels32来创建真实的绘画,但由于某种原因所有的setPixels都相关脚本参考的主题是在JavaScript中,我试图将它移植到c#,但我总是有错误,加上它是一种复杂的方法,脚本参考不能很好地解释它,所以我希望有人可以请我写信给我使用setPixels来使用另一个纹理更改对象纹理的一部分的示例? 或者我们可以将整个对象alpha设置为0,当我们点击它时,我们将该纹理alpha的一部分更改为1?

我真的希望这个话题不会因为它的多样性而被关闭,我尽力在解释整个情况时提出一个直截了当的问题。

谢谢

编辑:

几个小时之后,我已经达到了一个非常酷的结果,我认为这可能是达到我的目标的好方法,这个脚本允许用另一个选择的纹理替换材质纹理中的特定像素(目标纹理必须大小相同,可读)

// the texture that i will paint with public Texture2D targetTexture ; //temporary texture Texture2D tmpTexture; void Start () { //setting temp texture width and height tmpTexture = new Texture2D (targetTexture.width, targetTexture.height); for (int y =0; y<tmpTexture.height; y++) { for (int x = 0; x<tmpTexture.width; x++) { //filling the temporary texture with the target texture tmpTexture.SetPixel (x, y, targetTexture.GetPixel (x, y)); } } //Apply tmpTexture.Apply (); //change the object main texture renderer.material.mainTexture = tmpTexture; } 

现在我认为问题只会是“如何根据鼠标在对象上的位置知道应该替换哪个像素”

搞定了 !!

这段代码完美地按预期运行,它有很多评论,它显示了我所做的一切,它不允许动态绘制一个对象,因为我仍然在寻找如何在点击对象后获得纹理坐标,但是,你可以手动输入你的坐标并选择你想要绘制原始对象的目标纹理,我希望这对将来的其他人有用,代码:

 using UnityEngine; using System.Collections; public class BasicPainting : MonoBehaviour { // the texture that i will paint with and the original texture (for saving) public Texture2D targetTexture, originalTexture ; //temporary texture public Texture2D tmpTexture; void Start () { //setting temp texture width and height tmpTexture = new Texture2D (originalTexture.width, originalTexture.height); //fill the new texture with the original one (to avoid "empty" pixels) for (int y =0; y 

你需要两个资产套件;

1- https://www.assetstore.unity3d.com/#/content/2682 for paint(brush vs)
要么
https://www.assetstore.unity3d.com/#/content/11735用于涂料(喷枪vs)

用于精灵工作的2- https://www.assetstore.unity3d.com/#/content/908 (剪切,添加,删除)

使用它来找出与屏幕位置对应的纹理像素:

http://docs.unity3d.com/ScriptReference/RaycastHit-textureCoord.html

但是,你想克隆的游戏看起来只是一个2D游戏,它似乎不需要处理3D。