Saturday 21 December 2013

Unity Input Manager

It has not taken me long to come across one of the minor shortcomings of Unity, the InputManager.

It is very simplistic and apparently it cannot be changed at runtime or at least not after the initial Unity provided options screen!

http://docs.unity3d.com/Documentation/Manual/Input.html

I think players of computer games should have some flexibility to customise their controls for a game and it should be easy to do even on the PC not just on Consoles.    Not all games need this but first person shooters and similar, do, in my opinion.

Yes, Unity provides some customisation but it is not very user friendly.

I've started to write my own screens and am researching alternate input methods so that I can change this in my own, more user friendly, menus.

This is a list of some of the information, samples and assets I have found:
This is the sort of thing I want but I don't need everything: http://cinput2.weebly.com/index.html
The demo for CInput is useful for finding the Axes used by gamepads: http://cinput2.weebly.com/demo.html
This free project supports Ouya and others at the level I need: https://github.com/pbhogan/InControl
Edit 16 Dec 2014: A project with the same name is now on the Asset Store: https://www.assetstore.unity3d.com/en/#!/content/14695

Monday 16 December 2013

Unity Gotcha - What's in a name?

I like my folder structure in any project to be tidy and understandable. 

Cosmetically I find it odd to have folders in folders with the same name.  For example a Materials folder inside another folder called Materials.

I tidied up my folders and used the name 'Resources' to put all my assets in, within that I have Materials, Textures etc.  I thought it sounded like a good name to use.

 


Bad idea!  Folders called 'Resources' have a special meaning in Unity!

Anything in a folder with that name anywhere in the project folder tree will get compiled in to the game build even if the assets within it are never used in the game!

Everything in any other folder name only gets included in the build if it is used somewhere.

Luckily I spotted this before I had gone too far and can move everything to a folder with another name, like 'Content'.

Now I know that some folders have special meanings, I will be more carefull in the future.

Sunday 15 December 2013

Unity Code Naming Conventions

I did a quick bit of searching to find out what naming conventions were used.  It turns out that there isn't really one.

http://forum.unity3d.com/threads/135617-C-naming-conventions-for-Unity
http://answers.unity3d.com/questions/10571/where-are-the-rules-of-capitalization-documented.html

Unity supports three programming languages.  I'll ignore Boo because I know nothing about it and there are few samples.   Most of Unity's older code base is in UnityScript.  That has a very similar syntax to JavaScript.  In the UnityScript code base the only convention is that class and function names are in PascalCase and variables are in camelCase starting with a lowercase letter.

C# appears to becoming very popular with Unity developers, if not the dominant language but as the syntax is similar most people can mix and match if needed.

As C# is a Microsoft language many people have adopted the Microsoft guidelines for the use of case when  working in Unity.  I also prefer those naming conventions for case, they are:
PascalCase for public and protected properties and fields and camelCase for private properties and fields with PascalCase for all methods independent of if they are private, public or static etc.

The case is only significant for public or protected elements so that non-case sensitive languages can always reliably access them:

public Method(parameter)
protected Method(parameter)
private Method(parameter)
public Property
protected Property
private property
public Field
protected Field
private field

Some people like to use an underscore in front of _camelCase for private fields but that is their personal preference and appears to go against the recommendations in some of Microsoft's guidelines.  Again, that is only significant for public fields, what you use privately is just for readability of the code.


Saturday 14 December 2013

Texture Quality

My first hurdle with Unity was understanding texture importing and displaying them in 2D.

Unity is very scene based.  Many games and most tutorials put all the options within the player controller of the scene.  I find this very odd.

I wanted to start with a menu, the sort of thing virtually all commercial games have and using that menu select the game options and launch the desired level.

That was not too difficult.  What has delayed me for the best part of an hour is texture quality.  I wanted a good quality logo. 



I kept getting a horrid artefact ridden blur!



Every setting I tried with the texture type set to 'Texture' resulted in the same reduced image.  It turns out that I need to use the 'GUI' texture type with a format of 'Truecolor' to avoid the texture being compressed and resized when it is imported. 


You drag the texture in to any folder, as you do with most assets and then change the settings.  Remember to press 'Apply' to see your changes.



Those settings conveniently led me to the 'GUI Texture' and 'GUI Text' objects that are probably better for me to use to create my menus.

Monday 9 December 2013

Unity Startup

As I am new to Unity I thought it was worth noting down any observations I have as I go.  Once you become familiar with any development environment you, or at least I, tend to forget how difficult it was to find my way round when I first started.

By default Unity starts with the last project opened.

While experimenting I have found myself swapping between projects to look at different features.  It is therefore more convenient for me to select the project I want to open when I start Unity.


I want the Project Wizard to be the first screen I see.  It is easy to change in the Edit->Preferences form.


Enable 'Always Show Project Wizard.'

From then on Unity will start by asking you which project to open.

Friday 6 December 2013

Unity 3D SVN Setup and Usage

I have just started to create projects for Unity 3D to try things out.

I use Subversion (SVN) for my code storage and wanted to do the same with my Unity projects.  Luckily I had been doing lots of reading so had already come across the fact that unlike code based projects Unity needs a few changes to support using SVN.

The changes are very minor but important.  These include some useful reminders detailing what to do:
http://docs.unity3d.com/Documentation/Manual/ExternalVersionControlSystemSupport.html
http://blog.teamthinklabs.com/index.php/2012/04/11/unity-3-5-and-svn-now-easy-and-free-for-all/

Most of the guides mention using Meta-files.  Version 4 of Unity has two settings, hidden meta files or visible meta files.  I took them to mean use 'Visible' Meta Files' for SVN.

Edit -> Project Settings -> Editor...  Mode = Visible Meta Files

There are also Unity add-ins for helping with this but having everything in one intergated development environment (IDE) is not something I have ever worried about so I did not look in to any of those add-ins.

I use TortoiseSVN, and to make things easier I use the Ignore list to stop the Library folder showing up as missing.  That folder does not need to be stored with the source code because it is a local cache and will be rebuilt as needed.



Do not select the 'Library(recursive)' option because you may want to use the name 'Library' elsewhere in your repository.

 

I use the 'Check for Modifications' feature to make sure I commit any changes I make within the project:


When using SVN with Unity do NOT rename folders either in Unity nor with SVN.  Renaming in either case messes up the other

The simple solution is to always create a new folder in Unity and move the assets from the old folder to the new folder within Unity.  You can then delete the empty folder in Unity.  Add the new folder from your SVN client and commit the project.

 


You can delete or move assets within Unity it is just renaming folders that has a problem because the meta-data for either SVN or Unity is not updated by the other.

Although it it not tidy, missing folders and files can be marked as deleted when you commit your changes to the SVN repository.

Any missing items must be marked to be included in the commit before you do an Update.  If you do an SVN update before marking the missing items then those items will be restored from the repository.


Tortoise SVN has a convenient link to mark all missing items as deleted.

There are other ways to do the same things and here is another article on the same subject.