Skip to content

Commit 6120923

Browse files
Bump versions
1 parent 87310e3 commit 6120923

File tree

4 files changed

+122
-5
lines changed

4 files changed

+122
-5
lines changed

Examples.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/AccountsExample.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System.Collections;
2+
using UnityEngine;
3+
4+
namespace Meteor.Examples
5+
{
6+
/// <summary>
7+
/// A simple example demonstrating the accounts package and basic subscription and method calling.
8+
///
9+
/// To use this with a meteor server, add the following content to a javascript file in the server/ directory:
10+
/// <code>
11+
/// let collection = new Mongo.Collection('collectionName', {connection: null});
12+
/// Meteor.publish('subscriptionEndpointName', function (number1, number2, number3) {
13+
/// console.log(`Subscribed: ${number1}, ${number2}, ${number3}`);
14+
/// return collection.find({});
15+
/// });
16+
///
17+
/// Meteor.methods({
18+
/// 'getStringMethod': function (number1, number2, number3) {
19+
/// console.log(`Called method: ${number1}, ${number2}, ${number3}`);
20+
/// return "test";
21+
/// }
22+
/// });
23+
///
24+
/// Meteor.setInterval(function () {
25+
/// collection.insert({
26+
/// stringField: 'test',
27+
/// intField: 1
28+
/// })
29+
/// }, 1000);
30+
///
31+
/// Accounts.onCreateUser(function (user) {
32+
/// console.log(`User created: ${user._id}`);
33+
/// return user;
34+
/// });
35+
/// </code>
36+
/// </summary>
37+
public class AccountsExample : MonoBehaviour
38+
{
39+
IEnumerator Start()
40+
{
41+
yield return StartCoroutine(MeteorExample());
42+
}
43+
44+
IEnumerator MeteorExample()
45+
{
46+
var production = false;
47+
48+
// Connect to the meteor server. Yields when you're connected
49+
yield return Meteor.Connection.Connect("ws://localhost:3000/websocket");
50+
51+
// Login
52+
yield return (Coroutine) Meteor.Accounts.LoginAsGuest();
53+
54+
// Create a collection
55+
var collection = new Meteor.Collection<DocumentType>("collectionName");
56+
57+
// Add some handlers with the new observer syntax
58+
var observer = collection.Find().Observe(added: (string id, DocumentType document) =>
59+
{
60+
Debug.Log($"Document added: [_id={document._id}]");
61+
});
62+
63+
// Subscribe
64+
var subscription = Meteor.Subscription.Subscribe("subscriptionEndpointName", /*arguments*/ 1, 3, 4);
65+
// The convention to turn something into a connection is to cast it to a Coroutine
66+
yield return (Coroutine) subscription;
67+
68+
// Create a method call that returns a string
69+
var methodCall = Meteor.Method<string>.Call("getStringMethod", /*arguments*/1, 3, 4);
70+
71+
// Execute the method. This will yield until all the database side effects have synced.
72+
yield return (Coroutine) methodCall;
73+
74+
// Get the value returned by the method.
75+
Debug.Log($"Method response:\n{methodCall.Response}");
76+
}
77+
78+
public class DocumentType : Meteor.MongoDocument
79+
{
80+
public string stringField;
81+
public int intField;
82+
}
83+
}
84+
}

Examples/AccountsExample.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
Meteor-Unity
22
============
33

4-
**Download Version 3.1:** http://hiddenswitch.github.io/Meteor-Unity/Meteor-Unity_v3.1.unitypackage.
4+
**Download Version 3.2:** http://hiddenswitch.github.io/Meteor-Unity/Meteor-Unity_v3.2.unitypackage.
55

6-
A Unity SDK for Meteor. Tested with Unity3D 5.3.2p2, Meteor's Galaxy hosting and Modulus hosting on iOS 9.2 and 9.3 64bit platforms. See the [Documentation](http://hiddenswitch.github.io/Meteor-Unity/annotated.html).
6+
A Unity SDK for Meteor. Tested with Unity3D 2018.3.2f1 on il2cpp platforms. See the [Documentation](http://hiddenswitch.github.io/Meteor-Unity/annotated.html).
77

88
This release supports `il2cpp` backends, allowing it to be used in production for iOS builds. iOS, Android and desktop platforms are supported. WebGL is not supported.
99

1010
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 is an exception to how things usually work in Meteor:
1111

12-
- In Meteor, disconnecting and reconnecting triggers a removal of all records and adding of all new records, as though a subscription was torn down and recreated. In Meteor-Unity, disconnecting does not result in removing records, while reconnecting will result in add messages / added called in observe handles.
13-
14-
Compared to Meteor, Meteor-Unity has some limitations. It cannot simulate code yet, so database side effects must come from the server. It cannot handle documents that aren't explicitly typed.
12+
Compared to Meteor, Meteor-Unity has some limitations. It cannot simulate code yet, so database side effects must come from the server. It also cannot handle documents that are not explicitly typed.
1513

1614
##### Tips
1715

@@ -93,3 +91,32 @@ Compared to Meteor, Meteor-Unity has some limitations. It cannot simulate code y
9391
public int intField;
9492
}
9593
```
94+
95+
To use the above example, include the following file in the `server/` directory in your Meteor project:
96+
97+
```js
98+
let collection = new Mongo.Collection('collectionName', {connection: null});
99+
Meteor.publish('subscriptionEndpointName', function (number1, number2, number3) {
100+
console.log(`Subscribed: ${number1}, ${number2}, ${number3}`);
101+
return collection.find({});
102+
});
103+
104+
Meteor.methods({
105+
'getStringMethod': function (number1, number2, number3) {
106+
console.log(`Called method: ${number1}, ${number2}, ${number3}`);
107+
return "test";
108+
}
109+
});
110+
111+
Meteor.setInterval(function () {
112+
collection.insert({
113+
stringField: 'test',
114+
intField: 1
115+
})
116+
}, 1000);
117+
118+
Accounts.onCreateUser(function (user) {
119+
console.log(`User created: ${user._id}`);
120+
return user;
121+
});
122+
```

0 commit comments

Comments
 (0)