Example #1
0
        public static void DownloadFileToLocal(string remoteFilename, string localFilename, Action <StateCode, string> callback, Action <float> callbackProgress = null)
        {
            EditorCoroutine downloadFileCoroutine = null;

            downloadFileCoroutine = EditorCoroutine.Start(
                DownloadFile(
                    remoteFilename,
                    (stateCode, message, data) =>
            {
                if (StateCode.SUCCESS == stateCode)
                {
                    try
                    {
                        File.WriteAllBytes(localFilename, data);
                        callback(StateCode.SUCCESS, null);
                    }
                    catch (Exception e)
                    {
                        callback(StateCode.UNKNOWN_ERROR, e.Message);
                    }
                }
                else
                {
                    callback(stateCode, message);
                }

                if (downloadFileCoroutine != null)
                {
                    coroutineList.Remove(downloadFileCoroutine);
                    downloadFileCoroutine = null;
                }
            },
                    callbackProgress
                    )
                );
            coroutineList.Add(downloadFileCoroutine);
        }