Coder Social home page Coder Social logo

charles-bruel / unity.library.eppz.cloud Goto Github PK

View Code? Open in Web Editor NEW

This project forked from geri-borbas/unity.library.eppz.cloud

0.0 0.0 0.0 5.89 MB

 iCloud Key-value store native iOS plugin for Unity. With callbacks on changes per value.

License: Other

Objective-C 35.81% C# 61.75% Objective-C++ 2.44%

unity.library.eppz.cloud's Introduction

eppz.Cloud Build Status

part of Unity.Library.eppz

 iCloud Key-value store native iOS plugin for Unity. With callbacks on changes per value.

Simple usage

You can use it just like PlayerPrefs, if you don't need more control.

// Set values.
Cloud.SetStringForKey("eppz!", "name");
Cloud.SetFloatForKey(0.5f, "volume");
Cloud.SetIntForKey(4, "level");
Cloud.SetBoolForKey(true, "sound");

// Get values.
nameLabel.text = cloud.StringForKey("name");
volumeSlider.value = cloud.FloatForKey("volume");
game.level = cloud.IntForKey("level");
sound.volume = cloud.BoolForKey("sound");

As iCloud Key-Value store uses a local container on the device to manage data, iCloud Key-value store is effectively always available.

See corresponding official iCloud Design Guide at Choose the Proper iCloud Storage API for details.

 iCloud Key-Value store limitations

It is probably best suitable for stuff like preferences / game progress. Files, and binary data is likely to grow over the size limitations below pretty soon.

  • Storage is 1 MB per user
  • The maximum number of keys is 1024
  • Size limit for each value is 1 MB
  • The maximum length for a key string is 64 bytes (does not count against your 1 MB total quota)

See corresponding official iCloud Design Guide at Data Size Limits for Key-Value Storage for details.

Advanced usage

If you want to have a finer grained control over the details of synchronizing (key changes, conflict resolution, user changes), you'll probably like features below.

// Keep UI in sync with cloud content.
Cloud.OnKeyChange("gold", (int value) =>
{ goldLabel.text = value; });
// Simple resolution if local and remote values differ.
Cloud.OnKeyChange("gold", (int value) =>
{
	bool isConflict = (user.golds != value);
    if (isConflict)
    {
    	// Resolve strategy.
    	user.golds = Math.Max(user.golds, value);
    	// Sync (if any) new value.
        Cloud.SetIntForKey(user.golds, "gold");
        // Show (if any) new value.
    	goldLabel.text = user.golds;
    }
});

You can implement you own conflict resolution strategy at each value change callbacks. Also by these live callbacks you have the opportunity to update the game state / UI state on the fly.

On each callback, you can poll a paramerer Cloud.latestChangeReason that holds the reason for the given cloud update. Please note that when a cloud update occurs due to a user change (use signed out from iCloud, then signed in with a different user), you'll probably have to overwrite the game states without orchestrating any conflict resolution.

Best practice for resolving conflicts

See corresponding official iCloud Design Guide at Resolving Key-Value Conflicts.

License

Licensed under the MIT license.

unity.library.eppz.cloud's People

Contributors

geri-borbas avatar charles-bruel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.