I recently changed my desk layout so my laptop is next to my mac mini’s monitor. It’s awkward trying to cram two keyboards onto the desk, so I looked into some software I’d heard about that allows multiple machines to share one keyboard and mouse.
It’s called Synergy, and I’d heard other game developers sing its praises. The problem was that running the server or client on OSX Lion was barely working at all, bit rot and API changes had broken a lot of functionality. The potential boon was large enough, and the bugs annoying enough, that I actually did the first C++ programming I’ve done in many years.
The result is a greatly improved Mac client and server available at my bitbucket repot. There are precompiled binaries too, but keep in mind, this code watches all your key presses, so you have reason to be paranoid and want to compile it yourself (I swear I’m not evil or a l33t hacker though).
There are extensive docs about how to setup and use the client and server on the Synergy site. And hopefully they’ll integrate my patches at some point.
p.s. They still use SVN and have to manually apply diff patches when they want to accept contributions from people! If they’d migrate to Bitbucket or Github they could’ve integrated these patches in three clicks.
Good tips from the guy who wrote the super handy PlayModePersist.
Source: twitter.com
I’ve been working on a port of the C# PubNub library that can be used from in Unity3d. I put this together as a test for the library.
Ages ago I found a script for encoding and decoding JSON and popped it up on the Unity forums. Wasn’t great, but it did the job. Yesterday I took a look at it and spotted a bunch of ways it could be cleaned up and optimized.
Even though I still recommend using JsonFX, MiniJSON can still be useful for situations where you just want something really simple (Array, Dictionary, etc.) encoded and decoded and size is a consideration.
Careful though, this script has changed a lot, so it isn’t a drop-in replacement for the old version.
Link with 3 notes
A couple of people have asked how to use the JsonFx library that I put up on bitbucket. The version I’m using is 1.4 from JsonFx.net, and it is poorly documented.
The two key methods are:
JsonReader.Deserialize<T>(string json);
and
JsonWriter.Serialize(object src);
With Deserialize you need to specific the type (T) you want to unpack to. This can be almost any C# class that has public variables or properties. In the example unitypackage linked above, I created two quick classes for Twitter search results, and an individual tweet.
What’s great about JsonFx is that it can deserialize nested classes, so the array of Tweets that is returned in search results gets deserialized too. This is something that I had issues with in most other libraries I evaluated.
The Serialize method just take the object you want to turn into a JSON string and does its thing.
You then have a string you can post to a web server, using the WWWForm and WWW classes in Unity.
If you don’t want to create your own classes for Serialization/Deserialization, you can just use Dictionary<string,object>, or an Array, or whatever.
There are some other things that are hidden inside JsonFx, like a JsonFx.IgnoreAttribute for public fields that you don’t want to be serialized, etc. You’ll have to root around in the assembly or source code for the exact syntax for that stuff. Remember, I didn’t write JsonFx, I just commented out a couple lines to make it work better in Unity.
Here’s the C# script that’s in the above Unity package:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DB = UnityEngine.Debug;
using DC = DebugConsole;
using JsonFx.Json;
public class Tweet {
public System.DateTime created_at;
public string from_user;
public long from_user_id;
public string from_user_id_str;
public string from_user_name;
public string geo;
public long id;
public string id_str;
public string iso_language_code;
public Dictionary<string, string> metadata;
public string profile_image_url;
public string source;
public string text;
public long to_user_id;
public string to_user_id_str;
}
public class TwitterSearchResults {
public float completed_in;
public long max_id;
public string max_id_str;
public string next_page;
public int page;
public string query;
public string refresh_url;
public Tweet[] results;
public int results_per_page;
public long since_id;
public string since_id_str;
}
public class JsonFxDemo : MonoBehaviour {
public string query = "#Unity3d";
// Use this for initialization
void Start () {
DC.IsOpen = true;
StartCoroutine(PerformSearch(query));
}
void PrintResults(string rawJson) {
// Raw output:
DB.Log(DC.Log("******** raw string from Twitter ********"));
DB.Log(DC.Log(rawJson));
// Turn the JSON into C# objects
var search = JsonReader.Deserialize<TwitterSearchResults>(rawJson);
// iterate through the array of results;
DB.Log(DC.Log("******** search results ********"));
foreach (var tweet in search.results) {
DB.Log(DC.Log(tweet.from_user_name + " : " + tweet.text));
}
DB.Log(DC.Log("******** serialize an entity ********"));
// this turns a C# object into a JSON string.
string json = JsonWriter.Serialize(search.results[0]);
DB.Log(DC.Log(json));
}
IEnumerator PerformSearch(string query) {
query = WWW.EscapeURL(query);
using (var www = new WWW(string.Format("http://search.twitter.com/search.json?q={0}", query))) {
while (!www.isDone) {
yield return null;
}
PrintResults(www.text);
}
}
}
Big day, right? I’m having a little staycation and finally had the time to commit some repositories and write some posts. Tomorrow it’ll be back to playing games (gotta finish Arkham City).
It always annoyed me that MonoDevelop didn’t offer code completion for OnGUI, OnEnable, OnCollision, etc. events. Then I discovered that MonoDevelop had support for code snippets.
On the Mac you put these templates into ~/.config/MonoDevelop-Unity/templates/code/. Not sure where they live on PC. Then when you start typing the beginning of a Unity event (On...) it will show you a list of methods to insert. Select one and hit tab to insert it, and then tab again to insert the snippet.
This is only set up for C# Unity files.
Unity Pro has a function that enables external version control. It’s great because you don’t have to pay $500 for a Unity Asset Server license, but it’s kind of a mess because it adds a ton of .meta files, and if you don’t commit the .meta file with the regular file you’ve broken version control.
Unity Pro also has some powerful asset post processor functions that let you customize the importing pipeline. Maybe these could work together (hint).
This script uses an asset post processor function to find added/deleted/moved files and correctly apply those changes to a local Mercurial (hg) repository (including the associated .meta files).
Mercurial is a great distributed version control system that can have large binary support enabled. Mercurial.net is an awesome .net library that lets you interact with Mercurial repositories in C#. I mixed that chocolate and peanut butter with a Unity script to automate some of the grunt work of keeping a Unity repository in sync.
The script doesn’t do push/pull/commit/merge (yet), so you’ll still need to use the command line or GUI client to do that stuff. I use MacHg, SourceTree, and TortoiseHg.
I don’t know if there’s a similar .net library for git, but if there is it should be relatively easy to do the same thing for a git repot. SVN and Perforce integration might be possible too, but since those are coming in Unity 3.5 anyway, it’s probably not worth the effort.
I don’t know if I’ll have time to support this script, but hopefully it can be a useful starting place for other developers.
Ummm…I think this works. It waits interval seconds and then saves any modified assets.
This may not seem like a big deal to you, but frequently prefabs and materials in a Unity 3D project aren’t saved until you either quit Unity or select “Save Project” from the File menu. This script sorta fixes that. This can be important if you’re using version control.
Link with 3 notes
DebugConsole.cs has been really useful to me. Especially when I’ve been trying to debug iPhone or standalone builds of Unity projects.
When I first added the DebugConsole to my project I didn’t understand a lot of the magic it contained. I’m pretty sure it was my first introduction to C# delegates. Since then I’ve leveled up a few times and add a ton of stuff to the DebugConsole script.
I’m sharing my modifications to the DebugConsole, because learning how it worked was so helpful to me.
Here are a couple of the changes that I’ve made, you’ll have to scour the source and learn some stuff to discover all of it.
<enter> now submits the command line if it has focus.I just forked tipfy on bitbucket and committed a bunch of changes that I make every time I start a new project. This includes a base jinja template that is derived from h5bp.com’s settings, and a crapload of mimetypes added to app.yaml, taken from h5bp’s server-config repository.
The hello_world.html has been updated to inherit from h5bp.html, to give an example of how to use template inheritance.
h5bp’s build script is included, which minifies css and js files, with modifications to work with the default app configuration.
And to make it more user-friendly I added an Apache Ant build.xml script to simplify some common tasks.
First, install Apache Ant. If you’re running a Mac or Linux you probably already have it. Then download or clone the repot and go into the “app/project” directory using terminal or a command prompt. Type ant setup and it should download and install all the extensions needed to run tipfy (takes a few minutes).
After that’s done you can type ant compile-publish and the script will create a publish directory, minify your css and js scripts, optimize your images (if you have optipng and jpegtran installed), compile your templates, and leave you with a publish directory that you can upload to App Engine. Pre-compiling templates is usually an optional step that speeds up page rendering. Normally templates are dynamically compiled when they are viewed.
You can also type ant deploy-publish and it will do all of the above AND upload it to App Engine (after prompting you for email and password). Note: don’t make any changes you want to keep in the publish directory. It gets deleted and recreated every time you run “deploy-publish”.
ant deploy-dev will just upload the working app directory, without any minification or compilation.
In “build/config” there are a couple of property files that you can use to customize the behavior of the build scripts. Should be self explanatory, but might require some experimentation. Paul Irish has a video walkthrough of the build script that explains what it does and some of what these config files can do.
If you’ve been curious about App Engine, or Python web development, I highly recommend tipfy.
Page 1 of 2