Hi there, i thought i write a short story on how to convert an older title to unity 3. I have seen some info about that here and there in the forum, so you might have seen some tips already. But putting everything together might be helpful for some of you.
So i was trying to update lucky cats 3d iphone and iPad.
1. Depricated Code
Right after opening the older version in Unity 3 you will most likly see a whole lot of warnings about depricated code. Biggest one is about Touch. So you should change your code accordingly. For example:
var t1 : iPhoneTouch = iPhoneInput.GetTouch(0);
needs to be now:
var t1 : Touch = Input.GetTouch(0);
Note that the Type also changed. Best way to handle this is to use some Texteditor which is able to search and replace text in a directory (BBedit can do that)
2. Strict typing
Unity3 seems to be even more strict than 1.7. You might get some error Messages in XCode, when running on the device - while playing in the editor runs just fine.
I had one issue, where i had strings in an Arraylist which i combined with other Strings in a JS Script. The solution was to change Arraylist to String[ ]. Example:
fieldWords_arr = new string[2];
fieldWords_arr[0] = "field";
fieldWords_arr[1] = "fields";
3. .net2 GUIManager and Ani.Mate
Unity 3 “only” offers .net2 and that one doesn´t handle reflection it seems. So this is not really a U3 issue, it was the same in 1.7 when using .net2. In case you used GUI Manager and did some animations, thats also failing on the device.
My solution was to change all the tweens to iTween. That was quite a lot of work. But you can do it, even animation Chaining and Loops. Most often you need to use iTween.valueTo. Example of tweening a QuadObject:
// 1. Nummer einblenden…
void startYourAnimation() {
Hashtable tweenColorHash = new Hashtable();
tweenColorHash.Add("from", thisObj.Tint);
tweenColorHash.Add("to", trans);
tweenColorHash.Add("time", 1.2f);
tweenColorHash.Add("easetype","easeOutSine");
tweenColorHash.Add("onUpdate","tweenColorValue");
iTween.ValueTo(gameObject, tweenColorHash);
Hashtable tweenScaleHash = new Hashtable();
tweenScaleHash.Add("from", thisObj.Scale);
tweenScaleHash.Add("to", new Vector2(1.5f,1.5f));
tweenScaleHash.Add("time", 1.2f);
tweenScaleHash.Add("easetype","spring");
tweenScaleHash.Add("onUpdate","tweenScaleValue");
iTween.ValueTo(gameObject, tweenScaleHash);
Hashtable tweenRotationHash = new Hashtable();
tweenRotationHash.Add("from", thisObj.Rotation);
tweenRotationHash.Add("to", new Vector3(0f,0f,720f));
tweenRotationHash.Add("time", 1.2f);
tweenRotationHash.Add("easetype","spring");
tweenRotationHash.Add("onUpdate","tweenRotationValue");
iTween.ValueTo(gameObject, tweenRotationHash);
// 2. Nummer auf Icon animieren...
Hashtable tweenLocationHash = new Hashtable();
tweenLocationHash.Add("from", thisObj.Location);
tweenLocationHash.Add("to", new Vector2(xpos,190f));
tweenLocationHash.Add("time", 0.7f);
tweenLocationHash.Add("delay", 1.6f);
tweenLocationHash.Add("easetype","easeInSine");
tweenLocationHash.Add("onUpdate","tweenLocationValue");
iTween.ValueTo(gameObject, tweenLocationHash);
Hashtable tweenScaleToEndHash = new Hashtable();
tweenScaleToEndHash.Add("from", new Vector2(1.5f,1.5f));
tweenScaleToEndHash.Add("to", new Vector2(0.5f,0.5f));
tweenScaleToEndHash.Add("time", 0.7f);
tweenScaleToEndHash.Add("delay", 1.6f);
tweenScaleToEndHash.Add("easetype","easeOutSine");
tweenScaleToEndHash.Add("onUpdate","tweenScaleValue");
iTween.ValueTo(gameObject, tweenScaleToEndHash);
}
private void tweenScaleValue (Vector2 value) {
thisObj.Scale = value;
}
private void tweenColorValue (Color value) {
thisObj.Tint = value;
}
private void tweenLocationValue (Vector2 value) {
thisObj.Location = value;
}
private void tweenRotationValue (Vector3 value) {
thisObj.Rotation = value;
}
4. Texture Import Settings
The importsettings changed a lot, so make sure that every setting is correct and change and reimport if it is not.
5. Self made Shaders
I did not have any issues but some older shaders might not work any more and you need to update those.
6. Physics
I did not have any issues but the physics system changed and you might need to update some settings.
7. OnGui and Stripping
To my surprise a Scrollview did not show up when i used an level of stripping. Seems to be a bug - and there is apparently no workaround. Supersimpleexample (won´t work with stripping)
void OnGUI () {
GUI.BeginScrollView (scrollPosRect, scrollPos, scrollContentRect);
GUI.EndScrollView();
}
8 make content for the retina display (iphone4)
Since iPhone4 is now supported you can try to get the best quality out of it by using higher resolution textures.
There is a number of ways on how to do that, its up to you. Usually you need to focus on 2D grafics like gui and Sprites. In my case i used 512x512 textures for older phones and 1024x1024 for iPhone4, swapping textures to the higher version when iPhone4 is detected.
9 Speed on the device
You might run into a speed issue, where your game runs roughly at 50% or slower after you build and run it 1st time on the device. In this case you probably used universal “armv6+armv7 (opengl es1.1 + 2.0)” inside you player settings.
Change that to “Armv6 (openGL Es 1.1)”. If that doesn´t help have a look in xCode at AppController.mm and change the line “#define USE_OPENGLES20_IF_AVAILABLE 1” to “#define USE_OPENGLES20_IF_AVAILABLE 0”.
10 More Speed on iPad
This is no Unity3 tip. Anyways, i always felt that my iPad Version was running sluggish. An FPS test stated ~18FPS.
Meanwhile i knew that using transparent Objects in big sizes is no good idea. So first i got rid of a blob shadow and replaced that with a plane. That resulted in +4 FPS. I reduced the cats meshes: another +4FPS.
But the biggest one was GUI Manager. If you check out the game or have a look at the screenshots, you see a big background picture showing a chinese stone wall with ornaments. This Texture was mapped on a Gui QuadObject, which had the standard GUIManager Shader.
So i dublicated that shader and rewrote it to not use alphas. Shader Script:
Shader "GUIManager/GUIManager Opaque" {
Properties {
_Color ("Main Color", Color) = (1.0, 1.0, 1.0)
_MainTex ("Texture RGB", 2D) = "white" {}
}
Category {
//Blend SrcAlpha OneMinusSrcAlpha
//Alphatest Off
//ColorMask RGB
//Cull Back
Lighting Off
ZWrite Off
Fog {Mode Off}
BindChannels {
Bind "Color", color
Bind "Vertex", vertex
Bind "TexCoord", texcoord
}
// ---- Single texture cards (does not do color tint)
SubShader {
Tags {"Queue" = "Background" }
Pass {
SetTexture [_MainTex] {
combine texture * primary, texture * primary
}
SetTexture [_MainTex] {
constantcolor [_Color]
combine previous * constant, previous * constant
}
}
}
}
}
That change in another +10FPS. So now it is running on ~38 FPS on iPad.
In case you want tho check it out: i uploaded the iPad version 1.1 yesterday and most likely it will be updated in the store next week.
As for the new Uinty features that apply to iPhone, i cannot say anything about that, as this gae would not benefit from Lightmapping or Occlusion Culling.