unity3d - 如何使模态弹出窗口的背景更暗且统一不透明?
问题描述
我有一个模式弹出窗口,其中显示了故事标题列表和一个打开浏览器的按钮,该浏览器指向故事的链接,但弹出窗口现在是透明的 我希望背景看起来更暗
需要修改没有透明背景的模态弹出窗口或使背景颜色更深,或者如何更改 GUI 模态不透明或我可以为此 GUI 设置不透明值?
请在此处查看我的模态弹出代码:
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();
}
}
}
解决方案
推荐阅读
- reactjs - 材质 UI 中的样式
- swift - 如何从 Firebase 解码一个空数组?
- python - 在 Python 中同时保存 float 和 int 到文件
- python - 如何在 python 中使用 PIL 将文本居中放在图像上,并在 for 或 while 循环中使用不同的名称保存图像?
- javascript - Google Script doPost 仅接受来自单个 URL 的
- typescript - 如何使用 comlink 抛出/捕获自定义错误。打字稿
- javascript - 如何向图像滑块添加过渡/动画?
- r - 在 GLM 分析中使用小鼠输入的数据集;可以获得合并模型拟合指数吗?
- vba - VBA Word 宏选择插入的形状
- python - 如何在地图上绘制一些引用的标签?使用卡托比