示例#1
0
    IEnumerator FileFetchAllVersions()
    {
        JCloudDocumentOperation operation = JCloudDocument.FileFetchAllVersions("testfile.txt");

        while (!operation.finished)
        {
            yield return(null);
        }

        if (operation.success && operation.result != null)
        {
            JCloudDocumentVersions versions = (JCloudDocumentVersions)operation.result;
            documentResultString = "cloud document test file versions :";
            int offset = 1;
            foreach (JCloudDocumentVersionMetadata metadata in versions.versionsMetadata)
            {
                documentResultString += " " + offset + ". " + metadata.modificationDate + (metadata.isCurrent ? " (current)" : "");
                offset++;
            }
            documentResultString += " (hash : " + versions.versionsHash + ")" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
        else
        {
            documentResultString = "cloud document test file versions : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
示例#2
0
    IEnumerator DirectoryExists()
    {
        JCloudDocumentOperation operation = JCloudDocument.DirectoryExists("Test");

        while (!operation.finished)
        {
            yield return(null);
        }
        documentResultString = "cloud document test directory exists : " + ((bool)operation.result ? "exists" : "does not exist") + (operation.error != null ? (" ; error : " + operation.error) : "");
    }
示例#3
0
    IEnumerator DirectoryCreate()
    {
        JCloudDocumentOperation operation = JCloudDocument.DirectoryCreate("Test");

        while (!operation.finished)
        {
            yield return(null);
        }
        documentResultString = "cloud document did create test directory with " + ((bool)operation.result ? "success" : "failure") + (operation.error != null ? (" ; error : " + operation.error) : "");
    }
示例#4
0
    IEnumerator DirectoryModificationDate()
    {
        JCloudDocumentOperation operation = JCloudDocument.DirectoryModificationDate("Test");

        while (!operation.finished)
        {
            yield return(null);
        }
        documentResultString = "cloud document test directory modification date : " + (operation.success ? ((System.DateTime)operation.result).ToString("MM-dd-yyyy HH:mm:ss") : "failure") + (operation.error != null ? (" ; error : " + operation.error) : "");
    }
示例#5
0
    IEnumerator FileReadConflictVersionBytes()
    {
        JCloudDocumentOperation operation;

        operation = JCloudDocument.FileFetchAllVersions("testfile.txt");
        while (!operation.finished)
        {
            yield return(null);
        }

        if (operation.success && operation.result != null)
        {
            JCloudDocumentVersions        versions = (JCloudDocumentVersions)operation.result;
            JCloudDocumentVersionMetadata?conflictVersionMetadata = null;
            foreach (JCloudDocumentVersionMetadata metadata in versions.versionsMetadata)
            {
                if (metadata.isCurrent == false)
                {
                    conflictVersionMetadata = metadata;
                    break;
                }
            }

            if (conflictVersionMetadata != null)
            {
                operation = JCloudDocument.FileReadVersionBytes("testfile.txt", conflictVersionMetadata.Value.uniqueIdentifier);
                while (!operation.finished)
                {
                    documentResultString = "cloud document read conflict version bytes progress : " + operation.progress;
                    yield return(null);
                }
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
                if (operation.success)
                {
                    documentResultString = "cloud document did read conflict version bytes ; read this : " + ((operation.result == null) ? "(null)" : encoder.GetString(operation.result as byte[])) + (operation.error != null ? (" ; error : " + operation.error) : "");
                }
                else
                {
                    documentResultString = "cloud document read conflict version bytes : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
                }
            }
            else
            {
                documentResultString = "cloud document read conflict version bytes : failure" + (operation.error != null ? (" ; error : " + operation.error) : "") + " (found no conflict version)";
            }
        }
        else
        {
            documentResultString = "cloud document read conflict version bytes : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
示例#6
0
    IEnumerator FilePickCurrentVersion()
    {
        JCloudDocumentOperation operation;

        operation = JCloudDocument.FileFetchAllVersions("testfile.txt");
        while (!operation.finished)
        {
            yield return(null);
        }

        if (operation.success && operation.result != null)
        {
            JCloudDocumentVersions        versions = (JCloudDocumentVersions)operation.result;
            JCloudDocumentVersionMetadata?currentVersionMetadata = null;
            foreach (JCloudDocumentVersionMetadata metadata in versions.versionsMetadata)
            {
                if (metadata.isCurrent == true)
                {
                    currentVersionMetadata = metadata;
                    break;
                }
            }

            if (currentVersionMetadata != null)
            {
                operation = JCloudDocument.FilePickVersion("testfile.txt", currentVersionMetadata.Value.uniqueIdentifier, versions.versionsHash);
                while (!operation.finished)
                {
                    yield return(null);
                }

                if (operation.success)
                {
                    documentResultString = "cloud document did pick current version : " + (((bool)operation.result == true) ? "success" : "failure") + (operation.error != null ? (" ; error : " + operation.error) : "");
                }
                else
                {
                    documentResultString = "cloud document did pick current version : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
                }
            }
            else
            {
                documentResultString = "cloud document did pick current version : failure" + (operation.error != null ? (" ; error : " + operation.error) : "") + " (found no current version)";
            }
        }
        else
        {
            documentResultString = "cloud document did pick current version : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
示例#7
0
    IEnumerator FileDelete()
    {
        JCloudDocumentOperation operation = JCloudDocument.FileDelete("testfile.txt");

        while (!operation.finished)
        {
            yield return(null);
        }
        if (operation.success && (bool)operation.result)
        {
            documentResultString = "cloud document did delete" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
        else
        {
            documentResultString = "cloud document did not delete (may not exist?)" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
示例#8
0
    IEnumerator DirectoryDelete()
    {
        JCloudDocumentOperation operation = JCloudDocument.DirectoryDelete("Test");

        while (!operation.finished)
        {
            yield return(null);
        }
        if (operation.success)
        {
            documentResultString = "cloud document test directory deleted : " + ((bool)operation.result ? "success" : "failure") + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
        else
        {
            documentResultString = "cloud document test directory deleted : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
示例#9
0
    IEnumerator FileHasConflictVersions()
    {
        JCloudDocumentOperation operation = JCloudDocument.FileHasConflictVersions("testfile.txt");

        while (!operation.finished)
        {
            yield return(null);
        }

        if (operation.success)
        {
            documentResultString = "cloud document test file has conflict versions : " + ((bool)operation.result ? "yes" : "no") + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
        else
        {
            documentResultString = "cloud document test file has conflict versions : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
示例#10
0
    IEnumerator FileWriteAllBytesConflict()
    {
        System.Text.UTF8Encoding encoder   = new System.Text.UTF8Encoding();
        JCloudDocumentOperation  operation = JCloudDocument.FileWriteAllBytes("testfile.txt", encoder.GetBytes("this is a conflict test content"));

        while (!operation.finished)
        {
            yield return(null);
        }
        if (operation.success)
        {
            documentResultString = "cloud document did write bytes with : " + ((bool)operation.result ? "success" : "failure") + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
        else
        {
            documentResultString = "cloud document write all bytes failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
示例#11
0
    IEnumerator DirectoryCopy()
    {
        JCloudDocumentOperation operation = JCloudDocument.DirectoryCopy("Test", "Test Copy", true);

        while (!operation.finished)
        {
            documentResultString = "cloud document test directory copy progress : " + operation.progress;
            yield return(null);
        }
        if (operation.success)
        {
            documentResultString = "cloud document test directory copy : " + ((bool)operation.result ? "success" : "failure") + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
        else
        {
            documentResultString = "cloud document test directory copy : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
示例#12
0
    IEnumerator FileReadAllBytes()
    {
        JCloudDocumentOperation operation = JCloudDocument.FileReadAllBytes("testfile.txt");

        while (!operation.finished)
        {
            documentResultString = "cloud document read bytes progress : " + operation.progress;
            yield return(null);
        }
        System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
        if (operation.success)
        {
            documentResultString = "cloud document did read bytes ; read this : " + ((operation.result == null) ? "(null)" : encoder.GetString(operation.result as byte[])) + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
        else
        {
            documentResultString = "cloud document read bytes : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
示例#13
0
    IEnumerator LoadGame()
    {
        JCloudDocumentOperation operation = JCloudDocument.FileReadAllBytes("Savegames/My saved game.sav");

        while (!operation.finished)
        {
            yield return(null);
        }

        // Look for error -- if any, handle & stop coroutine here
        if (operation.error.HasValue)
        {
            HandleDocumentError(operation.error.Value);
            yield break;
        }

        // Success
        error = null;
        byte[] gameBytes = operation.result as byte[];

        // No bytes, no savegame
        if (gameBytes != null)
        {
            System.IO.MemoryStream dataStream = new System.IO.MemoryStream(gameBytes);
            System.IO.BinaryReader reader     = new System.IO.BinaryReader(dataStream);

            // Read player state
            DeserializeTransformFromReader(player.transform, reader);
            DeserializeRigidbodyFromReader(player.rigidbody, reader);

            // Read player camera state
            DeserializeTransformFromReader(playerCamera.transform, reader);

            // Read red, green & blue cubes state
            DeserializeTransformFromReader(redCube.transform, reader);
            DeserializeRigidbodyFromReader(redCube.rigidbody, reader);
            DeserializeTransformFromReader(greenCube.transform, reader);
            DeserializeRigidbodyFromReader(greenCube.rigidbody, reader);
            DeserializeTransformFromReader(blueCube.transform, reader);
            DeserializeRigidbodyFromReader(blueCube.rigidbody, reader);
        }
    }
示例#14
0
    IEnumerator DirectoryGetDirectories()
    {
        JCloudDocumentOperation operation = JCloudDocument.DirectoryGetDirectories("");

        while (!operation.finished)
        {
            yield return(null);
        }

        if (operation.success)
        {
            documentResultString = "cloud directory directories list : " + (operation.result as string[]).Length;
            for (int i = 0; i < (operation.result as string[]).Length; i++)
            {
                documentResultString += " ; " + (operation.result as string[])[i];
            }
            documentResultString += (operation.error != null ? (" ; error : " + operation.error) : "");
        }
        else
        {
            documentResultString = "cloud directory directories list : failure" + (operation.error != null ? (" ; error : " + operation.error) : "");
        }
    }
    private IEnumerator DownloadFromCloudByCheckingConflicts(System.Action <UserCloudDownloadDelegateEventArgs> onResul = null)
    {
#if UNITY_IPHONE || UNITY_EDITOR
        JCloudDocumentOperation operation;

        // Let's check file for conflict first
        operation = JCloudDocument.FileHasConflictVersions(FILE_NAME_CLOUD);

        while (operation.finished == false)
        {
            yield return(null);            // Wait for 1 frame
        }
        // Look for error -- if any, handle & stop coroutine here -- ignore cloud unvailable as it simply means conflicts are not handled
        if (operation.error.HasValue && operation.error.Value != JCloudDocumentError.CloudUnavailable)
        {
            HandleDocumentError(operation.error.Value, onResul);
            yield break;
        }

        // Did looking for conflict trigger a result?
        if (((bool?)operation.result).HasValue && (bool)operation.result == true)
        {
            // We have conflicts -- sort them out
            operation = JCloudDocument.FileFetchAllVersions(FILE_NAME_CLOUD);
            while (operation.finished == false)
            {
                yield return(null);
            }

            // Look for error -- if any, handle & stop coroutine here
            if (operation.error.HasValue)
            {
                HandleDocumentError(operation.error.Value, onResul);
                yield break;
            }

            // Get conflict versions
            JCloudDocumentVersions versions = (JCloudDocumentVersions)operation.result;

            // We will now attempt to pick the "best" version (e.g. most progress) -- you could offer UI
            UserCloud temporalUser;
            int       lastLevelTemporalUser = -1;
            byte[]    bestVersionIdentifier = null;
            foreach (JCloudDocumentVersionMetadata metadata in versions.versionsMetadata)
            {
                // Read version bytes
                operation = JCloudDocument.FileReadVersionBytes(FILE_NAME_CLOUD, metadata.uniqueIdentifier);
                while (operation.finished == false)
                {
                    yield return(null);
                }

                // Look for error -- if any, handle & stop coroutine here
                if (operation.error.HasValue)
                {
                    HandleDocumentError(operation.error.Value, onResul);
                    yield break;
                }

                // Pick best version
                temporalUser = UserCloud.Deserialize((byte[])operation.result);

                if (temporalUser == null)
                {
                    continue;
                }

                if (temporalUser.LastFinishedLvl > lastLevelTemporalUser)
                {
                    lastLevelTemporalUser = temporalUser.LastFinishedLvl;
                    bestVersionIdentifier = metadata.uniqueIdentifier;
                }
            }

            // At that point we should have the best version
            if (bestVersionIdentifier != null)
            {
                // Pick it as current version
                operation = JCloudDocument.FilePickVersion(FILE_NAME_CLOUD, bestVersionIdentifier, versions.versionsHash);
                while (operation.finished == false)
                {
                    yield return(null);
                }

                // Look for error -- if any, handle & stop coroutine here
                if (operation.error.HasValue)
                {
                    HandleDocumentError(operation.error.Value, onResul);
                    yield break;
                }
            }
        }

        // At that point conflicts have been cleared -- wait for file reading
        operation = JCloudDocument.FileReadAllBytes(FILE_NAME_CLOUD);
        while (operation.finished == false)
        {
            yield return(null);            // Wait for 1 frame
        }
        // Look for error -- if any, handle & stop coroutine here
        if (operation.error.HasValue)
        {
            HandleDocumentError(operation.error.Value, onResul);
            yield break;
        }

        byte[] bytes = operation.result as byte[];
        if (bytes != null)
        {
            //Save iCloud info in Memory. Then, merge information with local user data
            Debug.Log("- LoadUserFromCloud OK");
            CurrentCloudUser = UserCloud.Deserialize(bytes);
            this.MergeUsers(onResul);
        }
#endif

#if UNITY_ANDROID && !disableGoogleCloud
        byte[] googleCloudDataBytes = null;

        if (CanUseGoogleCloud())
        {
            while (!PlayGameServices.isSignedIn() && googleCloudTryingToLogin)
            {
                yield return(null);                // Wait for n frames until googleCloudTryingToLogin was setted to FALSE
            }

            if (!PlayGameServices.isSignedIn() && !googleCloudTryingToLogin)
            {
                HandleDocumentError(JCloudDocumentError.CloudUnavailable, onResul);
                yield break;
            }

            Debug.Log("[UserManagerCloud] DownloadFromCloudByCheckingConflicts(): Downloading user data from cloud...");
            PlayGameServices.loadCloudDataForKey(0, false);

            // Wait a maximum of 6 seconds to retrieve google cloud data
            float timeLeftToWait = 6f;
            float lastTime       = Time.realtimeSinceStartup;
            while (googleCloudData == null && timeLeftToWait > 0f)
            {
                timeLeftToWait -= Time.realtimeSinceStartup - lastTime;
                lastTime        = Time.realtimeSinceStartup;

                yield return(null);                // Wait for n frames until googleCloudData was setted in loadCloudDataForKeyFailedEvent or loadCloudDataForKeySucceededEvent
            }

            if (googleCloudData == "ERROR" || googleCloudData == null)
            {
                Debug.Log("ANDROID CLOUD SERVICES RETURNED ERROR DOWNLOADING");
                HandleDocumentError(JCloudDocumentError.DocumentNotFound, onResul);
                yield break;
            }

            Debug.Log("[UserManagerCloud] There is google cloud data : " + googleCloudData.Length);

            try
            {
                googleCloudDataBytes = System.Convert.FromBase64String(googleCloudData);
                Debug.Log("[UserManagerCloud] Cloud data size: " + googleCloudDataBytes.Length);
            }
            catch (Exception)
            {
                Debug.LogWarning("[UserManagerCloud] Failed to decode android cloud data: " + googleCloudData);
            }
        }
        CurrentCloudUser = UserCloud.Deserialize(googleCloudDataBytes);
        MergeUsers(onResul);

        //Free memory
        googleCloudData = null;
#endif
        yield break;
    }
    private IEnumerator SaveInCloud(System.Action <UserCloudUploadedDelegateEventArgs> onResultSave = null)
    {
        Debug.Log("Saving in the Cloud");
        UserCloudUploadedDelegateEventArgs args = new UserCloudUploadedDelegateEventArgs();
        bool isPossibleSaveInCloud = true;

        byte[] bytes = null;
        string errorReadingLocalData = string.Empty;

        try
        {
            bytes = System.IO.File.ReadAllBytes(UserCloud.GetPath(FILE_NAME_LOCAL));
            Debug.Log("[UserManagerCloud] Loaded local file user data: " + UserCloud.GetPath(FILE_NAME_LOCAL));
        }
        catch (Exception ex)
        {
            Debug.LogWarning("[SaveInCloud] Error reading local user data file...");
            isPossibleSaveInCloud = false;
            errorReadingLocalData = ex.Message;
        }

        if (isPossibleSaveInCloud == false)
        {
            Debug.LogWarning("Exception reading local user before save it: " + errorReadingLocalData);
            args.Error   = errorReadingLocalData;
            args.Message = "There was an error saving to iCloud";
            args.Result  = false;
            args.SaveIn  = ResultSave.NotSaved;
            RaiseUserHasBeenUploaded(args, onResultSave);

            yield break;
        }

#if UNITY_IPHONE || UNITY_EDITOR
        JCloudDocumentOperation op = JCloudDocument.FileWriteAllBytes(FILE_NAME_CLOUD, bytes);

        while (op.finished == false)
        {
            Debug.Log("[SaveInCloud] Writting user data to cloud: " + op.progress);
            yield return(null);
        }
        if (op.error.HasValue)
        {
            string res = "";
            switch (op.error.Value)
            {
            case JCloudDocumentError.PluginError:
            case JCloudDocumentError.NativeError:
            case JCloudDocumentError.InvalidArguments:                     // Look out for this one as it means you passed invalid path
                // Offer the user to retry
                res = "An error ocurred while saving text file. please retry.";
                Debug.LogWarning("[SaveInCloud] " + res);
                break;

            case JCloudDocumentError.DocumentNotFound:
                res = "There is no file present on this device. Create a new text file.";
                Debug.LogWarning("[SaveInCloud] " + res);
                break;

            case JCloudDocumentError.DownloadTimeout:
                // Offer the user to retry
                res = "Could not download user cloud file. Please retry.";
                Debug.LogWarning("[SaveInCloud] " + res);
                break;

            default:                     // We should never get there
                break;
            }

            Debug.LogWarning("[SaveInCloud] " + op.error.Value);
            args.Error     = res;
            args.Message   = "There was an error saving to iCloud";
            args.Result    = false;
            args.ErrorType = op.error.Value;
            args.SaveIn    = ResultSave.NotSaved;
            RaiseUserHasBeenUploaded(args, onResultSave);
        }
        else
        {
            // OK
            Debug.Log("[SaveInCloud] Saved user file in cloud " + bytes.Length + " bytes");
            args.Error   = string.Empty;
            args.Message = "Saved in iCloud";
            args.Result  = true;
            args.SaveIn  = ResultSave.Cloud;

            Debug.Log("[SaveInCloud] - SaveUser. Level: " + CurrentUser.LastFinishedLvl);

            RaiseUserHasBeenUploaded(args, onResultSave);
        }

        yield break;

//		byte[] bytes = System.IO.File.ReadAllBytes(UserCloud.GetPath(FILE_NAME_LOCAL));
//		JCloudDocument.FileWriteAllBytes(FILE_NAME_CLOUD, bytes);
//
////		UserCloudUploadedDelegateEventArgs args = new UserCloudUploadedDelegateEventArgs();
////
////		if (onResultSave != null)
////			onResultSave(ResultSave.Cloud);
//
//		Debug.Log("Save File in Cloud " + bytes.Length);
//		yield break;
#elif UNITY_ANDROID && !disableGoogleCloud
        if (CanUseGoogleCloud())
        {
            while (!PlayGameServices.isSignedIn() && googleCloudTryingToLogin)
            {
                yield return(null);
            }

            if (PlayGameServices.isSignedIn() && !googleCloudTryingToLogin)
            {
                string strUserData = null;
                try
                {
                    strUserData = System.Convert.ToBase64String(bytes);
                    Debug.Log("[UserManagerCloud] Saving to Google Cloud services: " + bytes.Length + " bytes");
                }
                catch (Exception)
                {
                    Debug.LogWarning("[UserManagerCloud] Failed to encode user raw bytes to string. Size: " + bytes.Length + " bytes");
                }

                if (strUserData != null)
                {
                    PlayGameServices.setStateData(strUserData, 0);
                }
            }
        }

        yield break;
#endif
    }
 private IEnumerator DeleteFromCloud()
 {
     JCloudDocument.FileDelete(FILE_NAME_CLOUD);
     yield break;
 }
示例#18
0
    // Just an exhaustive list of all usable functions with simple text monitoring for returns
    void OnGUI()
    {
        float width  = Screen.width;
        float height = Screen.height / 19;

        if (GUI.Button(new Rect(0.0f, 0.0f, width * 0.5f, height), "Write All Bytes To Test File"))
        {
            StartCoroutine(FileWriteAllBytes());
        }

        if (GUI.Button(new Rect(0.0f, height, width * 0.5f, height), "Read All Bytes From Test File"))
        {
            StartCoroutine(FileReadAllBytes());
        }

        if (GUI.Button(new Rect(0.0f, height * 2, width * 0.5f, height), "Delete Test File"))
        {
            StartCoroutine(FileDelete());
        }

        if (GUI.Button(new Rect(0.0f, height * 3, width * 0.5f, height), "Get Test File Modification Date"))
        {
            StartCoroutine(FileModificationDate());
        }

        if (GUI.Button(new Rect(0.0f, height * 4, width * 0.5f, height), "Check Test File Exists"))
        {
            StartCoroutine(FileExists());
        }

        if (GUI.Button(new Rect(0.0f, height * 5, width * 0.5f, height), "Copy Test File"))
        {
            StartCoroutine(FileCopy());
        }

        if (GUI.Button(new Rect(0.0f, height * 6, width * 0.5f, height), "Write All Bytes To Test File (Conflict)"))
        {
            StartCoroutine(FileWriteAllBytesConflict());
        }

        if (GUI.Button(new Rect(0.0f, height * 7, width * 0.5f, height), "Check Test File Has Conflict Versions"))
        {
            StartCoroutine(FileHasConflictVersions());
        }

        if (GUI.Button(new Rect(0.0f, height * 8, width * 0.5f, height), "Fetch File Fetch All Versions"))
        {
            StartCoroutine(FileFetchAllVersions());
        }

        if (GUI.Button(new Rect(0.0f, height * 9, width * 0.5f, height), "Read Conflict Version Bytes From Test File"))
        {
            StartCoroutine(FileReadConflictVersionBytes());
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 9, width * 0.5f, height), "Pick Conflict Version From Test File"))
        {
            StartCoroutine(FilePickConflictVersion());
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 8, width * 0.5f, height), "Pick Current Version From Test File"))
        {
            StartCoroutine(FilePickCurrentVersion());
        }

        if (GUI.Button(new Rect(0.0f, height * 10, width * 0.5f, height), "Poll Cloud Document Availability"))
        {
            bool availability = JCloudDocument.PollCloudDocumentAvailability();
            documentResultString = "cloud document " + (availability ? "available" : "unavailable");
        }

        if (GUI.Button(new Rect(width * 0.5f, 0.0f, width * 0.5f, height), "Create Test Directory"))
        {
            StartCoroutine(DirectoryCreate());
        }

        if (GUI.Button(new Rect(width * 0.5f, height, width * 0.5f, height), "Check Test Directory Exists"))
        {
            StartCoroutine(DirectoryExists());
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 2, width * 0.5f, height), "Delete Test Directory"))
        {
            StartCoroutine(DirectoryDelete());
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 3, width * 0.5f, height), "Get Test Directory Modification Date"))
        {
            StartCoroutine(DirectoryModificationDate());
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 4, width * 0.5f, height), "List Top Directory Files"))
        {
            StartCoroutine(DirectoryGetFiles());
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 5, width * 0.5f, height), "List Top Directory Folders"))
        {
            StartCoroutine(DirectoryGetDirectories());
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 6, width * 0.5f, height), "Copy Test Directory"))
        {
            StartCoroutine(DirectoryCopy());
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 7, width * 0.5f, height), "Register Cloud Document changes"))
        {
            documentResultString = "now watching cloud document changes";
            JCloudDocument.RegisterCloudDocumentExternalChanges(this);
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 10, width * 0.5f, height), "Clear Resultats"))
        {
            documentResultString = "";
        }

        GUI.Label(new Rect(0.0f, height * 11, width, height * 1.5f), "Document Result : " + documentResultString);

        if (GUI.Button(new Rect(0.0f, height * 11.5f, width * 0.5f, height), "Data Set \"TestKey\" Int"))
        {
            JCloudData.SetInt("TestKey", 15);
            dataResultString = "data set int return is void";
        }

        if (GUI.Button(new Rect(0.0f, height * 12.5f, width * 0.5f, height), "Data Get \"TestKey\" Int"))
        {
            int keyValue = JCloudData.GetInt("TestKey");
            dataResultString = "data get int return is : " + keyValue;
        }

        if (GUI.Button(new Rect(0.0f, height * 13.5f, width * 0.5f, height), "Data Set \"TestKey\" Float"))
        {
            JCloudData.SetFloat("TestKey", 13.37f);
            dataResultString = "data set float return is void";
        }

        if (GUI.Button(new Rect(0.0f, height * 14.5f, width * 0.5f, height), "Data Get \"TestKey\" Float"))
        {
            float keyValue = JCloudData.GetFloat("TestKey");
            dataResultString = "data get float return is : " + keyValue;
        }

        if (GUI.Button(new Rect(0.0f, height * 15.5f, width * 0.5f, height), "Register Cloud Data Changes"))
        {
            dataResultString = "now watching cloud data changes";
            JCloudData.RegisterCloudDataExternalChanges(this);
        }

        if (GUI.Button(new Rect(0.0f, height * 16.5f, width * 0.5f, height), "Poll Cloud Data Availability"))
        {
            bool availability = JCloudData.PollCloudDataAvailability();
            dataResultString = "cloud data " + (availability ? "available" : "unavailable");
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 11.5f, width * 0.5f, height), "Data Set \"TestKey\" String"))
        {
            JCloudData.SetString("TestKey", "this is a test string");
            dataResultString = "data set string return is void";
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 12.5f, width * 0.5f, height), "Data Get \"TestKey\" String"))
        {
            string keyValue = JCloudData.GetString("TestKey");
            dataResultString = "data get string return is : " + keyValue;
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 13.5f, width * 0.5f, height), "Data Has \"TestKey\" Key"))
        {
            bool exists = JCloudData.HasKey("TestKey");
            dataResultString = "data has TestKey key return is : " + (exists ? "yes" : "no");
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 14.5f, width * 0.5f, height), "Data Delete \"TestKey\" Key"))
        {
            JCloudData.DeleteKey("TestKey");
            dataResultString = "data delete TestKey key return is void";
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 15.5f, width * 0.5f, height), "Data Delete All Keys"))
        {
            JCloudData.DeleteAll();
            dataResultString = "data delete all keys return is void";
        }

        if (GUI.Button(new Rect(width * 0.5f, height * 16.5f, width * 0.5f, height), "Data Save"))
        {
            JCloudData.Save();
            dataResultString = "data save return is ok";
        }

        if (GUI.Button(new Rect(0.0f, height * 17.5f, width, height), "Clear Resultats"))
        {
            dataResultString = "";
        }

        GUI.Label(new Rect(0.0f, height * 18.5f, width, height * 1.5f), "Dict/Data Result : " + dataResultString);
    }
