Customizable Navigation Bar

Friday, August 30, 2013

Extension Methods In Unity

As a Unity developer, the ability to use C# for scripting allows for some of the great features that come with it. This includes extension methods. Extension methods allow for extensions to classes that already exist, and keep your code nice and clean, so I wanted to go into them with a little detail today.

So what is an extension method? And what advantages and disadvantages does it have?

MSDN states that "Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type". Couldn't say it better myself. Extension methods are basically syntactic sugar, allowing to you call your own methods from a class such as GameObject, or string, as if they were always a part of the class. This gives your code a much cleaner look.

There are a few disadvantages to using extension methods though, you can't just have the cake and eat it too.

  1. One of the disadvantages of extension methods is that you cannot create static methods for a class. Every extension method you create will be instance based. This is because extension methods are already a special type of static method, and the first parameter of the extension method is the instance of the object you are calling it on, so there is no way to get a static method out of it. You will see what I mean later when I show you some examples.
  2. Another disadvantage is that you cannot have extension properties, indexers, operators or constructors. So while you get the convenience of adding additional methods to a class, you still need to define a new class if you want extra properties, indexers or constructors.
  3. Reflection doesn't know what you are talking about. As I said before, extension methods are just syntactic sugar, so extension methods aren't actually a part of the class the method applies to. You can still technically call your extension methods from reflection, but you need to do some searching through your assemblies and the attributes applied to the methods.
  4. Extension methods will not take the place of functions that are already defined. If you came up with a better way find something in a list, you can't just create an extension method with the exact same name and parameters. The compiler will look at the already defined methods before it looks at the extension methods, so if you have a method that is faster or better than the already defined method, just call it something similar that you will remember.
So what does an extension method look like anyways? 

The first example I am going to show you is an extension of the Transform class in Unity. The transform class defines a method called transform.Find(), where you pass in a path to the child transform you are looking for. An example of this would be transform.Find("arm/hand/finger");

Sometimes this method is a little finicky, and you also need to know what the path is beforehand, so if anything changes in the hierarchy, you have to edit your code and recompile. I'm not a fan of this, so I wrote an extension method for Transform, called Transform.Search(). All you need to do is pass in the name of the child you are looking for, and it will return it if it find it, or it will return null if the name passed does not exist in the hierarchy.


//The first thing you want to do is define a static class. We will call this class TransformExtension
public static class TransformExtension
{

//Next we will create a static method, and this is the extension method that will be applied to the Transform class. We will call this method Search. Pay attention to the parameters of this method, especially the first one.  

public static Transform Search(this Transform transform, string name)
{
//The first parameter passed has the 'this' keyword, and the type of the class that this extension method applies to. This is so the compiler knows which instance of the class the extension method is being applied to.

  //Now we fill out the method as we normally do

  //its faster to compare two ints than it is to compare two strings, so we compare the length first, then check the string if the lengths are the same, if this is the transform just return it
  if(transform.name.Length == name.Length)
  {
    if(transform.name == name)
    {
      return transform;
    }
  }
        
//do the same for the children
for(int i = 0; i < transform.childCount; ++i)
{

//this function is also recursive, so we just call search through this child as well
  Transform result = Search(transform.GetChild(i), name);

  if(result != null)
  {
    return result;
  }
}

return null;
}
}

And that's it! Now you have a quick and much simpler way to search through your transform for a child.

Extension methods also work on generic classes as well. So you can provide extension methods for classes such as List<String>.

//remember to create a static class
public static class StringListExtension
{

//Static method that returns true or false if the list contains the string passed. Remember that the first parameter is the keyword 'this', and the type that this extension method applies to.
public static bool fastContains (this List<string> list, string name)
{

  for (int i = 0, iMax = list.Count, nameLength = name.Length; i < iMax; i++)
  {

    //Checking two ints is faster than checking two strings, so we check the length first
    if (list [i].Length == nameLength)
    {
      //if the length of the string is the same, then compare the two strings together to see if they are the same
      if (list [i] == name)
      {
        return true;
      }
    }
  }

return false;
}
}

