Game Development Reference
In-Depth Information
Underneath you will find a Used Assets listing. Load times are affected by the size, and game
players want to get straight to playing. This means optimization can be implemented here by
removing unused assets that piled up in your project during development. Mobile users have greater
memory constraints on their devices as well as download size limitations designated by their service
providers, so app size is a consideration in their choice to purchase or download your game.
By comparing the Used Assets listing to the contents of your Assets folder, you can safely remove
any unused assets.
Scripts
Script optimization has been touched on lightly throughout the topic in references to good coding
practices, efficient code, and refactoring. There are a variety of techniques you can implement to
optimize your code. You can incorporate some of these into your standard coding practices, while
other examples demonstrate different approaches you might take while optimizing until you achieve
target performance.
Static Typing and #pragma strict
One such practice you have been following consistently but it bears more explanation now.
MonoDevelop created every script for you beginning with the line #pragma strict . This line tells the
compiler to interpret the following code “strictly,” which in turn forces you to use static typing or else
a compiler error is thrown.
Static typing refers to the typing of variables when you declare them. In the following line of code,
you explicitly declared myVariable to be of type int :
var myVariable : int = 2;
You could alternatively declare the variable as follows:
var myVariable = 2;
Unity automatically converts this to statically typed code using a method called type inference .
While this capability allows for the writing of simpler code, if the variable cannot be type-inferred
Unity will rely on dynamic typing.
In dynamic typing , Unity has to figure out what the variable type is based on the value assigned to
it. “Figuring out” takes time, and taking time affects game performance. Sticking with static typing
helps performance, while #pragma strict helps to make sure that you do.
 
Search WWH ::




Custom Search