x


GUI.BeginGroup() and GUI.matrix problem

I'm trying to use GUI.BeginGroup() to clip an area of the GUI where the inner elements can be rotated or scaled. For doing that I change the GUI.matrix. But when I do that the clipping doesn't work.

Anyone knows a way to avoid this problem without removing the use of GUI.matrix?

The code that make the problems:

public void OnGUI()
{
    UnityEngine.GUI.BeginGroup(new UnityEngine.Rect(100, 100, 100, 20));

    GUI.matrix = Matrix4x4.identity;
    for (int i = 0; i < 20; i++)
    {
        GUI.matrix = Matrix4x4.identity * Matrix4x4.TRS(new Vector3(45 * i, 0, 0), Quaternion.identity, Vector3.one);
        UnityEngine.GUI.DrawTexture(new Rect(0, 0, 42, 42), (Texture2D)Resources.Load("some_texture_here"));
    }

    UnityEngine.GUI.EndGroup();
}
more ▼

asked Jul 13 '11 at 09:52 AM

pontfx gravatar image

pontfx
16 2 2 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

No, it isn't possible since the matrix transformations are applied after the clipping. GUI.matrix isn't really useful in most cases. I'm not sure if you can replace the default shader that renders the GUI layer but if it's possible that would be a way to implement your own clipping.

more ▼

answered Jul 13 '11 at 01:38 PM

Bunny83 gravatar image

Bunny83
45k 11 48 206

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3669
x81
x80

asked: Jul 13 '11 at 09:52 AM

Seen: 920 times

Last Updated: Jul 13 '11 at 01:38 PM