예제 #1
0
    public void loadResF(string path, loadCallback cb)
    {
        try
        {
                        #if UNITY_WEBPLAYER || UNITY_WEBGL
            if (GameManager.instance)
            {
                GameManager.instance.StartCoroutine(wwwLoad(path, cb));
            }
                        #else
            FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read);

            if (stream == null)
            {
                cb(null, true);
                return;
            }

            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, (int)stream.Length);
            stream.Close();
            stream.Dispose();

            cb(bytes, false);
                        #endif

            //System.GC.Collect();
        }
        catch (Exception ex)
        {
            Debug.LogWarning(ex.Message + " " + path + " load error.");
        }
    }
예제 #2
0
//	public void loadResWWW( string path , loadCallback cb )
//	{
//		if ( GameTestManager.instance )
//		{
//			GameTestManager.instance.StartCoroutine( wwwLoad( path , cb ) );
//		}
//
//		if ( GameManager.instance)
//		{
//			GameManager.instance.StartCoroutine( wwwLoad( path , cb ) );
//		}
//	}


    IEnumerator wwwLoad(string url, loadCallback cb)
    {
        if (Application.platform == RuntimePlatform.WindowsEditor ||
            Application.platform == RuntimePlatform.WindowsPlayer ||
            Application.platform == RuntimePlatform.OSXPlayer ||
            Application.platform == RuntimePlatform.OSXEditor ||
            Application.platform == RuntimePlatform.IPhonePlayer)
        {
            url = "file://" + url;
        }

        UnityWebRequest www = new UnityWebRequest(url);

        yield return(www);

        if (www.isDone)
        {
            if (www.error != null)
            {
                Debug.LogWarning(url + " load error.");
            }
            else
            {
                cb(www.downloadHandler.data, false);
                www.Dispose();
            }
        }
        else
        {
            //cb( null , true );
            Debug.LogWarning(url + " load error.");
        }
    }
예제 #3
0
    public void loadRes(string path, loadCallback cb)
    {
        if (IsWWW)
        {
//			if ( GameTestManager.instance )
//			{
//				GameTestManager.instance.StartCoroutine( wwwLoad( path , cb ) );
//			}
//
//			if ( GameManager.instance)
//			{
//				GameManager.instance.StartCoroutine( wwwLoad( path , cb ) );
//			}
        }
        else
        {
//			try
//			{
                                #if UNITY_WEBPLAYER
            FileStream stream = File.Open(path, FileMode.Open);
                                #else
            FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read);
                                #endif

            if (stream == null)
            {
                cb(null, true);
                return;
            }

            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, (int)stream.Length);
            stream.Close();
            stream.Dispose();

            cb(bytes, false);

            //System.GC.Collect();
//			}
//			catch ( Exception ex )
//			{
//				Debug.LogWarning( ex.Message + " " + path + " load error." );
//			}
        }
    }