Example #1
0
    //public static void ChangeCurrentPlayerInBackend(string strUserId, string strPlayerId, PostUserCallback callback)
    //{
    //    auth.SignInWithEmailAndPasswordAsync(YipliHelper.userName, YipliHelper.password).ContinueWith(task =>
    //    {
    //        if (task.IsCanceled)
    //        {
    //            Debug.LogError("SignInAnonymouslyAsync was canceled.");
    //            return;
    //        }
    //        if (task.IsFaulted)
    //        {
    //            Debug.LogError("SignInAnonymouslyAsync encountered an error: " + task.Exception);
    //            return;
    //        }

    //        Firebase.Auth.FirebaseUser newUser = task.Result;
    //        Debug.LogFormat("User signed in successfully: {0} ({1})",
    //            newUser.DisplayName, newUser.UserId);

    //        //FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://yipli-project.firebaseio.com/");
    //        DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;

    //        reference.Child("profiles/users").Child(strUserId).Child("current-player-id").SetValueAsync(strPlayerId);
    //    });
    //}

    /* The function call to be allowed only if network is available */
    //public static async Task<DataSnapshot> GetGameData(string userId, string playerId, string gameId, PostUserCallback callback)
    //{
    //    DataSnapshot snapshot = null;
    //    if (userId.Equals(null) || playerId.Equals(null) || gameId.Equals(null))
    //    {
    //        Debug.Log("User ID not found");
    //    }
    //    else
    //    {
    //        try
    //        {
    //            Firebase.Auth.FirebaseUser newUser = await auth.SignInWithEmailAndPasswordAsync(YipliHelper.userName, YipliHelper.password);
    //            Debug.LogFormat("User signed in successfully: {0} ({1})",
    //            newUser.DisplayName, newUser.UserId);

    //            //FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://yipli-project.firebaseio.com/");
    //            DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
    //            snapshot = await reference.Child("profiles/users/" + userId).Child("players").Child(playerId).Child("activity-statistics/games-statistics").Child(gameId).Child("game-data").GetValueAsync();
    //        }
    //        catch(Exception exp)
    //        {
    //            Debug.Log("Failed to GetGameData : " + exp.Message);
    //        }
    //    }
    //    return snapshot;
    //}

    /* The function call to be allowed only if network is available */
    //public static async Task<List<YipliPlayerInfo>> GetAllPlayerdetails(string userId, PostUserCallback callback)
    //{
    //    List<YipliPlayerInfo> players = new List<YipliPlayerInfo>();
    //    DataSnapshot snapshot = null;
    //    if (userId.Equals(null))
    //    {
    //        Debug.Log("User ID not found");
    //    }
    //    else
    //    {
    //        try
    //        {
    //            Firebase.Auth.FirebaseUser newUser = await auth.SignInWithEmailAndPasswordAsync(YipliHelper.userName, YipliHelper.password);
    //            Debug.LogFormat("User signed in successfully: {0} ({1})",
    //            newUser.DisplayName, newUser.UserId);

    //            //FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://yipli-project.firebaseio.com/");
    //            DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
    //            snapshot = await reference.Child("profiles/users/" + userId).Child("players").GetValueAsync();

    //            foreach (var childSnapshot in snapshot.Children)
    //            {
    //                YipliPlayerInfo playerInstance = new YipliPlayerInfo(childSnapshot, childSnapshot.Key);
    //                if(playerInstance.playerId != null)
    //                {
    //                    players.Add(playerInstance);
    //                }
    //                else
    //                {
    //                    Debug.Log("Skipping this instance of player, backend seems corrupted.");
    //                }
    //            }
    //        }
    //        catch(Exception exp)
    //        {
    //            Debug.Log("Failed to GetAllPlayerdetails : " + exp.Message);
    //            return null;
    //        }
    //    }
    //    return players;
    //}

    ///* The function call to be allowed only if network is available */
    //public static async Task<YipliPlayerInfo> GetCurrentPlayerdetails(string userId, PostUserCallback callback)
    //{
    //    Debug.Log("Getting the Default player from backend");

    //    DataSnapshot snapshot = null;
    //    YipliPlayerInfo defaultPlayer = new YipliPlayerInfo();//Cant return null defaultPlayer. Initialze the default player.

    //    if (userId.Equals(null) || userId.Equals(""))
    //    {
    //        Debug.Log("User ID not found");
    //    }
    //    else
    //    {
    //        try
    //        {
    //            Firebase.Auth.FirebaseUser newUser = await auth.SignInWithEmailAndPasswordAsync(YipliHelper.userName, YipliHelper.password);
    //            Debug.LogFormat("User signed in successfully: {0} ({1})",
    //            newUser.DisplayName, newUser.UserId);

    //            //FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://yipli-project.firebaseio.com/");
    //            DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;

    //            //First get the current player id from user Id
    //            snapshot = await reference.Child("profiles/users").Child(userId).GetValueAsync();
    //            string playerId = snapshot.Child("current-player-id").Value?.ToString() ?? "";

    //            //Now get the complete player details from Player Id
    //            DataSnapshot defaultPlayerSnapshot = await reference.Child("profiles/users/" + userId + "/players/" + playerId).GetValueAsync();

    //            defaultPlayer = new YipliPlayerInfo(defaultPlayerSnapshot, defaultPlayerSnapshot.Key);

    //            if (defaultPlayer.playerId != null)
    //            {
    //                //Do Nothing
    //                Debug.Log("Found Default player : " + defaultPlayer.playerId);
    //            }
    //            else
    //            {
    //                //Case to handle if the default player object doesnt exist in backend/or is corrupted
    //                Debug.Log("Default Player Not found. Returning null.");
    //                return null;
    //            }
    //        }
    //        catch(Exception exp)
    //        {
    //            //If couldnt get defualt player details from the backend, return null.
    //            Debug.Log("Failed to GetAllPlayerdetails: " + exp.Message);
    //            return null;
    //        }
    //    }

    //    return defaultPlayer;
    //}


    // Mat related queries

    /* The function call to be allowed only if network is available */
    //public static async Task<YipliMatInfo> GetCurrentMatDetails(string userId, PostUserCallback callback)
    //{
    //    Debug.Log("Getting the Default mat from backend");
    //    DataSnapshot snapshot = null;
    //    YipliMatInfo defaultMat = new YipliMatInfo();

    //    if (userId.Equals(null) || userId.Equals(""))
    //    {
    //        Debug.Log("User ID not found");
    //    }
    //    else
    //    {
    //        try
    //        {
    //            Firebase.Auth.FirebaseUser newUser = await auth.SignInWithEmailAndPasswordAsync(YipliHelper.userName, YipliHelper.password);
    //            Debug.LogFormat("User signed in successfully: {0} ({1})",
    //            newUser.DisplayName, newUser.UserId);

    //            //FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://yipli-project.firebaseio.com/");
    //            DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;

    //            //First get the current mat id from user Id
    //            snapshot = await reference.Child("profiles/users").Child(userId).GetValueAsync();

    //            string matId = snapshot.Child("current-mat-id").Value?.ToString() ?? "";
    //            //Now get the complete player details from Player Id
    //            DataSnapshot defaultMatSnapshot = await reference.Child("profiles/users/" + userId + "/mats/" + matId).GetValueAsync();
    //            defaultMat = new YipliMatInfo(defaultMatSnapshot, defaultMatSnapshot.Key);

    //            if (defaultMat.matId != null)
    //            {
    //                //Do Nothing
    //                Debug.Log("Found Default mat : " + defaultMat.matId);
    //            }
    //            else
    //            {
    //                //Case to handle if the default mat object doesnt exist in backend/or is corrupted
    //                return null;
    //            }
    //        }
    //        catch(Exception exp)
    //        {
    //            Debug.Log("Failed to GetAllMatdetails : " + exp.Message);
    //            return null;
    //        }
    //    }
    //    return defaultMat;
    //}

    /* The function call to be allowed only if network is available */
    //public static async Task<List<YipliMatInfo>> GetAllMatDetails(string userId, PostUserCallback callback)
    //{
    //    List<YipliMatInfo> mats = new List<YipliMatInfo>();
    //    DataSnapshot snapshot = null;
    //    if (userId.Equals(null) || userId.Equals(""))
    //    {
    //        Debug.Log("User ID not found");
    //    }
    //    else
    //    {
    //        try
    //        {
    //            Firebase.Auth.FirebaseUser newUser = await auth.SignInWithEmailAndPasswordAsync(YipliHelper.userName, YipliHelper.password);
    //            Debug.LogFormat("User signed in successfully: {0} ({1})",
    //            newUser.DisplayName, newUser.UserId);

    //            //FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://yipli-project.firebaseio.com/");
    //            DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
    //            snapshot = await reference.Child("profiles/users/" + userId + "/mats").GetValueAsync();

    //            foreach (var childSnapshot in snapshot.Children)
    //            {
    //                YipliMatInfo matInstance = new YipliMatInfo(childSnapshot, childSnapshot.Key);
    //                if(matInstance.matId != null)
    //                {
    //                    mats.Add(matInstance);
    //                }
    //                else
    //                {
    //                    Debug.Log("Skipping this instance of mat, backend seems corrupted.");
    //                }
    //            }
    //        }
    //        catch(Exception exp)
    //        {
    //            Debug.Log("Failed to GetAllPlayerdetails : " + exp.Message);
    //        }
    //    }
    //    return mats;
    //}


    /*
     * profilePicUrl : Player profile pic property stored already
     * onDeviceProfilePicPath : Path to store the image locally
     */
    public static async Task <Sprite> GetImageAsync(string profilePicUrl, string onDeviceProfilePicPath)
    {
        Debug.Log("Local path : " + onDeviceProfilePicPath);

        // Get a reference to the storage service, using the default Firebase App
        Firebase.Storage.StorageReference storage_ref = yipliStorage.GetReferenceFromUrl(profilePicRootUrl + profilePicUrl);

        Debug.Log("File download started.");

        try
        {
            // Start downloading a file and store it at local_url path
            await storage_ref.GetFileAsync(onDeviceProfilePicPath);

            byte[]    bytes   = System.IO.File.ReadAllBytes(onDeviceProfilePicPath);
            Texture2D texture = new Texture2D(1, 1);
            texture.LoadImage(bytes);
            Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));

            Debug.Log("Profile image downloaded.");
            return(sprite);
        }
        catch (Exception exp)
        {
            Debug.Log("Failed to download Profile image : " + exp.Message);
            return(null);
        }
    }
    IEnumerator AssetBudleDownloadLocal()                                                                               // 로컬 방식 다운로드..
    {
        bLoading = true;
        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("AssetBundleTest1/" + assetBundleName);                            // 업로드 확인해야 함...

        string local_file = "";

        if (Application.platform == RuntimePlatform.Android)
        {
            if (!Directory.Exists(Application.persistentDataPath + "/" + "AssetBundle"))                                                    //폴더가 있는지 체크하고 없으면 만든다.
            {
                Directory.CreateDirectory(Application.persistentDataPath + "/" + "AssetBundle");
            }
            if (File.Exists(Application.persistentDataPath + "/" + "AssetBundle" + "/" + assetBundleName))
            {
                StartCoroutine(AssetBundleLoadFromLocal());                                                                                                 // 에셋번들 로드...
                yield break;
            }
            local_file = Application.persistentDataPath + "/" + "AssetBundle" + "/" + assetBundleName;
        }
        else
        {
            if (File.Exists("C:/Users/Gana/Downloads/AssetBundle/AssetBundle_PC" + "/" + assetBundleName))
            {
                StartCoroutine(AssetBundleLoadFromLocal());
                yield break;
            }
            local_file = "C:/Users/Gana/Downloads/AssetBundle/AssetBundle_PC" + "/" + assetBundleName;
        }

        Task TmpTask = rivers_ref.GetFileAsync(local_file, 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(task => {
            Debug.Log(string.Format("OnClickDownload::IsCompleted:{0} IsCanceled:{1} IsFaulted:{2}", task.IsCompleted, task.IsCanceled, task.IsFaulted));
            if (task.IsFaulted || task.IsCanceled)
            {
                Debug.Log(task.Exception.ToString());
                bLoading = false;
            }
            else
            {
                Debug.Log("Finished downloading...");
            }
        });

        yield return(new WaitUntil(() => TmpTask.IsCompleted));

        PrintState("Downloading Complete");
        StartCoroutine(AssetBundleLoadFromLocal());
    }
    // 파이어 베이스에서 내려받음....
    IEnumerator AssetBudleDownLoad(string _strUrl, string _strDir, string _strBundleName)
    {
        string assetBundleName = _strBundleName;

        bLoading = true;
        Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance;
        // Create a storage reference from our storage service
        Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://sohn123-f1d8d.appspot.com/");
        // Create a reference to the file you want to upload
        //Firebase.Storage.StorageReference rivers_ref = storage_ref.Child("AssetBundle/" + assetBundleName);                            // 업로드 확인해야 함...
        Firebase.Storage.StorageReference rivers_ref = storage_ref.Child(_strUrl);                                                                              // 업로드 확인해야 함...


        string local_file = "";

        if (Application.platform == RuntimePlatform.Android)
        {
            // 아래 수정 해야 함....
            if (!Directory.Exists(Application.persistentDataPath + "/AssetBundle/ " + _strDir))                                                    //폴더가 있는지 체크하고 없으면 만든다.
            {
                Directory.CreateDirectory(Application.persistentDataPath + "/AssetBundle/ " + _strDir);
            }
            local_file = Application.persistentDataPath + "/AssetBundle/" + _strDir + "/" + _strBundleName;
        }
        else
        {
            local_file = "C:/Users/Gana/Downloads/AssetBundle/" + _strDir + "/" + _strBundleName;                                                // PC ....
        }

        Task TmpTask = rivers_ref.GetFileAsync(local_file, 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(task => {
            //Debug.Log(string.Format("OnClickDownload::IsCompleted:{0} IsCanceled:{1} IsFaulted:{2}", task.IsCompleted, task.IsCanceled, task.IsFaulted));
            if (task.IsFaulted || task.IsCanceled)
            {
                Debug.Log(task.Exception.ToString());
                bLoading = false;
            }
            else
            {
                //Debug.Log("Finished downloading...");
            }
        });

        yield return(new WaitUntil(() => TmpTask.IsCompleted));

        //PrintState("Downloading Complete");
        //StartCoroutine(AssetBundleLoadFromLocal());
        Debug.Log("Finished");
    }
Example #4
0
    void Test()
    {
        Debug.Log("downloading image");
        Firebase.Storage.FirebaseStorage  storage     = Firebase.Storage.FirebaseStorage.DefaultInstance;
        Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://stargaze-embedded.appspot.com/image.jpg");

        // Create local filesystem URL
        string local_url = "file:///local/images/image.jpg";

        // Download to the local filesystem
        storage_ref.GetFileAsync(local_url).ContinueWith(task => {
            if (!task.IsFaulted && !task.IsCanceled)
            {
                Debug.Log("File downloaded.");
            }
        });
    }
    IEnumerator LocalDownloadXmlQuiz(string _fileName)
    {
        // test....
        fileName = _fileName;
        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("XmlFile_Chuncheon/" + fileName);                                                          // 하위 폴더...

        string local_file = "";

        // 경로 지정....
        if (Application.platform == RuntimePlatform.Android)
        {
            local_file = Application.persistentDataPath + "/" + fileName;                                           // android 의 접근 가능한 주소,, 폴더 추가 가능..
        }
        else
        {
            local_file = Application.streamingAssetsPath + "/" + fileName;
        }

        Task TmpTask = rivers_ref.GetFileAsync(local_file, 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(task => {
            Debug.Log(string.Format("OnClickDownload::IsCompleted:{0} IsCanceled:{1} IsFaulted:{2}", task.IsCompleted, task.IsCanceled, task.IsFaulted));
            if (task.IsFaulted || task.IsCanceled)
            {
                Debug.Log(task.Exception.ToString());
                // Uh-oh, an error occurred!
                Debug.Log("Oops,, Error..");
            }
            else
            {
                Debug.Log("Finished downloading...");
            }
        });

        yield return(new WaitUntil(() => TmpTask.IsCompleted));

        bXmlFileQuiz = true;
    }
Example #6
0
    // 로컬 다운로드...
    IEnumerator LocalDownloadStart()
    {
        // 로컬 방식....
        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");
        // Create a reference to the file you want to upload
        Firebase.Storage.StorageReference rivers_ref = storage_ref.Child("AssetBundleTest1/" + fileName);

        string local_file = "";

        if (Application.platform == RuntimePlatform.Android)
        {
            local_file = Application.persistentDataPath + "/" + fileName;                           // android 의 접근 가능한 주소,, 폴더 추가 가능..
        }
        else
        {
            local_file = "C:/Users/Gana/Downloads/AsssetBundle/" + fileName;
        }

        //var TmpTask = rivers_ref.GetFileAsync(local_file).ContinueWith(task => {
        var TmpTask = rivers_ref.GetFileAsync(local_file, 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(task => {
            Debug.Log(string.Format("OnClickDownload::IsCompleted:{0} IsCanceled:{1} IsFaulted:{2}", task.IsCompleted, task.IsCanceled, task.IsFaulted));
            if (task.IsFaulted || task.IsCanceled)
            {
                Debug.Log(task.Exception.ToString());
                // Uh-oh, an error occurred!
                //authUI.ShowNotice("Error....");
                Debug.Log("Oops,, Error..");
            }
            else
            {
                Debug.Log("Finished downloading...");
            }
        });

        yield return(new WaitUntil(() => TmpTask.IsCompleted));

        PrintState("Finished downloading...");
    }