Ejemplo n.º 1
0
        // Request is sent by the Save System
        public void OnLoadRequest(SaveGame saveGame)
        {
            if (cachedSaveGame != saveGame)
            {
                if (cachedSaveGame != null)
                {
                    hasLoaded = false;
                }

                cachedSaveGame = saveGame;
            }

            if (saveGame == null)
            {
                Debug.LogWarning("Invalid save game request");
                return;
            }

            if (loadOnce && hasLoaded)
            {
                return;
            }

            if (string.IsNullOrEmpty(saveIdentification))
            {
                //Debug.LogWarning(string.Format("Save identification is empty on {0}", this.gameObject.name));
                return;
            }

            int componentCount = saveableComponentIDs.Count;

            for (int i = componentCount - 1; i >= 0; i--)
            {
                ISaveable getSaveable       = saveableComponentObjects[i];
                string    getIdentification = saveableComponentIDs[i];

                if (getSaveable == null)
                {
                    Debug.Log(string.Format("Failed to load component: {0}. Component is potentially destroyed.", getIdentification));
                    saveableComponentIDs.RemoveAt(i);
                    saveableComponentObjects.RemoveAt(i);
                }
                else
                {
                    string getData = saveGame.Get(saveableComponentIDs[i]);

                    if (!string.IsNullOrEmpty(getData))
                    {
                        getSaveable.OnLoad(getData);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // Request is sent by the Save System
        public void OnLoadRequest(SaveGame saveGame)
        {
            if (loadOnce && hasLoaded)
            {
                return;
            }
            else
            {
                // Ensure it only loads once with the loadOnce
                // Parameter
                hasLoaded         = true;
                hasIdentification = !string.IsNullOrEmpty(saveIdentification);
            }

            if (!hasIdentification)
            {
                Debug.Log("No identification!");
                return;
            }

            int componentCount = saveableComponentIDs.Count;

            for (int i = componentCount - 1; i >= 0; i--)
            {
                ISaveable getSaveable       = saveableComponentObjects[i];
                string    getIdentification = saveableComponentIDs[i];

                if (getSaveable == null)
                {
                    Debug.Log(string.Format("Failed to load component: {0}. Component is potentially destroyed.", getIdentification));
                    saveableComponentIDs.RemoveAt(i);
                    saveableComponentObjects.RemoveAt(i);
                }
                else
                {
                    string getData = saveGame.Get(saveableComponentIDs[i]);

                    if (!string.IsNullOrEmpty(getData))
                    {
                        getSaveable.OnLoad(getData);
                    }
                }
            }
        }