Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 如何在unity中的弹出窗口中显示链接并在unity中的浏览器中打开链接_Unity3d_Unity Container - Fatal编程技术网

Unity3d 如何在unity中的弹出窗口中显示链接并在unity中的浏览器中打开链接

Unity3d 如何在unity中的弹出窗口中显示链接并在unity中的浏览器中打开链接,unity3d,unity-container,Unity3d,Unity Container,我想解析这个JSON,我想在弹出窗口中显示它,当用户单击任何链接时,它必须在浏览器中打开URL 这是我的JSON: [ { "post_title": "This is an interview book of world film composers.", "guid": "http://abcwebsite.com/news/?p=15" }, { "post_title": "HK Title", "guid": "http://ab

我想解析这个JSON,我想在弹出窗口中显示它,当用户单击任何链接时,它必须在浏览器中打开URL

这是我的JSON:

[
  {
    "post_title": "This is an interview book of world film composers.",
    "guid": "http://abcwebsite.com/news/?p=15"
  },
  {
    "post_title": "HK Title",
          "guid": "http://abcwebsite.com/news/?p=100"
  },
  {
    "post_title": "India China Economy",
     "guid": "http://abcwebsite.com/news/?p=1500"
  }
]
下面是我正在尝试的代码:

我将对此进行解析,但如何打开一个模式HTML弹出窗口来显示弹出窗口上的所有故事列表,以便我可以将所有可单击的链接放在该弹出窗口上,然后当用户单击任何链接时,它必须在浏览器中打开url

我尝试了这段代码,我能够解析,但是我的模式弹出窗口没有提供单击ahref链接的工具

这是我的密码

        void Start () {
                    // Get a reference to the World Map API:
                    map = WorldMapGlobe.instance;            
                    map.OnCountryClick += (int countryIndex, int regionIndex) =>onClickOnCountry(countryIndex,regionIndex);
                    }
        void onClickOnCountry(int countryIndex, int regionIndex){    
                      StartCoroutine(getCountryNews(map.countries [countryIndex].name));               
                     } 
          [System.Serializable]
         public struct countryNewsObject 
         {
             public string post_title;
             public string guid;
         }
         [System.Serializable]
         public class countryNewsData 
         {
             public List<countryNewsObject > country_news_list;
         }
        IEnumerator getCountryNews(string country_name)
            {  
                sModalMessage =""; //clear it initially 
                Debug.Log ("in getCountryNews () Posted paramter country name:"+country_name );              
                WWWForm form = new WWWForm();
                form.AddField("country_name", country_name);       
                using (UnityWebRequest www = UnityWebRequest.Post("http://kitsdmcc.com/news/wp-json/custom-plugin/get_country_news_link", form))
                {
                    Debug.Log ("getLoginedUserCountryList () Posted to get user cuntry list.." );
                    yield return www.SendWebRequest();
                    if (www.isNetworkError)
                    {
                        //errorMessage = www.error;
                        Debug.Log ("Json response error from WP API for UserCountryList : " + www.error );
        yield return null;
                    }
                    else
                    {
                        string responseText = www.downloadHandler.text;
                        Debug.Log ("Json response got from WP API for country news List : " + responseText );    
                      //parse json response:
                        JSONNode jsonMainNode = SimpleJSON.JSON.Parse(responseText);
                        // get individual values from the jsonNode for the data node    
                       string JSONToParse = "{\"country_news_list\":" + responseText.ToString() + "}";       
                       countryNewsData  data = JsonUtility.FromJson<countryNewsData>(JSONToParse);  
                       Debug.Log ("COUNT :"+data.country_news_list.Count);
                      if(data.country_news_list.Count>0){
                        Debug.Log (" get list of news title for this country..." );
                        foreach (countryNewsObject  countryNews in data.country_news_list) {
                        Debug.Log ("Json Response - News Title:"+countryNews.post_title+"  News Link: "+countryNews.guid );

                        string sNewsTitle        = countryNews.post_title;
                        string sHyperLinkofNews  = "<a href="+countryNews.guid+">"+countryNews.post_title+"</a>";
                        sHyperLinkofNews         = sHyperLinkofNews.Replace('"', ' ').Trim();//to get the string without double quotes
                        string    sMessage       = sNewsTitle+ " \n"+sHyperLinkofNews+" \n";
                        sModalMessage =sModalMessage+sMessage ;
                         } 
                        //Call model pop up and add the sModalMessage which is fetched from the json using the above function
                        HFTDialog.MessageBox("News Title and News Links of "+country_name, sModalMessage, () => { Application.Quit(); });
                        Debug.Log ("Json Response - Final Message to Pop- up:"+sModalMessage);
                      }else{
                       HFTDialog.MessageBox("News Title and News Links of "+country_name, "Currently No News Available ", () => { Application.Quit(); });
                         }


                    }
                }
           }
         //End of get country news function
void Start(){
//获取对世界地图API的引用:
map=WorldMapGlobe.instance;
map.OnCountryClick+=(int countryIndex,int regionIndex)=>onClickOnCountry(countryIndex,regionIndex);
}
void onClickOnCountry(int countryIndex,int regionIndex){
Start例程(getCountryNews(map.countries[countryIndex].name));
} 
[系统可序列化]
公共结构countryNewsObject
{
公共字符串post_title;
公共字符串guid;
}
[系统可序列化]
公共类countryNewsData
{
公开名单国家新闻名单;
}
IEnumerator getCountryNews(字符串country\u name)
{  
sModalMessage=“;//最初清除它
Log(“在getCountryNews()中发布参数country name:“+country\u name”);
WWWForm form=新WWWForm();
表格.AddField(“国家名称”,国家名称);
使用(UnityWebRequest www=UnityWebRequest.Post)http://kitsdmcc.com/news/wp-json/custom-plugin/get_country_news_link“,表格(
{
Log(“getLoginedUserCountryList()发布以获取用户cuntry列表..”);
返回www.SendWebRequest();
如果(www.isNetworkError)
{
//errorMessage=www.error;
Log(“UserCountryList的WP API的Json响应错误:”+www.error);
收益返回空;
}
其他的
{
string responseText=www.downloadHandler.text;
Log(“针对国家新闻列表从WP API获得的Json响应:“+responseText”);
//解析json响应:
JSONNode-jsonMainNode=SimpleJSON.JSON.Parse(responseText);
//从jsonNode获取数据节点的各个值
字符串JSONToParse=“{\'country\u news\u list\”:“+responseText.ToString()+”}”;
countryNewsData=JsonUtility.FromJson(JSONToParse);
Log(“COUNT:+data.country\u news\u list.COUNT”);
如果(数据、国家/地区、新闻、列表、计数>0){
Log(“获取这个国家的新闻标题列表…”);
foreach(countryNewsObject数据中的countryNews.country\u新闻列表){
Log(“Json响应-新闻标题:+countryNews.post_Title+”新闻链接:+countryNews.guid);
字符串snewsitle=countryNews.post_title;
字符串sHyperLinkofNews=“”;
sHyperLinkofNews=sHyperLinkofNews.Replace(“,”).Trim();//获取不带双引号的字符串
字符串sMessage=snewsitle+“\n”+sHyperLinkofNews+“\n”;
sModalMessage=sModalMessage+sMessage;
} 
//调用model弹出窗口并添加sModalMessage,该消息是使用上述函数从json获取的
HFTDialog.MessageBox(“新闻标题和“+country_name,sModalMessage,()=>{Application.Quit();}”的新闻链接);
Log(“Json响应-弹出的最终消息:“+sModalMessage”);
}否则{
HFTDialog.MessageBox(“新闻标题和“+country_name,”当前没有可用新闻“,()=>{Application.Quit();}的新闻链接);
}
}
}
}
//获取国家/地区新闻功能结束
模式弹出窗口的代码是

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

        }
    }            

[![Modal pop-up window][1]][1]       
使用UnityEngine;
使用制度;
//例如:
//HFTDialog.MessageBox(“错误”,“对不起,您是S.O.L”,()=>{Application.Quit()});
公共类HFTDialog:单一行为{
矩形m_windowRect;
行动m_行动;
字符串m_标题;
字符串m_msg;
静态公共void消息框(字符串标题、字符串消息、操作)
{
GameObject go=新游戏对象(“HFTDialog”);
HFTDialog dlg=go.AddComponent();
dlg.Init(标题、消息、动作);
}
静态公共void CloseMessageBox(游戏对象go)
{
销毁(go.gameObject);
}
void Init(字符串标题、字符串消息、操作)
{
m_title=标题;
m_msg=msg;
m_动作=动作;
}
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=新矩形(
(屏幕宽度-宽度)/2,
(屏幕高度-高度)/2,
宽度,
高度);
m_windowRect=GUI.Window(0,m_windowRect,WindowFunc,m_t