WWW加载资源

今天项目中遇到一个必须使用StreamingAssets这个目录,而这个目录里面必须使用www加载界面上的资源,自己就总结下,方便下次忘记时可以翻看

private IEnumerator SetLoadingBg()
    {
        string[] bgName = YFSDKManager.Instance.GetChannelImageDate ().GetLoadingArray();
        string path = AppConst.PathURL + "ChannelImage/" +  bgName[Random.Range(0,bgName.Length)];
        WWW www = new WWW(path);
        yield return www;
        if (www.bytes == null) {
            Debug.Log ("请求数据失败");
        }
        if(string.IsNullOrEmpty(www.error))
        {
            ShowBG (www.texture);
        }
    }

public void ShowBG(UnityEngine.Texture tex)
    {
        BG.mainTexture = tex;
    }

这样就可以完美的加载资源啦

猜你喜欢

转载自www.cnblogs.com/qinshuaijun/p/10145005.html