How to clip EditorGUI.DrawPreviewTexture to GUI group?

+1 vote
asked Apr 27, 2016 in Programming by Gleny Student (480 points)
Is there a way to clip the textures drawn with

EditorGUI.DrawPreviewTexture(rect, texture, material);

When I use the overloaded method without the material argument, it works just fine. When passing a material doesnt get clipped anymore.

I need the material argument to blend solid color textures with the existing background.

Thank you!

1 Answer

+2 votes
answered Apr 27, 2016 by ismix Senior (1,150 points)
selected Apr 27, 2016 by Gleny
Best answer

What you could try is manually clipping the Rect used for drawing.

        public Rect ClipToBounds(Rect rect, Rect bounds)
            Rect r = new Rect();
            r.xMin = Mathf.Clamp(rect.xMin, bounds.xMin, bounds.xMax);
            r.yMin = Mathf.Clamp(rect.yMin, bounds.yMin, bounds.yMax);
            r.xMax = Mathf.Clamp(rect.xMax, bounds.xMin, bounds.xMax);
            r.yMax = Mathf.Clamp(rect.yMax, bounds.yMin, bounds.yMax);

            return r;

But note that this only work with solid color textures, as the uv coords may get skewed.

Welcome to Bugstacker Q&A, where you can ask questions concerning Game Development, Programming and Design and receive answers from other members of the community.

Help for