And that's it! If you want to use this extension method, its as simple as stringlist.fastContains(stringvalue); and it will return true or false if the list contains the string passed.

These two examples are just some of the many ways that extension methods can be used. They offer a clean way to add functionality to classes that are already existing, and who knows maybe in the future we will get some extra functionality to them. I personally wouldn't mind seeing extension properties or constructors in the future.

That's all for now though, so good luck with your projects!

Friday, August 23, 2013

Developing On A Budget

As an independent developer, finding the right tools to do your job without breaking the bank can be a very stressful experience. Everywhere you go you see subscription fees, license fees, parking fees, and it can be really difficult to determine whether or not these products are worth the cost, and how much time you would have to dedicate if you were to avoid these products altogether.

Well have no fear, for I am here! With a list of the programs and products that I use, and LoneWolfPack Interactive uses on a daily basis. We have not had to pay a dime for any of these programs, and without them we wouldn't be where we are today. These range from project management, to asset creation, and I will be running through the list on all of them.


Project Management

Getting yourself organized can be a very tedious process. Sometimes you just don't know where to start and what is available for you to use. Here is a list of programs and services that will make organizing and managing yourself a lot easier, without breaking the bank.

BitBucket - https://bitbucket.org/



BitBucket is a service that offers unlimited private code repositories, allowing you to collaborate and manage your code using Git or Mercurial. If you have teams of 5 or less, you can use BitBucket completely free of charge, which is perfect for small teams of developers looking for a place to host their code repositories.

On top of being able to host your code, BitBucket also has a very basic issue tracker, the ability to create a wiki for your projects, and has a services feature, which allows you integrate plugins for other services such as Twitter, Fogbugz, Basecamp and many more.

If you are looking for a very inexpensive(free) way to host code repositories, BitBucket is definitely the way to go.

Costs:
Up to 5 users: FREE

Up to 10 users: $10/month
Up to 25 users:$25/month
Up to 50 users:$50/month
Up to 100 users:$100/month
Unlimited users:$200/month


Google Drive - http://www.google.com/drive




Google is slowly taking over the internet, offering services that would normally cost money for absolutely nothing. One of the most handy services that this evil company offers is Google Drive.

Google drive allows you do create word documents, excel documents, power points, and basically anything else you can get from a basic Microsoft Office suite, and it allows you to edit and manipulate your documents in real time with your team. This feature is extremely handy when you are fleshing ideas out or going over your GDD and asset list. Now everyone that takes part in design can take their own section of a document, provide feedback as someone is filling in details, and troll each other while they are trying to get work done.

Plus once you have finished up your documents, if you need to mail them out, you can save them as common formats such as PDFs, Word/Excel documents and even OpenOffice documents.

If that's not enough, there are even extensions for Google Drive that allow you to create things like Gantt charts and many other handy tools to help organize and speed your process up. If you are on the go, grab the Google Drive app for your phone or tablet, and you can edit and collaborate on the move.

If you are looking for an inexpensive alternative to Office365 or some other office tools program, Google Drive is the way to go. For the massive cost of free, the ability to collaborate, edit on the move, and create/install extensions is extremely handy and is definitely worth checking out.

Costs: 
15 GB of Storage: FREE

100 GB of Storage: 4.99/month
200 GB of Storage: 9.99/month
400 GB of Storage: 19.99/month
1 TB of Storage: 49.99/month
2 TB of Storage: 99.99/month
4 TB of Storage: 199.99/month
8 TB of Storage: 399.99/month
16 TB of Storage: 799.99/month


Dropbox - https://www.dropbox.com/




Dropbox has picked up a lot of steam in the last few years, and for good reason, it is an extremely useful tool. The ability to drag a file into your Dropbox folder and have it automatically download to everyone that shares that folder saves more time than you can imagine. Does your artist have a new concept that he wants everyone to see? Just toss it on the Dropbox. Was there an update to an animation for one of your characters? Just toss it on the Dropbox. Did you just create a new build of your tablet game? Toss it on the Dropbox, and then everyone can open up the Dropbox app on their tablet and install it right from there.

