如何在统一穆迪尔弹出式窗口中创建几个ahref链接

时间:2019-11-25 10:23:28

标签: unity3d unity-container unityscript facebook-unity-sdk

是否可以在弹出窗口中创建ahref链接,还是可以在弹出窗口中支持html标签ahref

我要实现的是,当用户单击游戏对象时,将显示一个模型弹出窗口,并且在该模型的流行故事标题和故事链接将显示为列表,并且当用户单击任何链接时,它必须在浏览器窗口中打开网址。

我尝试了这种模式,但是ahref在此弹出窗口中不起作用

    using UnityEngine;
    using System;

    // 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;

        static public void MessageBox(string title, string msg, Action action)
        {
            GameObject go = new GameObject("HFTDialog");
            HFTDialog dlg = go.AddComponent<HFTDialog>();
            dlg.Init(title, msg, action);
        }


        static public void CloseMessageBox(GameObject go)
        {
           Destroy(go.gameObject);
        }

        void Init(string title, string msg, Action action)
        {
            m_title = title;
            m_msg = msg;
            m_action = action;
        }

        void OnGUI()
        {
            const int maxWidth = 640;
            const int maxHeight = 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);

            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;

            Rect l = new Rect(
                border,
                border + spacing,
                m_windowRect.width - border * 2,
                m_windowRect.height - border * 2 - height - spacing);
            GUI.Label(l, m_msg);

            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();
            }

        }
    }

0 个答案:

没有答案