Taming Unity

logo

For the last couple of months I have been working on a few different things including many new releases of Post To Tumblr. Most of my time however has been spent working on an unnamed (as of yet) game in Unity.

Its my first time using Unity, having come from a predominantly Flash games background I was excited to have the power of C# with a WYSIWYG editor for rapid iterations, and indeed I did make rapid progress. I soon had a working gameplay prototype up and running and everything and everything was hunky dory. It worked but the code was far from pretty with dependencies between my components all over the place not to mention the headaches when I tried to introduce Unit Testing into the mix.

The game I am developing is a turn based strategy with some complex gameplay rules, perfectly suited to unit testing I thought. Unfortunately however the power of Unity’s rapid development is also its downfall. It allows you to do some pretty nasty things. It also uses a vast number of statics and singletons making testing rather tricky. I managed to muddle my way through things using Unity’s recently released Unit Testing Tools however things were far from ideal.

The main issues were dependency hell and Managers. Unity seems to recommend “Managers” as a way to look after various parts of game logic. You create an empty game object then attach a manager component to it then reference that manager from anywhere. Seems okay (though there are numerous problems with this particularly when it comes to changing scenes) however the big problem is how to reference that manager from your components?

The method I was using was in the Awake() I would use GameObject.FindObjectOfType(); then cache the result and use it. Fair enough but this still means I have a dependency in this component on the Manager. It also makes Unit Testing very hard because there is no way to pass in a mock Manager. A stopgap solution was to use constructors to pass in the manager:

private MyManager _manager;
public MyClass(MyManager <span class="hiddenGrammarError" pre="">manager)
{
_manager</span> = manager;
}

void Awake()
{
if(_manager==null) _manager = GameObject.FindObjectOfType();
}

Still we have the dependency there however and my code was starting to get more and more complex. Plus Unity doesn’t really like you instantiating MonoBehaviours using constructors so I would continually get warnings in my tests. Far from ideal, so I decided to go looking for an alternative.

In the past I have worked a great deal with the Robotlegs framework and knew it was designed specifically to help with clear separation of use and help with managing dependencies for easy unit testing. So I wondered if anyone had ported Robotlegs to Unity. Well I was very happy to discover someone had and had done a good job of it in the form of Strange IoC.

Strange is an MVCS framework very similar to Robotlegs so if you know Robotlegs you should be swimming. I wont go into the details of MVCS, checkout the documentation or the Robotlegs documentation if you want to know more.

Using Strange I was able to replace the dependencies in my components by converting most my components into “Views” which respond by displaying data and then dispatching signals which the rest of the application picks up in Commands and and updates the Models or uses Services to communicate with the database. It immediately made my code much more testable by removing many of the dependencies between my components. At the same time I was able to convert many of my Models and other “Manager” like classes to implement Interfaces which made my code much more portable should I choose to change parts or reuse bits in future projects.

A disclaimer is that I have only used it for my menu systems and multiplayer services so far as thats what MVCS is ideally suited for and haven’t converted my spaghetti game logic over to it yet so cant comment on it just yet. My main worry is that it may slow down the enjoyment of rapid iteration and development. I will have to think carefully about that as I go forward.

Mike Goes Down Under

CropperCapture[1]

Last May I took off on a journey of a life time to the Americas. In 8.5 months I visited 16 countries. Along the way I had the good fortune of meeting a special lady. We travelled together for 5 months, virtually every second of every single day was spent together.

So I was surprised when she invited me to come live with her in Australia. She must be mad I thought to myself. Still, I had better go over there and find out if she has actually lost it.

Well guess its fortunate that Australia is the top of my "to visit" list. So I thought to myself what better way to check out this huge continent than with a beautiful, smart and funny lady who I guess is partly insane too.

As for what ill be working on while im over there, I have some freelance work lined up but my real passion is games so I plan on working on an indie game or two while im out there. Thats until the remaining of my saving last and I have to get a job or more likely she finally gets fed up of me and sends me back to England!

Post To Tumblr v.4

While I was travelling I have had a great many people contact me about my popular chrome extension Post To Tumblr. Some wanted me to fix things some wanted me to add things others wanted to buy the extension outright.

Well I didn’t have time to do any of those things while I was away so put it off until I returned home. Well I have been back now for a few weeks and have decided to spend quite a bit of time upgrading the extension.

Unfortunately my time isnt free now that I am working freelance and so I need to justify the time spent working on the extension. So I need a way to monetize the app. There are quite a few ways to do it and I couldn’t decide which to go for so I surveyed my users.

screenshot_0116

The results were interesting:

screenshot_0220

If you take the results on face value it looks as if people didnt mind ad injection but I suspect that they misunderstood the meaning of what ad injection was and thought I just meant adverts. I decided that ad injection was a little too evil for me and decided to go with making the donation more prominent.

To do this I rewrote the entire app using Typescript with KnockoutJS and then make the donations front and center. When a user opens the window they are presented with a popup that informs them about all the new features and improvements and gives them an opportunity to donate:

screenshot_0117

From there they are taken to the donate tab of the options that lets them quickly and easily donate.

screenshot_0222

I decided to set the minimum donation amount to $3 which is about the price of a cup of tea in Starbucks.

As an incentive I have locked certain features such as the advanced 1-click process and a suggestion submission feature:

screenshot_045

I also have promised new features coming soon which donors will have access to:

screenshot_056

On the whole people have responded well to the changes however there have unfortunately been some negative reviews from people on the chrome web store.

The negative reviews regarding me asking for donations sadden me. I don’t think people understand that I need to justify my time spent on the extension. When Tumblr change their API I have to spend days working out why. This is time I could be spending doing freelance work.

The amount I ask for is about what you would pay for a mobile app and people don’t seem to complain when purchasing those. Unfortunately this just seems to be the way things are on the Chrome Web Store, people expect things to be free.

I have tried hard not to be evil with this release, I could have made much more money by either implementing ad injection or selling to an ad injection company, instead I have worked hard to fix and improve things in a clean and non intrusive way. I just wish I could make the negative reviewers understand that.