If you are using Dropbox for free, you are somewhat limited in space. You start with a maximum of 2GB of storage, but if you invite a friend and they download and install Dropbox, you get an extra 500MB of space, up to a maximum of 16GB (18GB in total). So if 2GB of space isn't enough for you, just shoot an email to your friends, and watch your space grow.

For the low low price of free, this tool is extremely useful. Even if you don't transfer assets back and forth with it, just being able to toss an Android build on it and install it straight to everyone's device is worth checking it out.

Costs: 

2GB of space (Up to 18GB) : FREE

Pro
100 GB of space: $9.99/month or $99.00/year
200 GB of space: $19.99/month or $199.00/year
500 GB of space: $49.99/month or $499.00/year

Business
Unlimited Space: $795/year for 5 users, $125/year for each additional user


TortoiseHg - http://tortoisehg.bitbucket.org/




At LoneWolfPack Interactive, and for my own personal projects, Mercurial is used for version control. While command line is pretty awesome in some cases, none of us were around during the DOS ages, so we like a clicky interface, with buttons and pretty graphics. This is where TortoiseHg comes in. TortoiseHg is a shell extension for Mercurial, that provides context menus and icons in your file explorer. It also comes with merge tools, a workbench for viewing your repository in detail, and a bunch of other windows that make it much easier to add commit messages, ignore files and a whole ton more.

If you are a Mercurial user, TortoiseHg is a great tool. For the low price of free, this open source tool is great for everyone that uses Mercurial for version control, and if you are a source code kind of guy like me, you can grab the source and look through it if you want to.

Cost: FREE


Trello - https://trello.com/



Trello is a new service that I was recently pointed to. Basically what it is, is a task list service that allows you to create tasks in detail, assign them to people, assign deadlines, and click and drag them to the appropriate task list.

Trello makes creating your to-do lists much easier and more organized. It also provides you with online collaboration with everyone in your project, so everyone can fill out task cards, check off the competed tasks, and assign work to each other in real time. It is an extremely simple service, but it is pretty cool and handy to have around.

I think you guys are probably noticing the pattern here, because Trello is also free to use.

Costs:

Basic: FREE
Business Class: $25/month or $200/year


Asset Creation


Asset creation on a budget can be daunting. There are many horror stories from people using free programs, and there are just as many horror stories from people who spend the big bucks. So where do you go? What products do you use if you are trying to save a few pennies? The programs listed here will provide you with a very solid base to create your assets and make your games.


Blender - http://www.blender.org/




Blender has had a bad rap for it's learning curve. Moving from Maya or 3DSMax to Blender has always thrown people for a loop, and it isn't used as often as the other "standard" 3D modelling programs in the industry.

As a programmer, any art tool is going to throw me off, but I have to say that when I opened and started using Blender, it was expecting way worse, and after about an hour or so I preferred blender over Max and Maya. My biggest problem with Blender was its default control scheme for moving the camera around with the mouse. After 10 minutes I figured out where the keyboard preferences were, I changed them so that I could control the camera like you do in Maya or Unity, and Blender was like a whole new program. It was as easy to get the hang of as Maya, but had as many shortcuts and tools as 3DS Max did (Boy did I ever miss the modifier list when I started using Maya).

Another benefit that Blender has is that it is open source, so you if there are any bugs in the software, they are usually ironed out in a few weeks or so. It's pretty amazing that you can have better customer support and updates from a free open source program than you do from a $3000 program like Maya or 3DS Max. Also like I mentioned with a previous program, I am a source code kind of guy, so I think it's great to be able to download the source and look through it if I get curious.

I think that if Blender really was that bad, and the interface wasn't very user friendly, the issues have been fixed and it deserves another try.

Cost: FREE (But you can donate to the developers)


GIMP - http://www.gimp.org/




