예제 #1
0
        /// <summary>
        /// Load the inventory data from the JSON file that this Inventory
        /// references.
        /// </summary>
        public void Load()
        {
            assetBundlePath = System.IO.Path.Combine(Application.persistentDataPath, "AssetBundles");
            assetBundlePath = System.IO.Path.Combine(assetBundlePath, assetBundleName);
            Debug.Log("[Inventory.Load] assetBundlePath = " + assetBundlePath);

            loadedAssetBundle =
                AssetBundleManager.LoadAssetBundleAtPath(assetBundlePath);

            if (!loadedAssetBundle)
            {
                Debug.LogError("[Inventory.Load] Failed to load asset bundle" +
                               " at path '" + assetBundlePath + "'");
            }

            path = System.IO.Path.Combine(Application.persistentDataPath,
                                          folderName);
            path = System.IO.Path.Combine(path, filename);

            // Load save data from disk
            if (File.Exists(path))
            {
                using (StreamReader streamReader = File.OpenText(path))
                {
                    string        jsonString = streamReader.ReadToEnd();
                    InventoryData loadedData =
                        JsonUtility.FromJson <InventoryData>(jsonString);
                    data = loadedData;
                }
            }
            else
            {
                data = InventoryData.Null;
            }
        }
예제 #2
0
        /// <summary>
        /// Save the inventory data to the JSON file that this Inventory
        /// references.
        /// </summary>
        public void Save()
        {
            string jsonString    = JsonUtility.ToJson(data, true);
            var    directoryPath =
                System.IO.Path.Combine(Application.persistentDataPath, folderName);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            using (StreamWriter streamWriter = File.CreateText(path))
            {
                streamWriter.Write(jsonString);
            }

            AssetBundleManager.UnloadAssetBundleAtPath(assetBundlePath);
            loadedAssetBundle = null;
            data = InventoryData.Null;
        }