public void onFilesSelected(string filenames) { if (_multipleFilesCallback != null) { var files = filenames.Split('|'); var itemsWithStream = new ItemWithStream[files.Length]; for (var i = 0; i < itemsWithStream.Length; i++) { itemsWithStream[i] = new ItemWithStream() { Name = files[i] }; } _multipleFilesCallback(itemsWithStream); } }
private IEnumerator InvokeCallback(string json) { var browserFiles = JArray.Parse(json); var browserItemsWithStream = new ItemWithStream[browserFiles.Count]; if (browserFiles.Count > 0) { for (var i = 0; i < browserFiles.Count; i++) { var browserFile = browserFiles[i]; var loader = new WWW(browserFile.SelectToken("url").ToString()); yield return(loader); if (string.IsNullOrWhiteSpace(loader.error)) { browserItemsWithStream[i] = new ItemWithStream { Name = browserFile.SelectToken("name").ToString(), Stream = new MemoryStream(loader.bytes) }; } else { throw new Exception(loader.error); } } } if (MultipleFilesCallback != null) { MultipleFilesCallback.Invoke(browserItemsWithStream); } else if (SingleFileCallback != null && browserItemsWithStream.Length > 0) { SingleFileCallback.Invoke(browserItemsWithStream[0]); } SingleFileCallback = null; MultipleFilesCallback = null; Destroy(gameObject); }