unity 加载读取外部XML

cfg.xml

<rootNode>
    <category name="网站">
        <item name="mainPage">www.4463.com</item>
    </category >
</rootNode>

 

testReadXml.cs
using UnityEngine;
using System.Collections;
using System.Xml;

public class testReadXml : MonoBehaviour {
    public string xmlURL;//http://192.168.1.106/app/cfg.xml

    void Start () {
        StartCoroutine (getXML());
    }

    IEnumerator getXML(){
        WWW www = new WWW (xmlURL);
        string progress;
        while(!www.isDone){
            progress=(((int)(www.progress * 100)) % 100) + "%";
            Debug.Log (progress);
            yield return 1;
        }
        if(www.error!=null){
            Debug.Log ("loading error:"+www.url);
        }else{
            progress="100%";
            Debug.Log (progress);
            //enter complete code
            Debug.Log(www.text);
            parseXML(www.text);
        }
    }

    private void parseXML(string xmlText){
        XmlDocument xmlDoc=new XmlDocument();
        xmlDoc.LoadXml(xmlText);
        XmlNodeList nodeList=xmlDoc.SelectSingleNode("rootNode").ChildNodes;
        for(int i=0;i<nodeList.Count;i++){
            XmlElement category=nodeList[i] as XmlElement;
            Debug.Log (category.GetAttribute("name"));//output: 网站
            Debug.Log (category.InnerXml);//output: <item name="mainPage">www.4463.com</item>
            for(int j=0;j<category.ChildNodes.Count;j++){
                XmlElement item=category.ChildNodes[j] as XmlElement;
                Debug.Log (item.GetAttribute("name"));//output: mainPage
                Debug.Log (item.InnerXml);//output: www.4463.com
                Debug.Log (item.InnerText);//output: www.4463.com
            }
        }

    }

}

 

转载于:https://www.cnblogs.com/kingBook/p/6483011.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unity是一款广泛用于游戏开发和多媒体应用程序的跨平台游戏引擎。在Unity加载外部VideoClip非常简单。 首先,我们需要确认视频文件的格式。Unity支持广泛的视频格式,如MP4、MOV、AVI等。确保视频文件的编码和分辨率与Unity兼容。 其次,我们需要将视频文件添加到Unity项目中。将视频文件拖放到Unity工程中的Assets文件夹内即可。确保视频文件已在Unity资源管理器中显示出来。 然后,在Unity的场景中创建一个物体,作为视频播放器的载体。可以是一个空物体或具有Mesh Renderer组件的3D物体。 接着,在Unity的脚本中添加代码来加载和播放视频。使用VideoPlayer组件来加载和控制视频播放。首先,创建一个VideoPlayer对象并指定其视频源,这里是我们之前添加到项目中的VideoClip。然后,设置VideoPlayer的渲染目标为之前创建的载体物体,并将视频播放器启。 最后,在Unity中运行游戏或应用程序,即可看到外部VideoClip被成功加载和播放了。 需要注意的是,Unity加载外部视频可能涉及到文件路径的设置、视频格式的兼容性等问题。如果遇到加载失败或不正常播放的情况,可以检查文件路径是否正确、视频格式是否兼容,或者尝试使用其他视频文件进行测试。 总结起来,Unity加载外部VideoClip可以通过将视频文件添加到项目中并使用VideoPlayer组件来实现。这样,我们就可以在Unity中方便地加载和播放外部视频了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值