Archive for the ‘ unity ’ Category

Grouping signals in StrangeIoC

Recently I have started relearning Unity3d and because I very much enjoy DI and IoC I’m also relearning StrangeIoC. Since I’ve last looked at Strange, Signals have been added. This makes me very happy being an old AS3 dev that <3’d Robotlegs and AS3Signals.

Anywho, one “problem” with signals, that existed in flash as well, is that each signal is a class. The idea of making a 5 line class for each signal I want to dispatch irks me. My solution is an ugly one but I liked it when doing flash and so far like it here as well.

namespace ca.openbracket.signals{
    public class StartSignal:Signal{}
    public class TestSignal:Signal{}
}

What I like about this approach is that I can group my related signals into a single file and see them all.  The two big drawbacks are searching for a signal can be difficult if you aren’t accustomed to this and you don’t get more granulated version control details.

Is this worth it? I have no idea. But it makes me happy.

StrangeIoC

Moving from Actionscript to Unity one of the things I missed the most was a framework like Robotlegs that has been the base for any as3 project I’ve done in the last year or two. Recently a buddy at work discovered StrangeIoC and I must say, it is awesome.  If you haven’t used and IoC framework before you should really check it out.

Anyways, if you are familiar with Robotlegs then this is definitely for you since the API is very similar. So similar in fact that a guide for RL users exists!

Give it a shot. It’s bloody awesome

Unity development – 3rd party tools I couldn’t live without

For the last few months, I have primarily been doing only Unity work and have come to rely on a few third party tools every day:

RageSpline

http://ragespline.com/

  • Generate 2D vector graphics inside Unity Editor with bézier splines
  • Fully adjustable colors and gradients + emboss styling
  • Multi-texturing with easy texture positioning
  • Automatic physics collider generation with BoxCollider and MeshCollider options
  • Adjustable vertex count for visuals and physics.
  • Grid & snapping gizmo for accurate drawing
  • Good peformance on iOS/Android
  • RageSpline API for run-time code access

2dToolKit

http://www.unikronsoftware.com/2dtoolkit/

2D Toolkit provides an efficient and flexible 2D sprite and text system which integrates seamlessly into the Unity environment. Our key focus with this product is mobile performance and workflow efficiency.

2D Toolkit is designed for rapid prototyping, and is built to take you all the way to a shipping game.

NGUI

http://www.tasharen.com/?page_id=140

NGUI is a powerful UI system and event notification framework for Unity (both Pro and Free) written in C# that closely follows the KISS principle. It features clean code and simple, minimalistic approach to everything. Most classes are kept under 200 lines of code. For a programmer this means a much easier time when it comes to working with the kit — from extending its functionality to tweaking the existing one. For everyone else this means better performance, less frustration, and more fun.

Bonus! Playmaker

http://www.hutonggames.com/

This is possibly the most powerful tool I have used to date in Unity, but I haven’t been able to explore it as fully I would like to. In short, it’s a FSM that can easily hook into all aspects of your application. It allows the developer to quickly and visually create easy light switches to complex AI.

JSONFX and Unity

Hey all. It’s been fucking ages since my last post, but maybe this time I’ll be able to keep this sucker going. But to hell with excuses and whatnot. On to the point!

Recently I have been working with unity to build some games at work and decided to take a crack at a 2d game for myself. One of the first things I’ve decided to do is work on the quest engine for the game. Since this is going to be a single player game I’m storing my quests in a local file. I initially tried to store this data in XML until I discovered how awful XML is in C#. I then moved over to storing my quests in JSON. After some googling I came across JsonFX and went with it since it will also work on mobile.

Looking at the examples it seem pretty straight forward so off I went. And after a little trial and error I got it at least loading and parsing the json into my unity project finally!

using UnityEngine;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text;
using JsonFx.Json;

public class FetchQuest{
	public string name;
	public int questId;
}

public class StoryQuest{
	public string name;
	public int npcId;
}

public class Quest2{
	public FetchQuest[] fetchquests;
	public StoryQuest[] storyquests;
}

public class QuestManager : MonoBehaviour {
	void Start () {
		StreamReader r = File.OpenText(Application.dataPath+"/quest.json");
	    string _info = r.ReadToEnd();
	    r.Close();
		print(_info);
		var search = JsonReader.Deserialize<Quest2>(_info);
		print(search.fetchquests[0].name);
	}
}

{
"fetchquests":
	[{"name":"test", "questId":1},
	{"name":"test", "questId":1}]
,"storyquests":
	[{"name":"story 1", "npcId":1},
	{"name":"story 2", "npcId":2}]
}

And thats loading and deserializing! This makes me happy. A thing to note and this is what caught me, is that it looks up the class variables by name, so case matters! Remember this!