/// <summary> /// Save plugin data to disk. /// </summary> private void SavePluginData() { #if HOUDINIENGINEUNITY_ENABLED // Convert dictionary to JSON and store as string in EditorPrefs // Retrieve dictionary keys and store as array in temporary class. // Then write out array class using JsonUtility. StoreDataArray<string> keyArray = new StoreDataArray<string>(); keyArray._array = new string[_dataMap.Count]; _dataMap.Keys.CopyTo(keyArray._array, 0); string keyJson = JsonUtility.ToJson(keyArray); // Retrieve dictionary values and store as array in temporary class. // Then write out array class using JsonUtility. StoreDataArray<StoreData> dataArray = new StoreDataArray<StoreData>(); dataArray._array = new StoreData[_dataMap.Count]; _dataMap.Values.CopyTo(dataArray._array, 0); string dataJson = JsonUtility.ToJson(dataArray); //Debug.Log("Save:: Keys: " + keyJson); //Debug.Log("Save:: Data: " + dataJson); #if UNITY_EDITOR // Store in Editor Prefs UnityEditor.EditorPrefs.SetString(HEU_Defines.PLUGIN_STORE_KEYS, keyJson); UnityEditor.EditorPrefs.SetString(HEU_Defines.PLUGIN_STORE_DATA, dataJson); #endif #endif _requiresSave = false; }
/// <summary> /// Retrieve the array from given JSON string. /// </summary> /// <typeparam name="T">Type of array</typeparam> /// <param name="jsonArray">String containing JSON array.</param> /// <returns>Array of objects of type T.</returns> private T[] GetJSONArray<T>(string jsonArray) { // Parse out array string into array class, then just grab the array. StoreDataArray<T> dataArray = JsonUtility.FromJson<StoreDataArray<T>>(jsonArray); return dataArray._array; }