IEnumerator DownloadCacheImgByBuffer() // 이미지를 로컬에 저장하지 않고, cache 메모리에 저장 후 화면에 표시.. { bool bError = false; byte[] fileContents2 = null; Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; // Create a storage reference from our storage service //Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://fir-authtest22.appspot.com"); Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://eduplatform-97d55.appspot.com/"); // Create a reference to the file you want to upload Firebase.Storage.StorageReference rivers_ref = storage_ref.Child("ccc/" + fileName); // 최대 사이즈 지정할 수 있음.. const long maxAllowedSize = 5 * 1024 * 1024; // 최대사이즈 일단 5mb var TmpTask = rivers_ref.GetBytesAsync(maxAllowedSize, new Firebase.Storage.StorageProgress <Firebase.Storage.DownloadState>(state => { // 다운로드 진행율 표시... Debug.Log(string.Format("Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount)); PercentView(state.BytesTransferred, state.TotalByteCount); })).ContinueWith((System.Threading.Tasks.Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! bError = true; } else if (task.IsCompleted) { Debug.Log("Finished downloading!"); fileContents2 = task.Result; bError = false; } }); yield return(new WaitUntil(() => TmpTask.IsCompleted)); if (false == bError) { Texture2D tmpTexture = new Texture2D(16, 16, TextureFormat.RGB24, false); bool isLoaded = tmpTexture.LoadImage(fileContents2); while (!isLoaded) { yield return(null); } tmpTexture.name = "tmpTexutre"; rawImage.gameObject.SetActive(true); rawImage.texture = tmpTexture; PrintState("image view"); } else if (true == bError) { PrintState("Error..."); } }
IEnumerator DownloadByBufferTxt() // 텍스트를 로컬에 저장하지 않고, cache 메모리에 저장 후 화면에 표시.. 한글은 UTF-8 만 가능. { bool bError = false; byte[] fileContents = null; Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; // Create a storage reference from our storage service Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://eduplatform-97d55.appspot.com/"); // Create a reference to the file you want to upload Firebase.Storage.StorageReference rivers_ref = storage_ref.Child("ccc/text_1.txt"); // 최대 사이즈.... const long maxAllowedSize = 2 * 1024 * 1024; // 2mb var TmpTask = rivers_ref.GetBytesAsync(maxAllowedSize, new Firebase.Storage.StorageProgress <Firebase.Storage.DownloadState>(state => { // 다운로드 진행율 표시... Debug.Log(string.Format("Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount)); PercentView(state.BytesTransferred, state.TotalByteCount); })).ContinueWith((System.Threading.Tasks.Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! bError = true; } else if (task.IsCompleted) { Debug.Log("Finished downloading!"); fileContents = task.Result; bError = false; } }); yield return(new WaitUntil(() => TmpTask.IsCompleted)); if (false == bError) { string testText = System.Text.Encoding.UTF8.GetString(fileContents); // UTF8로 인코딩하여서 변환... PrintState("lyrics: " + testText); } else if (true == bError) { PrintState("Error..."); } }
public void LoadImageFromStorage() { Firebase.Storage.StorageReference storageReference = Firebase.Storage.FirebaseStorage.DefaultInstance.GetReferenceFromUrl(item.imageURL); loaded = false; storageReference.GetBytesAsync(1024 * 1024). ContinueWith((System.Threading.Tasks.Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); } else { imageData = task.Result; loaded = true; } }); }
public static void LoadImageFromStorage(string URL, System.Action <byte[]> resultTask) { if (Application.internetReachability == NetworkReachability.NotReachable) { return; } Firebase.Storage.StorageReference storageReference = Firebase.Storage.FirebaseStorage.DefaultInstance.GetReferenceFromUrl(URL); storageReference.GetBytesAsync(1024 * 1024). ContinueWith((System.Threading.Tasks.Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); } else { resultTask(task.Result); } }); }
/* * Function that performs the following: * 1. Pulls input from the unity form * 2. Validates the input * 3. Attempts to authenticate the user with username/password using FirebaseAuth * 4. If the user is authenticated, a map is checked for at the location {app_url}/app_height_maps/{user_id}/mobile_height_map.raw" * a. if the map is found, continues with game loop. Terrain will be build on next scene load. * b. if map is not found, populates text box with error message * * TODO: For final product, the .raw height map might have an additional 20 bytes of position data that will need to be read to place the game objects. * */ public async void StartAuthFlowAsync() { Debug.Log("Starting AuthFlow"); // Get auth instance Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; string email = emailField.GetComponent <InputField>().text; string password = passField.GetComponent <InputField>().text; bool auth_result = false; // Validate input if (!ValidateEmailPass(email, password)) { SetErrorTextBox(true, "Invalid Username/Password"); return; } //attempt to sign the user in, wait to proceed await auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SignInWithCustomTokenAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SignInWithCustomTokenAsync encountered an error: " + task.Exception); return; } curUser = task.Result; auth_result = true; }); //if the user was able to log in, continue with file download attempt if (curUser != null && auth_result) { const long maxSize = 3 * 1024 * 1024; //3mb limit (1025x1025x16bit + 32 bytes position data map should always be ~ 2MB) string path = app_folder + "/" + curUser.UserId + "/" + file_name;; //{app_url}/app_height_maps/{userID}/mobile_height_map.raw // Get storage instance Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; string url = storage.RootReference + path; Firebase.Storage.StorageReference gs_reference = storage.GetReferenceFromUrl(url); // Download the .raw heightmap file await gs_reference.GetBytesAsync(maxSize).ContinueWith((Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); heightData = null; } else { heightData = task.Result; CheckForHighScore(); } }); if (heightData != null) { //something was able to be downloaded SetErrorTextBox(false); sceneLoader.GetComponent <SceneLoader>().LoadNextScene(); } else { //file was unable to be downloaded SetErrorTextBox(true, "No heightmap available!"); } } else { // problem authorizing the user SetErrorTextBox(true, "Authorization Failed!"); } }