Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于位置的Unity3d渲染纹理_C#_Unity3d - Fatal编程技术网

C# 基于位置的Unity3d渲染纹理

C# 基于位置的Unity3d渲染纹理,c#,unity3d,C#,Unity3d,我目前正在尝试创建一个内部有多个四边形的容器,并且正在寻找一种方法来阻止四边形中超出容器边界的部分被渲染 我只是花了二十分钟试图弄清楚如何正确地解释这个问题(但失败了),所以我画了一幅漂亮的图画。红线表示边界,黑色正方形表示我的纹理四边形 试试这个: private Rect ClipRectToScreen (Rect input) { // Special handling for screen

我目前正在尝试创建一个内部有多个四边形的容器,并且正在寻找一种方法来阻止四边形中超出容器边界的部分被渲染

我只是花了二十分钟试图弄清楚如何正确地解释这个问题(但失败了),所以我画了一幅漂亮的图画。红线表示边界,黑色正方形表示我的纹理四边形

试试这个:

private Rect ClipRectToScreen (Rect input)
                    {
                            // Special handling for screen reading of render texture so it always stay in visible area.
                            // Will throw error withoud this fix.
                            Rect r;
                            r = new Rect (input.x, (Screen.height - input.y - input.height) , input.width, input.height);
                            if (r.x < 0f) {
                                    r.width = r.width - UnityEngine.Mathf.Abs (r.x);
                                    r.x = 0f;
    //                              Debug.Log ("x < 0");
                            }
                            if (r.y < 0f) {
                                    r.height = r.height - UnityEngine.Mathf.Abs (r.y);
                                    r.y = 0f;
    //                              Debug.Log ("y < 0");
                            }
                            if (r.x > Screen.width) {
                                    r.width = r.width - UnityEngine.Mathf.Abs (r.x);
                                    r.x = 0f;
    //                              Debug.Log ("x > Screen.width");
                            }
                            if (r.y > Screen.height) {
                                    r.height = r.height - UnityEngine.Mathf.Abs (r.y);
                                    r.y = 0f;
    //                              Debug.Log ("y > Screen.height");
                            }
                            if ((r.x + r.width) > Screen.width) {
                                    r.width = Screen.width - r.x;
    //                              Debug.Log ("r.x + r.width > Screen.width");
                            }
                            if ((r.y + r.height) > Screen.height) {
                                    r.height = Screen.height - r.y;
    //                              Debug.Log ("r.y + r.height > Screen.height");
                            }

                            return r;
                    }
private Rect-ClipRectToScreen(Rect输入)
{
//对渲染纹理的屏幕读取进行特殊处理,使其始终保持在可见区域。
//将在没有此修复的情况下抛出错误。
矩形r;
r=新的Rect(input.x,(Screen.height-input.y-input.height),input.width,input.height);
如果(r.x<0f){
r、 宽度=r.width-UnityEngine.Mathf.Abs(r.x);
r、 x=0f;
//Debug.Log(“x<0”);
}
如果(r.y<0f){
r、 高度=r.height-UnityEngine.Mathf.Abs(r.y);
r、 y=0f;
//Debug.Log(“y<0”);
}
如果(r.x>屏幕宽度){
r、 宽度=r.width-UnityEngine.Mathf.Abs(r.x);
r、 x=0f;
//Debug.Log(“x>Screen.width”);
}
如果(r.y>屏幕高度){
r、 高度=r.height-UnityEngine.Mathf.Abs(r.y);
r、 y=0f;
//Debug.Log(“y>Screen.height”);
}
如果((r.x+r.width)>屏幕宽度){
r、 宽度=屏幕宽度-r.x;
//Debug.Log(“r.x+r.width>Screen.width”);
}
如果((y+r高度)>屏幕高度){
r、 高度=屏幕高度-r.y;
//Debug.Log(“r.y+r.height>Screen.height”);
}
返回r;
}

一定要在Unity answers上发帖,你很可能会在那里得到回复。谢谢你的提示,will Do你的问题有点详细。您是在纹理上完成这些操作,还是四边形的实际网格是统一的?如果是网格,则需要进行数学运算以分割超出边界的四边形,或者使用着色器将超出边界的像素设置为透明。这两种选择都不容易用如此简单的答案来表达。