1

我目前正在尝试在 Unity 中创建一个包含多个四边形的容器,并且正在寻找一种方法来阻止渲染容器边界之外的四边形部分?

我只花了 20 分钟试图弄清楚如何正确解释问题(但失败了),所以创建了这张漂亮的图片。红线代表边界,黑色方块代表我的纹理四边形。

在此处输入图像描述

4

1 回答 1

0

尝试这个:

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;
                    }
于 2014-07-17T16:27:25.723 回答