示例#1
0
    public static IEnumerator Initialize()
    {
        if (status == LoadStatus.Done)
        {
            yield break;
        }
        else if (status == LoadStatus.Loading)
        {
            yield return(new WaitUntil(() => status >= LoadStatus.Done));
        }
        else
        {
            string assetFile = GetAssetFile();

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
            //这两个平台用UnityWebRequest加载要加file://
            assetFile = string.Format("file://{0}", assetFile);
#endif
            Debug.Log("AssetMode:" + mode.ToString() + " assetFile:" + assetFile);

            using (UnityWebRequest request = UnityWebRequest.Get(assetFile))
            {
                status = LoadStatus.Loading;

                UnityWebRequestAsyncOperation operation = request.SendWebRequest();
                yield return(operation);

                if (string.IsNullOrEmpty(request.downloadHandler.text) == false)
                {
                    list.FromXml(request.downloadHandler.text);

                    status = LoadStatus.Done;
                }
                else
                {
                    status = LoadStatus.Error;
                    Debug.LogError(request.error);
                }
            }
        }
    }