Coder Social home page Coder Social logo

meteor-unity's Introduction

Meteor-Unity

A Unity SDK for Meteor.

Getting started
  1. Install meteor and meteorite
```sh
# Install Brew if it isn't already installed
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
# Install git if it isn't already installed
brew install git
# Install node
brew install node
# Install npm
brew install npm
# Install meteor
curl https://install.meteor.com/ | sh
# Install meteor's package manager, meteorite
sudo -H npm install -g meteorite
```
  1. Create a new Unity project.
```sh
# For Mac
/Applications/Unity/Unity.app/Contents/MacOS/Unity -createProject ~/Documents/Example
cd ~/Documents/Example
```
  1. Set your Unity project to use text serialization and visible metafiles. This is very important for good git functionality.
  2. 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
# Grab my handy and advanced .gitignore. This command downloads something from the Internet and saves it to a file.
curl https://github.com/hiddenswitch/Meteor-Unity-Tests/blob/develop/.gitignore > .gitignore
# Initialize git.
git init
# Make this your first commit
git -am "Initial commit."
# Add the submodules and initialize them. You can use the Meteor-Unity repo directly, or fork it so you can make changes to it (my practice).
git submodule add [email protected]:hiddenswitch/Meteor-Unity.git Assets/Scripts/Meteor
git submodule update --init --recursive
git commit -am "Adding submodules"
```
  1. Create a meteor project, add the accounts-password package, and run the project.
```sh
meteor create Web
cd Web
meteor add accounts-password
meteor run
```
  1. 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 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 Meteor.Accounts.LoginAsGuest ();

	// Create a collection
	var collection = Meteor.Collection<DocumentType>.Create ("collectionName");

	// Add some handlers
	collection.DidAddRecord += (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;
}
```

meteor-unity's People

Contributors

doctorpangloss avatar neobii avatar

Stargazers

 avatar

Watchers

 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.