Unity3D Scaling GUI With Aspect Ratio & Size

Unity3D is a great tool and I’ve been very fortunate to have such a great product to build this game on.  Everyone knows that the Unity GUI tools are a little frustrating to work with though.  One of the issues is the GUI’s size.  The next is making sure it works with all aspect ratios.  Since unity allows us to release to PC, Mac, iOS, and android it’s pretty obvious how this can get annoying quickly.  So to help others, here is how I solved these issues.

Creating the GUI 
When starting off the best way to design the anything with Unity GUI is to hard code the values at whatever resolution you are currently working in.  Keep it consistent and you will have perfectly usable interface in no time.  Here are some helpful links for the Unity GUI:

Scaling the GUI with screen height & width
The easiest way to scale your GUI with different sized screens is to use Unity’s GUI Matrix.  This matrix allows you to hard code the size of your GUI, and will automatically stretch or shrink your GUI to match the users actual resolution.

//set up scaling 
//The native_width & height are the resolutions you have hard coded
float resX = Screen.width / native_width; 
float resY = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));

This works great, but if the aspect ratio changes then your GUI will be stretched to match it.

Scaling the GUI with Aspect Ratios
To get around this limitation we have to take a more manual approach.  We scale the GUI with the Height of the screen.  By using the height to scale the interface you won’t be able to hard code any values, all of the hieghts and widths will be derived from a fraction of your screen.height.
We decided that our interface should take up about 1/5 of the screen height so that has become our unit of measurement.  So you’ll want to declare a variable with this size in it, we’ll call this variable guiBaseUnit.
Our minimap on the left side of the screen is square, so it’s height and width are both set to guiBaseUnit.
Our control panel features all of our controls, so it’s a larger rectangle that uses a lot of screen space.  So it’s height is guiBaseUnit, but it’s width is guiBaseUnit * 2.5.

This is probably not the cleanest way to create the GUI, but it does create a better user experience and creates a reusable interface system.

 

RTS Combat System

I think a lot about what I want out of a combat system in my RTS games.  I love hard counters, but I feel most games use them incorrectly.  A rock should smash the scissors, but that rock should see some scratches along the way.

Our system has four types of normal damage.  They are Cut, Bash, Stab, and Wreck.  Depending on what type of armor they are attacking they can get a damage bonus of up to 50%, making it very important to pay attention to your offense and defense.

We have three types of armor.  They are Light, Heavy, and Construct.  I didn’t want to focus on what exactly a unit is wearing, so instead we focus on easy to see and understand.  Characters are designed with the idea of no middle grounds so it’s easy to know their armor type at first glance.

The balance between the damages and the armors are split up on usefulness.  If something is very good against one type it gets nothing against others, but some weapon types are useful against multiple types.

Armor VS Weapons—–Light—Heavy—Construct
———————Cut——150%—-100%——100%
——————-Bash——100%—-125%——125%
——————–Stab——125%—-125%——100%
—————–Wreck——100%—-100%——150%

These bonuses are simple, clear cut and consistent.  So the major rules are as follows:

  • Cut up the light armor
  • Bash the thick armors
  • Stab the living units
  • Wreck the buildings and Gears
Oh, but you don’t know what Gears are yet…  Maybe next week…  Until then here is some old video footage of combat.

 

We Call Them Slek

These are the approved concept images of the slek. A race of intelligent creatures for our game Cairn. They are savage in appearance, but aren’t as ferocious as they seem. Some slek undergo a binding with another organism, a sort of symbiotic relationship that creates some pretty bad ass units.
We’re not sure how strongly the slek will be featured in our first release of Cairn, but they’re awesome, so I thought I would share.

Shifting to Second Gear

So we’ve been pretty quiet, which is always boring. I got tired of keeping up with the weekly task lists. I find that I spend too much time managing those when I could be writing lore or working on mechanics. So we’re going to try to do more in depth works in progress snap shots.

We have a ton of art work, Rodrigo has been powering through unit concepts and sprite designs. I posted one of his older ones a few weeks ago, so expect lots more.

We have a new sound guy who is wrapping up the first of our official tracks. We’ll be sharing that soon.

We are going to open our alpha builds to anyone who wants to play around with them. There isn’t much too do for players, but perhaps you’ll have fun finding all of my mistakes.

We also have a wikia going live soon. It will be full of information about our units and the world.

Our unique visitors to the website is slowly climbing. I like to think that means people are reading these posts.
My favorite search terms that have led people are are:
“Failed Embalming”
“Does embalming last forever”

The First Sovereign

The Praetorian
Praetorians are the most respected of leaders in all the Thermocrat army. Given command of state of the art equipment they are held to a very high standard and many collapse under the pressures of their responsibility.
White hot flames burst from crevices of their Lorica armor, few opponents can handle the immense amount of heat pouring from a Praetorian. Their short swords licked by alchemical fires possess the ability to slash and burn through any enemy troops.

The Wheels of Progress Keep On Turning

Here is something I haven’t done in a little while. A snapshot of the things we’ve completed since the last update. So from Oct until now, this is where we are.

3/7/2012
Adam

  • Create Player Object & Move Current GOs under it
  • Create new Unit Model & Unit Prefab
  • Switch to Unity3D built in Path finding
  • Unit Selection Model
  • Unit Selection Controller
  • Redo GUI (Force click down and release for GUI pieces)
  • Select the First 20 Units to be drawn out
  • QA Point Calculator for Units Recruitment
  • Iso Camera
  • Unit formations
  • Unit AI

Rodrigo

  • GUI Layout
  • Kajarii Concepts
  • Slek Concepts
  • Arcole Concepts
  • Dukarim Concepts
  • Launch-able Items
  • Framework Sprite

We have lost the entire engine, restored it, and surpassed it. Rodrigo has gone from concept artist to helping me stand up an entire fictional world. I have gone struggling to understand how scripts interact to spawning an arrow that arcs, deals damage, and triggers a damage effect on the hit unit.

We’ve come pretty far in the last 5 months. Far enough that next week I’m releasing an Alpha. I think that in 5 more we may have something to sell.

On Your Best Behavior

So this is our first behavior engine release. Any RTS has to have some dynamic AI that acts and reacts to opponent actions. This is our take on these actions.

You’ll notice that I talk about moods for each unit, this is scratching the surface of our “Stance” system. Each troop of units has 6 different stances they can activate, each stance offers different behavior logic and different stat bonuses.

Guard & Hold Position will offer an armor bonuses which is good against Normal Attacks.

Attack & Rampage will offer bonuses to all types of damage.

Evade & Route grants a movement speed increase.

January Week 3 Work

The project continues.

Adam -

I have been working on recovering from a technical mishap where I deleted a large chunk of the source code while trying to integrate with our new path finding solution.  Other than that work is now moving forward again.  Unity 3.5 pathfinding is being integrated with our selection, formations and basic game objects.

Rodrigo -

Cranking out some great concept art and working on some sprite tests.