示例#19
0
    IEnumerator SaveGame()
    {
        // Failsafe
        if (player && playerCamera && redCube && greenCube && blueCube)
        {
            // Prepare a memory stream & a binary writer
            System.IO.MemoryStream dataStream = new System.IO.MemoryStream();
            System.IO.BinaryWriter writer     = new System.IO.BinaryWriter(dataStream);

            // Write player state
            SerializeTransformToWriter(player.transform, writer);
            SerializeRigidbodyToWriter(player.rigidbody, writer);

            // Write player camera state
            SerializeTransformToWriter(playerCamera.transform, writer);

            // Write red, green & blue cubes state
            SerializeTransformToWriter(redCube.transform, writer);
            SerializeRigidbodyToWriter(redCube.rigidbody, writer);
            SerializeTransformToWriter(greenCube.transform, writer);
            SerializeRigidbodyToWriter(greenCube.rigidbody, writer);
            SerializeTransformToWriter(blueCube.transform, writer);
            SerializeRigidbodyToWriter(blueCube.rigidbody, writer);

            // Save game -- make sure directory exists
            JCloudDocumentOperation operation;
            operation = JCloudDocument.DirectoryExists("Savegames");
            while (!operation.finished)
            {
                yield return(null);
            }

            // Look for error -- if any, handle & stop coroutine here
            if (operation.error.HasValue)
            {
                HandleDocumentError(operation.error.Value);
                yield break;
            }

            if (!(bool)operation.result)
            {
                operation = JCloudDocument.DirectoryCreate("Savegames");
                while (!operation.finished)
                {
                    yield return(null);
                }

                // Look for error -- if any, handle & stop coroutine here
                if (operation.error.HasValue)
                {
                    HandleDocumentError(operation.error.Value);
                    yield break;
                }
            }

            // Write file
            operation = JCloudDocument.FileWriteAllBytes("Savegames/My saved game.sav", dataStream.GetBuffer());
            while (!operation.finished)
            {
                yield return(null);
            }

            // Look for error -- if any, handle & stop coroutine here
            if (operation.error.HasValue)
            {
                HandleDocumentError(operation.error.Value);
                yield break;
            }
        }
    }