コード例 #1
0
    // Load the game.
    public void Load()
    {
        if (File.Exists(saveGameName))
        {
            // 1 - deserialize the save game information.
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGame));
            FileStream    stream     = File.Open(saveGameName, FileMode.Open);
            Game = serializer.Deserialize(stream) as SaveGame;
            stream.Dispose();

            // 2 - any setup after loading data.
            InstantiateState(true);

            // 3 - restart the any objects
            foreach (Transform child in SceneRoot.transform)
            {
                GameObject   go       = child.gameObject;
                IActivatable activate = go.GetComponent(typeof(IActivatable)) as IActivatable;
                if (activate != null)
                {
                    activate.SetEnabled(true);
                }
            }
            Debug.Log("Game Loaded");
        }
    }