GIMP is the open source alternative to Photoshop. It isn't as user friendly as Photoshop, and it doesn't come with as many built in plugins and brushes as photoshop, but once you get used to the interface, and download a few plugins from the plugin database, you'll never really need photoshop again.

It has an interesting layout, where the toolbox and other windows are floating, and that takes some getting used to, but once you get past the odd layout, the program isn't half bad. It's fast, it's light, and its open source for the code curious. GIMP also allows you to export your images as a ton of different formats like any image editing program should. In general it is just a solid alternative to Photoshop, much better than a lot of the others out there. I'm looking at you Paint.Net.

Cost: FREE (But you can donate to the developers)


Audacity - http://audacity.sourceforge.net/



Audacity is a very basic audio editing tool. Out of the box it provides you with the tools to clip, stretch, and manipulate audio files. It also comes with a few basic filters that you can apply to your audio, giving them basic reverb and effects to improve your sound.

I think one of Audacity's strong points is the ability to import VST effects, so if you have purchased or downloaded any free VSTs, you can drag them into the Audacity plugins folder and get access to your favourite effects. Audacity is by no means a replacement for something like Logic Pro or Adobe Audition, but if you need something to quickly trim dead noise, or just need something for very basic audio editing, Audacity will be perfect for you. Plus it's open source, so that's a bonus too.

Cost: FREE (But you can donate to the developers)


Unity - http://unity3d.com/



And then there is Unity. It took about 11 minutes for me to get hooked on Unity, after having a not so pleasant experience with the UDK. 

Unity offers a free version to all developers, which basically strips out features such as occlusion culling, static batching, and the profiler, and depending on who you ask, those three on their own are worth the pro license. The Unity engine allows for extremely easy customization of the editor, and basically everything is drag and drop to attach components to object. You can use three different languages to program in, which are C#, Javascript and Boo(which is something like Python). 

On top of being easy to develop for, you can distribute it to multiple platforms at a touch of a button. If you want to see if your PC game translates to a tablet, fiddle with the settings and build it to see. About a month before this post Unity made the basic mobile licenses free to use, so now you can develop for iOS and Android for free (other than the one time fees associated with the Apple and Google developer accounts of course).

I could rant and rave about Unity all day, but at the end of it all, just try it out. It's free, and as long as you don't make more than $100,000, you can make as many games and sell them without having to worry about Unity asking for a few bucks.

Costs:

Unity Basic (Comes with basic mobile licenses): FREE
Unity Pro: $1500
iOS Pro: $1500
Android Pro: $1500
BlackBerry 10 Pro: $1500
Team License: $500 (Team license allows for collaboration so multiple people can edit the same level and see the changes in real time)


So all in all, you can see that there are plenty of options available that allow for free/extremely inexpensive development. Stick with open source where you can, and don't be afraid to look around for an alternative to a paid program, because you just might be surprised at how functional and how easy they are to get the hang of. 

That's all for today! Try not to spend too much time counting all of the money you saved! And don't forget to point people to this article if you enjoyed it!

Friday, August 16, 2013

Blog Reconstruction and Activity

Hey everyone, it has been a while, and I'm tired of saying that every time I post something here. So things are going to change, and I am going to become much more active over the next little while.

As I had said in a post a few months ago, a few friends and I had created a indie game company called LoneWolfPack Interactive. Currently we've created two games on the Android marketplace called President 3D and CuBlitz.

There has been a lot a stuff going on lately, whether it is business related or development related, and I have decided that I am going to start talking about being an independent developer and the pros and cons about it. While we are developing our newest games and tools I will be tossing up articles and cool little tidbits of information about our games, our development process and any cool and useful scripts I create to help move things along.

On top of that, I am also going to be putting some fun stuff up here as well. As people who create games, we also like to play them, so you may see some of our let's play videos posted here as well.

The whole point of what I am doing is so that you can experience what I experience, develop along side me and have fun the whole time.

Anyways, back to it I suppose, I am currently prototyping our newest project, and I said I would have a playable version tonight. Fingers crossed!