iPhoneSettings

While the iOS SDK promises to give you a single platform to all of the iOS devices, there are going to be times that you want to do device specific things. For example, you may want to load Retina Display compatible assets if you are on the iPhone4 or you may want to provide another networking interface other than Game Center if you find yourself on a 1G, 2G, or base 3G device. Further, you may want to determine where this device is located in the world. All of this is accomplished by gaining access to iPhoneSettings.

Screen orientation

iPhoneSettings provides an interface for getting the current screen orientation from the device and it will allow you to specify the orientation you want your content to be displayed in.

If you want to only operate in one mode, you can attach a script to the camera and in its Start() method define the orientation you want.

// Start in landscape mode
function Start () {
  iPhoneSettings.screenOrientation = iPhoneScreenOrientation.Landscape;
}

Later in the chapter we will build an example that illustrates how to move between the multiple modes that the device is capable of, as the user changes the device orientation.

Sleep mode

By default, any iOS portable device will follow power management settings and darken its screen after a certain amount of time to prevent draining the battery if the user isn't using it. The iOS power management system will reset its internal timers every time a touch event happens on the device. However, for games this may become a problem since you may not require the user to maintain contact with the device or through a Bluetooth keyboard during gameplay. Driving games and flight simulators come immediately to mind as two genres of games that may be impacted by this.

In these cases it makes sense to put the device in a state where the device will not be allowed to go to sleep. This can be accomplished by setting the screenCanDarken attribute of iPhoneSettings to false. It is important to review that statement again – the device will not be allowed to go to sleep – EVER. As long as your application is running, it will block the device from entering a sleep state. Consequently, it is your responsibility to make sure that if you leave the states of your game where users aren't touching the device that you flip the screenCanDarken attibute to true so that iOS can darken the screen.

Device information

Unity provides several useful fields to the developer that gives information about the device and its unique identification.

Field

Description

name

This is the name that the user has given to the device. Useful if you want to allow users to find one another across the wan or locally

model

Provides a simple text model name

systemName

This is simply the name of the OS running on the device

generation

This will tell you what generation this device belongs to. The values are enumerated in iPhoneGeneration and provide a reliable way to determine exactly what type of device the user has

uniqueIdentifier

This is the globally unique identifier that identifies this device specifically

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.117.157