static void OnMapLoaded(ref PNTransferStatusUnity status, IntPtr contextPtr) { GCHandle handle = GCHandle.FromIntPtr(contextPtr); Action <bool, bool, float> loadProgressCb = handle.Target as Action <bool, bool, float>; PNTransferStatusUnity statusClone = status; MainThreadTaskQueue.InvokeOnMainThread(() => { if (statusClone.completed) { Debug.Log("Loaded map!"); loadProgressCb(true, false, 1); handle.Free(); } else if (statusClone.faulted) { Debug.Log("Failed to downloading map!"); loadProgressCb(false, true, 0); handle.Free(); } else { Debug.Log("Downloading map!"); loadProgressCb(false, false, (float)(statusClone.bytesTransferred) / statusClone.bytesTotal); } }); }
static void OnMapUploaded(ref PNTransferStatusUnity status, IntPtr contextPtr) { GCHandle handle = GCHandle.FromIntPtr(contextPtr); SaveLoadContext context = handle.Target as SaveLoadContext; Action <bool, bool, float> progressCb = context.progressCb; PNTransferStatusUnity statusClone = status; Debug.Log(String.Format("mapId {0} completed {1} faulted {2} bytesTransferred {3} bytesTotal {4}", status.mapId, status.completed, status.faulted, status.bytesTransferred, status.bytesTotal) ); MainThreadTaskQueue.InvokeOnMainThread(() => { if (statusClone.completed) { Debug.Log("Uploaded map!"); progressCb(true, false, 1); handle.Free(); } else if (statusClone.faulted) { Debug.Log("Failed to upload map!"); progressCb(false, true, 0); handle.Free(); } else { Debug.Log("Uploading map!"); progressCb(false, false, (float)(statusClone.bytesTransferred) / statusClone.bytesTotal); } }); }