Game Development Reference
In-Depth Information
The VehicleCommand constructor creates the vehicle command by setting the class member
variables discussed previously. (See Listing 8-13.)
Listing 8-13. Vehicle Constructor
VehicleCommand(Context iContext,AIVehicleCommand Command, AIVehicleObjectsAffected ObjectsAffected,
int NumberObjectsAffected,float DeltaAmount,float DeltaIncrement,float MaxValue,float MinValue, int
NumberWayPoints,Vector3[] WayPoints,Vector3 Target,Object3d TargetObject)
{
m_Context = iContext;
m_Command = Command;
m_ObjectsAffected =ObjectsAffected;
m_NumberObjectsAffected= NumberObjectsAffected;
m_DeltaAmount = DeltaAmount;
m_DeltaIncrement = DeltaIncrement;
m_MaxValue = MaxValue;
m_MinValue = MinValue;
m_NumberWayPoints = NumberWayPoints;
m_WayPoints = WayPoints;
m_Target =Target;
m_TargetObject= TargetObject;
}
The SaveState() function saves the VehicleCommand class member data using the input Handle
string as the main index name under which to store the vehicle command data.
The SaveState() function does the following:
1.
Gets a SharedPreferences object associated with the Activity specified in
m_Context and the input Handle.
2.
Sets up an editor variable from the SharedPreferences object in step 1 that is
used to put the class member data into the shared preferences file.
3.
Saves the value of each class member variable. The general procedure is to
a. Create a handle to the class member variable by concatenating the Handle that is an
input parameter to the function and a string representing the variable. For example,
Handle + "Command" .
b. Next, if needed, convert the variable into a form that can be written into a
SharedPreferences object such as a string or integer. For example, an enumeration
can be converted to a string by adding it to a null string "" . The statement
m_Command + "" will convert the enumeration to a string.
c.
Store the variable in a key value pair format using the handle specific to that class
member variable as the key and the value of the class member variable as the value.
4.
Saves the changes made to all the data to the shared preferences file by
calling commit() on the editor variable created in step 2.
 
Search WWH ::




Custom Search