Meteor-Unity
3
A C#-based SDK for connecting Unity to Meteor servers
|
A Unity SDK for Meteor. Supports Unity3D 5.3.2 and higher. See the Documentation.
Current version: v2.2. This is regarded as the first fully stable and operational release for desktop and mobile platforms. WebGL is not supported. On iOS and Android, only the Mono2x backend is supported.
See the example code at the bottom of the Readme for an overview of all the supported features. Wherever possible, the API matches the Meteor API, and the details match Meteor details. There are a few exceptions:
Compared to Meteor, Meteor-Unity has some limitations. It cannot simluate code yet, so database side effects must come from the server. It cannot handle documents that aren't explicitly typed.
0. Check out the documentation at http://hiddenswitch.github.io/Meteor-Unity/annotated.html.
Install meteor
and git
```sh
curl https://install.meteor.com/ | sh
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git ```
Create a new Unity project.
```sh
/Applications/Unity/Unity.app/Contents/MacOS/Unity -createProject ~/Documents/Example cd ~/Documents/Example ```
git
functionality.Initialize git
and add the Meteor SDK as a submodule. This lets you use the bleeding edge of the project and contribute back changes to it really easily.
```sh
curl https://github.com/hiddenswitch/Meteor-Unity-Tests/blob/develop/.gitignore > .gitignore
git init
git -am "Initial commit."
git submodule add https://github.com/hiddenswitch/Meteor-Unity.git Assets/Scripts/Meteor-Unity git submodule update –init git commit -am "Adding submodules" ```
Create a meteor
project, add the accounts-password
package, and run the project.
```sh meteor create Web cd Web meteor add accounts-password meteor ```
Connect to your server from Unity. All meteor
work should live in coroutines.
```c# // This will give you access to a .Serialize() method on every object to turn it into // its JSON representation using Meteor.Extensions; IEnumerator MeteorExample() { var production = false;
// Connect to the meteor server. Yields when you're connected if (production) { yield return Meteor.Connection.Connect ("wss://productionserver.com/websocket"); } else { yield return Meteor.Connection.Connect ("ws://localhost:3000/websocket"); }
// Login yield return (Coroutine)Meteor.Accounts.LoginAsGuest ();
// Create a collection var collection = new Meteor.Collection<DocumentType> ("collectionName");
// Add some handlers with the new observer syntax var observer = collection.Find ().Observe (added: (string id, DocumentType document) => { Debug.Log(string.Format("Document added:\n{0}", document.Serialize())); });
// Subscribe var subscription = Meteor.Subscription.Subscribe ("subscriptionEndpointName", /*arguments*/ 1, 3, 4); // The convention to turn something into a connection is to cast it to a Coroutine yield return (Coroutine)subscription;
// Create a method call that returns a string var methodCall = Meteor.Method<string>.Call ("getStringMethod", /*arguments*/1, 3, 4);
// Execute the method. This will yield until all the database sideffects have synced. yield return (Coroutine)methodCall;
// Get the value returned by the method. Debug.Log (string.Format ("Method response:\n{0}", methodCall.Response)); }
public class DocumentType : Meteor.MongoDocument { public string stringField; public int intField; } ```