如何在Unity中显示概述的GUI框? [英] How to show an outlined GUI Box in Unity?

查看:262
本文介绍了如何在Unity中显示概述的GUI框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在屏幕上显示带有彩色边框的透明GUI.Box.我该怎么办?

I would like to show a transparent GUI.Box on screen with a colored border. How can I do this?

推荐答案

  1. 创建一个PNG图片,该图片的透明中心和边框具有所需的厚度.图像的大小无关紧要,但是图像周围的边框应为所需的边框大小.例如,我在 Pixilart 上创建了带有2px绿色边框的64 x 64图像.
  1. Create a PNG image with a transparent center and a border with your desired thickness. The size of the image doesn't matter, but the border around the image should be your desired border size. For instance, I created the 64 x 64 image with a 2px green border on Pixilart.

  1. 在您的项目中将PNG添加为2D纹理.您可以将图像从Finder拖到资产"窗格中以执行此操作.

  1. Add the PNG as a 2D texture in your project. You can drag the image from Finder into your Assets pane to do this.

使用以下GUI.Box调用:

Use the following GUI.Box invocation:

public Texture2D BoxBorder; // Set this to your border texture in the Unity Editor

void OnGUI()
{
    var borderSize = 2; // Border size in pixels
    var style = new GUIStyle();
    style.border = RectOffset(borderSize, borderSize, borderSize, borderSize);
    style.normal.background = BoxBorder;
    GUI.Box(new Rect(/* rect position */), GUIContent.none, style);
}

这篇关于如何在Unity中显示概述的GUI框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