Exemple #1
0
    public void OnLoad(string data)
    {
        inventorySaveData = JsonUtility.FromJson <InventorySaveData>(data);

        if (inventorySaveData.savedItems.Length != 0)
        {
            items.Clear();

            for (int i = 0; i < inventorySaveData.savedItems.Length; i++)
            {
                InventoryItemSave getSave = inventorySaveData.savedItems[i];

                ItemData getItemData = ScriptableAssetDatabase.GetAsset(getSave.guidString) as ItemData;

                if (getItemData != null)
                {
                    AddItem(getItemData, getSave.amount, getSave.index);

                    // TODO: Create cleaner way to modify additional data in items.
                    if (getItemData.HasEnergy)
                    {
                        GetItem(getSave.index).Energy = getSave.energy;
                        ReloadItemSlot(getSave.index);
                    }
                }
                else
                {
                    Debug.Log($"Attempted to obtain guid: {getSave.guidString}");
                }
            }

            obtainedStartingItems = inventorySaveData.obtainedStartingItems;
        }
    }
    public void OnLoad(string data)
    {
        SaveData saveData = JsonUtility.FromJson <SaveData>(data);

        if (!string.IsNullOrEmpty(saveData.partGuid))
        {
            Set(ScriptableAssetDatabase.GetAsset(saveData.partGuid) as BodyData);
        }
    }
Exemple #3
0
    public void OnLoad(string data)
    {
        SaveData getData = JsonUtility.FromJson <SaveData>(data);

        if (!string.IsNullOrEmpty(data))
        {
            Configure(ScriptableAssetDatabase.GetAsset(getData.data) as ItemData, getData.amount);
        }
    }
Exemple #4
0
    public void OnLoad(string data)
    {
        if (string.IsNullOrEmpty(data))
        {
            return;
        }

        currentSaveGame = SaveUtility.LoadSave(currentSaveSlot.Value);

        if (currentSaveGame == null)
        {
            Debug.Log("Could not find current save");
            return;
        }

        SaveData saveData = JsonUtility.FromJson <SaveData>(data);

        if (saveData.data != null && saveData.data.Count > 0)
        {
            for (int i = 0; i < saveData.data.Count; i++)
            {
                SaveablePrefab saveablePrefab = ScriptableAssetDatabase.GetAsset(saveData.data[i].prefabGUID) as SaveablePrefab;

                if (saveablePrefab == null)
                {
                    Debug.Log($"Could not find reference in ScriptableAssetDatabase for Saveable Prefab : {saveData.data[i].prefabGUID}");
                    continue;
                }

                for (int i2 = 0; i2 < saveData.data[i].saveableGUIDs.Count; i2++)
                {
                    Saveable getSaveable = saveablePrefab.Retrieve <Saveable>(saveData.data[i].saveableGUIDs[i2]);
                    getSaveable.OnLoadRequest(currentSaveGame);

#if UNITY_EDITOR
                    getSaveable.transform.SetParent(this.transform, true);
#endif
                }
            }
        }
    }
Exemple #5
0
    public void OnLoad(string data)
    {
        SaveData saveData = JsonUtility.FromJson <SaveData>(data);

        if (saveData != null)
        {
            for (int i = 0; i < saveData.actions.Count; i++)
            {
                ScriptableTileBase tileBase = ScriptableAssetDatabase.GetAsset(saveData.actions[i].Guid) as ScriptableTileBase;

                if (tileBase != null)
                {
                    SetTile(saveData.actions[i].Location, saveData.actions[i].Tag, tileBase);
                }
                else
                {
                    Debug.Log("Tried to obtain null tilebase data");
                }
            }
        }
    }
Exemple #6
0
 private void Awake()
 {
     instance = this;
     GameObject.DontDestroyOnLoad(this.gameObject);
 }
Exemple #7
0
    private static void LoadItems(bool testingInEditor)
    {
        int buildIndex = EditorSceneManager.GetActiveScene().buildIndex;

        bool canCreateAssetDatabase = (testingInEditor) ? true : (buildIndex == 0);

        // We only want to create this object at the first scene.
        if (canCreateAssetDatabase)
        {
            guidCache = new HashSet <string>();

            if (BuildPipeline.isBuildingPlayer)
            {
                var scene = EditorSceneManager.GetActiveScene();
                EditorSceneManager.MarkSceneDirty(scene);
            }

            GameObject assetDataBase = new GameObject("Scriptable Asset Database");

            EditorUtility.SetDirty(assetDataBase);

            ScriptableAssetDatabase dataBase = assetDataBase.AddComponent <ScriptableAssetDatabase>();

            EditorUtility.SetDirty(dataBase);

            string[] lookPath      = new string[] { "Assets/ScriptableObjects", "Upload/Assets/ScriptableObjects" };
            string[] itemGuidPaths = AssetDatabase.FindAssets("t:ScriptableObject", lookPath);

            for (int i = 0; i < itemGuidPaths.Length; i++)
            {
                string path = AssetDatabase.GUIDToAssetPath(itemGuidPaths[i]);
                IReferenceableAsset getItemData = AssetDatabase.LoadAssetAtPath <ScriptableObject>(path) as IReferenceableAsset;

                if (getItemData != null)
                {
                    string           guid  = getItemData.GetGuid().ToString();
                    ScriptableObject asset = getItemData as ScriptableObject;

                    bool isGuidDuplicate = guidCache.Contains(guid);

                    // Check if guid is valid or duplicate, if so then we assign a new one for the asset.
                    // And we ensure this gets saved within the editor.
                    if (string.IsNullOrEmpty(getItemData.GetGuid()) || isGuidDuplicate)
                    {
                        getItemData.GenerateNewGuid();
                        guid = getItemData.GetGuid().ToString();

                        EditorUtility.SetDirty((ScriptableObject)getItemData);

                        Debug.Log($"Found duplicate guid on {getItemData}");
                    }

                    dataBase.values.Add(asset);
                    dataBase.keys.Add(guid);

                    // Fast way to do a lookup in case there is a duplicate guid
                    guidCache.Add(guid);
                }
            }
        }
    }
Exemple #8
0
 private void Awake()
 {
     //Debug.Log("ScriptableAssetDatabase.Awake");
     instance = this;
     GameObject.DontDestroyOnLoad(this.gameObject);
 }