Unity3d 如何使模态弹出窗口的背景更暗和不透明?
我有一个模式弹出窗口,其中显示了一个故事标题列表和一个按钮,用于打开指向故事链接的浏览器,但弹出窗口现在是透明的,我希望背景看起来更暗 需要在没有透明背景的情况下修改模式弹出窗口或使背景颜色变暗,或者如何更改GUI模式不透明,或者如何为此GUI设置不透明值 请在此处检查我的模式弹出代码:Unity3d 如何使模态弹出窗口的背景更暗和不透明?,unity3d,unity-container,Unity3d,Unity Container,我有一个模式弹出窗口,其中显示了一个故事标题列表和一个按钮,用于打开指向故事链接的浏览器,但弹出窗口现在是透明的,我希望背景看起来更暗 需要在没有透明背景的情况下修改模式弹出窗口或使背景颜色变暗,或者如何更改GUI模式不透明,或者如何为此GUI设置不透明值 请在此处检查我的模式弹出代码: using UnityEngine; using System; using System.Collections.Generic; using System.Collections.ObjectModel
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
// example:
// HFTDialog.MessageBox("error", "Sorry but you're S.O.L", () => { Application.Quit() });
public class HFTDialog : MonoBehaviour {
Rect m_windowRect;
Action m_action;
string m_title;
string m_msg;
string[] m_myNewsTitleColl;
string[] m_myColl;
GUIStyle labelStyle, labelStyleShadow, buttonStyle, sliderStyle, sliderThumbStyle;
// The position on of the scrolling viewport
public Vector2 scrollPosition = Vector2.zero;
private GUIStyle guiStyle; //create a new variable
static public void MessageBox(string[] myNewsTitleColl, string[] myColl,string title, string msg, Action action)
{
GameObject go = new GameObject("HFTDialog");
HFTDialog dlg = go.AddComponent<HFTDialog>();
dlg.Init(myNewsTitleColl,myColl,title, msg, action);
}
static public void CloseMessageBox(GameObject go)
{
Destroy(go.gameObject);
}
void Init( string[] myNewsTitleColl,string[] myColl,string title, string msg, Action action)
{
m_title = title;
m_msg = msg;
m_action = action;
m_myColl=myColl;
m_myNewsTitleColl=myNewsTitleColl;
}
void OnGUI()
{
const int maxWidth = 640;
const int maxHeight = 480;//480;
int width = Mathf.Min(maxWidth, Screen.width - 20);
int height = Mathf.Min(maxHeight, Screen.height - 20);
m_windowRect = new Rect(
(Screen.width - width) / 2,
(Screen.height - height) / 2,
width,
height);
GUI.color = Color.white;
GUI.backgroundColor = Color.yellow;
m_windowRect = GUI.Window(0, m_windowRect, WindowFunc, m_title);
}
void WindowFunc(int windowID)
{
const int border = 10;
const int width = 50;
const int height = 25;
const int spacing = 10;
guiStyle = new GUIStyle();
//guiStyle.fontSize = 14; //change the font size
guiStyle.fontStyle = FontStyle.Bold;
guiStyle.normal.textColor = Color.white;
int myNewsTitlePositionY=border + spacing;//Initial position
if(m_myNewsTitleColl.Length==0){
Rect l = new Rect(border, myNewsTitlePositionY,m_windowRect.width - border * 2,m_windowRect.height - border * 2 - height - spacing);
GUI.Label(l, "Currently No News Available ,Please try later..",guiStyle);//This is the news title label
}
else{
for(var i = 0; i < m_myNewsTitleColl.Length; i++)
{
var NewsTitle = m_myNewsTitleColl[i];
Rect l = new Rect(border, myNewsTitlePositionY,m_windowRect.width - border * 2,m_windowRect.height - border * 2 - height - spacing);
GUI.Label(l, NewsTitle,guiStyle);//This is the news title label
myNewsTitlePositionY=myNewsTitlePositionY+33;//next y position of the news title label
}
}
int myY=-15;
for(var i = 0; i < m_myColl.Length; i++)
{
var item = m_myColl[i];
// work with link item here to make a button
myY=myY+33; //Y position of button
Rect btn = new Rect(550,myY, width+25, height);
//Rect btn = new Rect(510,myY, width+25, height); //when scroll enable -
if (GUI.Button(btn, "Open Link"))
{
//open browser pointing the url
Application.OpenURL(item);
}
Debug.Log ("from string array value is :"+item);
}
//End Scrollview
// GUI.EndScrollView();
Rect b = new Rect(
m_windowRect.width - width - border,
m_windowRect.height - height - border,
width,
height);
if (GUI.Button(b, "close"))
{
Destroy(this.gameObject);
// m_action();
}
}
}
使用UnityEngine;
使用制度;
使用System.Collections.Generic;
使用System.Collections.ObjectModel;
//例如:
//HFTDialog.MessageBox(“错误”,“对不起,您是S.O.L”,()=>{Application.Quit()});
公共类HFTDialog:单一行为{
矩形m_windowRect;
行动m_行动;
字符串m_标题;
字符串m_msg;
字符串[]m_myNewsTitleColl;
字符串[]m_myColl;
GUI样式标签样式,标签样式阴影,按钮样式,滑块样式,滑块样式;
//滚动视口上的位置
公共向量2滚动位置=向量2.0;
private GUIStyle GUIStyle;//创建一个新变量
静态公共void消息框(字符串[]myNewsTitleColl,字符串[]myColl,字符串标题,字符串消息,操作)
{
GameObject go=新游戏对象(“HFTDialog”);
HFTDialog dlg=go.AddComponent();
dlg.Init(myNewsTitleColl、myColl、title、msg、action);
}
静态公共void CloseMessageBox(游戏对象go)
{
销毁(go.gameObject);
}
void Init(字符串[]myNewsTitleColl,字符串[]myColl,字符串标题,字符串消息,操作)
{
m_title=标题;
m_msg=msg;
m_动作=动作;
m_myColl=myColl;
m_myNewsTitleColl=myNewsTitleColl;
}
void OnGUI()
{
const int maxWidth=640;
const int maxHeight=480;//480;
int width=Mathf.Min(maxWidth,Screen.width-20);
int height=Mathf.Min(maxHeight,Screen.height-20);
m_windowRect=新矩形(
(屏幕宽度-宽度)/2,
(屏幕高度-高度)/2,
宽度,
高度);
GUI.color=color.white;
GUI.backgroundColor=Color.yellow;
m_windowRect=GUI.Window(0,m_windowRect,WindowFunc,m_title);
}
void WindowFunc(int windowID)
{
常数int border=10;
const int width=50;
const int height=25;
常数int间距=10;
guiStyle=新的guiStyle();
//guiStyle.fontSize=14;//更改字体大小
guiStyle.fontStyle=fontStyle.Bold;
guiStyle.normal.textColor=Color.white;
int myNewsTitlePositionY=边框+间距;//初始位置
if(m_myNewsTitleColl.Length==0){
Rect l=新Rect(边框,myNewsTitlePositionY,m_windowRect.width-边框*2,m_windowRect.height-边框*2-高度-间距);
Label(l,“当前没有新闻,请稍后再试…”,guiStyle);//这是新闻标题标签
}
否则{
对于(var i=0;i
您正在使用Unity 2019。这意味着你肯定是后统一4.6。不要使用。imgui(即时UI)很难调试,缺乏灵活性,并且强制将所有静态UI编入代码中,这些代码必须在每一帧执行才能可见。UGUI在场景视图中使用游戏对象,这更快、更易于使用,并且更易于自定义。IMGUI剩下的唯一用途是编辑器脚本。