Skip to content

Commit 87310e3

Browse files
Update readme
1 parent 69f7b90 commit 87310e3

File tree

1 file changed

+56
-60
lines changed

1 file changed

+56
-60
lines changed

README.md

Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -27,73 +27,69 @@ Compared to Meteor, Meteor-Unity has some limitations. It cannot simulate code y
2727
0. Check out the documentation at http://hiddenswitch.github.io/Meteor-Unity/annotated.html.
2828

2929
1. Install `meteor`.
30-
31-
```sh
32-
# Install meteor
33-
curl https://install.meteor.com/ | sh
34-
```
30+
```sh
31+
# Install meteor
32+
curl https://install.meteor.com/ | sh
33+
```
3534

3635
2. Create a new Unity project.
37-
38-
```sh
39-
# For Mac
40-
/Applications/Unity/Unity.app/Contents/MacOS/Unity -createProject ~/Documents/Example
41-
cd ~/Documents/Example
42-
```
36+
```sh
37+
# For Mac
38+
/Applications/Unity/Unity.app/Contents/MacOS/Unity -createProject ~/Documents/Example
39+
cd ~/Documents/Example
40+
```
4341

4442
4. Download and install the [Meteor-Unity package](http://hiddenswitch.github.io/Meteor-Unity/Meteor-Unity_v3.0.unitypackage).
4543

4644

4745
5. Create a `meteor` project, add the `accounts-password` package, and run the project.
48-
49-
```sh
50-
meteor create Web
51-
cd Web
52-
meteor add accounts-password
53-
meteor
54-
```
46+
```sh
47+
meteor create Web
48+
cd Web
49+
meteor add accounts-password
50+
meteor
51+
```
5552

5653
6. Connect to your server from Unity. All `meteor` work should live in coroutines. Here is an example which uses a coroutine (`IEnumerator`) to sequence a bunch of actions one after another. In this example, we assume we've defined a collection called `collectionName` on the server and created a few methods and subscriptions. You can't copy and paste the code below and expect it to work with an empty `meteor` project, but it will compile.
57-
58-
```c#
59-
IEnumerator MeteorExample() {
60-
var production = false;
54+
```c#
55+
IEnumerator MeteorExample() {
56+
var production = false;
6157
62-
// Connect to the meteor server. Yields when you're connected
63-
if (production) {
64-
yield return Meteor.Connection.Connect ("wss://productionserver.com/websocket");
65-
} else {
66-
yield return Meteor.Connection.Connect ("ws://localhost:3000/websocket");
67-
}
68-
69-
// Login
70-
yield return (Coroutine)Meteor.Accounts.LoginAsGuest ();
71-
72-
// Create a collection
73-
var collection = new Meteor.Collection<DocumentType> ("collectionName");
74-
75-
// Add some handlers with the new observer syntax
76-
var observer = collection.Find ().Observe (added: (string id, DocumentType document) => {
77-
Debug.Log(string.Format("Document added: [_id={0}]", document._id));
78-
});
79-
80-
// Subscribe
81-
var subscription = Meteor.Subscription.Subscribe ("subscriptionEndpointName", /*arguments*/ 1, 3, 4);
82-
// The convention to turn something into a connection is to cast it to a Coroutine
83-
yield return (Coroutine)subscription;
84-
85-
// Create a method call that returns a string
86-
var methodCall = Meteor.Method<string>.Call ("getStringMethod", /*arguments*/1, 3, 4);
87-
88-
// Execute the method. This will yield until all the database side effects have synced.
89-
yield return (Coroutine)methodCall;
90-
91-
// Get the value returned by the method.
92-
Debug.Log (string.Format ("Method response:\n{0}", methodCall.Response));
93-
}
94-
95-
public class DocumentType : Meteor.MongoDocument {
96-
public string stringField;
97-
public int intField;
98-
}
99-
```
58+
// Connect to the meteor server. Yields when you're connected
59+
if (production) {
60+
yield return Meteor.Connection.Connect ("wss://productionserver.com/websocket");
61+
} else {
62+
yield return Meteor.Connection.Connect ("ws://localhost:3000/websocket");
63+
}
64+
65+
// Login
66+
yield return (Coroutine)Meteor.Accounts.LoginAsGuest ();
67+
68+
// Create a collection
69+
var collection = new Meteor.Collection<DocumentType> ("collectionName");
70+
71+
// Add some handlers with the new observer syntax
72+
var observer = collection.Find ().Observe (added: (string id, DocumentType document) => {
73+
Debug.Log(string.Format("Document added: [_id={0}]", document._id));
74+
});
75+
76+
// Subscribe
77+
var subscription = Meteor.Subscription.Subscribe ("subscriptionEndpointName", /*arguments*/ 1, 3, 4);
78+
// The convention to turn something into a connection is to cast it to a Coroutine
79+
yield return (Coroutine)subscription;
80+
81+
// Create a method call that returns a string
82+
var methodCall = Meteor.Method<string>.Call ("getStringMethod", /*arguments*/1, 3, 4);
83+
84+
// Execute the method. This will yield until all the database side effects have synced.
85+
yield return (Coroutine)methodCall;
86+
87+
// Get the value returned by the method.
88+
Debug.Log (string.Format ("Method response:\n{0}", methodCall.Response));
89+
}
90+
91+
public class DocumentType : Meteor.MongoDocument {
92+
public string stringField;
93+
public int intField;
94+
}
95+
```

0 commit comments

Comments
 (0)