首页 > 解决方案 > 如何使模态弹出窗口的背景更暗且统一不透明?

问题描述

我有一个模式弹出窗口,其中显示了故事标题列表和一个打开浏览器的按钮,该浏览器指向故事的链接,但弹出窗口现在是透明的 我希望背景看起来更暗

我的模态弹出

需要修改没有透明背景的模态弹出窗口或使背景颜色更深,或者如何更改 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();
        }


    }
}

标签: unity3dunity-container

解决方案


推荐阅读