Ejemplo n.º 1
0
        // Request is sent by the Save System
        public void OnSaveRequest(SaveGame saveGame)
        {
            if (!hasIdentification)
            {
                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 save component: {0}. Component is potentially destroyed.", getIdentification));
                    saveableComponentIDs.RemoveAt(i);
                    saveableComponentObjects.RemoveAt(i);
                }
                else
                {
                    if (!hasStateReset && !getSaveable.OnSaveCondition())
                    {
                        continue;
                    }

                    string dataString = getSaveable.OnSave();

                    if (!string.IsNullOrEmpty(dataString))
                    {
                        saveGame.Set(saveIdentification, container?.PathSourceContainer, getIdentification, dataString, this.gameObject.scene.name);
                    }
                }
            }

            hasStateReset = false;
        }
Ejemplo n.º 2
0
        // Request is sent by the Save System
        public void OnSaveRequest(SaveGame saveGame)
        {
            if (cachedSaveGame != saveGame)
            {
                cachedSaveGame = saveGame;
            }

            if (string.IsNullOrEmpty(saveIdentification))
            {
                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 save component: {0}. Component is potentially destroyed.", getIdentification));
                    saveableComponentIDs.RemoveAt(i);
                    saveableComponentObjects.RemoveAt(i);
                }
                else
                {
                    if (getSaveable.OnSaveCondition() == false)
                    {
                        continue;
                    }
                    else
                    {
                        saveGame.Set(getIdentification, getSaveable.OnSave(), this.gameObject.scene.name);
                    }
                }
            }
        }