Game Development Reference
In-Depth Information
Figure 9-4. Adding a LoadSaveManager component to the GameManager object in the scene
Next, we'll amend the GameManager class first coded in Chapter 4 of this topic. Consider Listing 9-6,
which lists the complete and final implementation of the GameManager class, integrating with
load-and-save game functionality. Comments follow.
Listing 9-6. Completing the GameManager Class
001 //GameManager
002 //Singleton and persistent object to manage game state
003 //For high level control over game
004 //--------------------------------------------------------------
005 using UnityEngine;
006 using System.Collections;
007 //Game Manager requires other manager components
008 [RequireComponent (typeof (NotificationsManager))] //Component for sending and receiving notifications
009 //--------------------------------------------------------------
010 public class GameManager : MonoBehaviour
011 {
012 //--------------------------------------------------------------
013 //public properties
014 //C# property to retrieve currently active instance of object, if any
015 public static GameManager Instance
016 {
017 get
018 {
019 if (instance == null) instance = new GameObject ("GameManager").
AddComponent<GameManager>(); //create game manager object if required
Search WWH ::




Custom Search