public static SaveSettings Get() { if (instance != null) { return(instance); } var savePluginSettings = Resources.Load(SaveSettingsAssetName, typeof(SaveSettings)) as SaveSettings; #if UNITY_EDITOR // In case the settings are not found, we create one if (savePluginSettings == null) { return(CreateFile()); } #endif // In case it still doesn't exist, somehow it got removed. // We send a default instance of SavePluginSettings. if (savePluginSettings == null) { Debug.LogWarning($"Could not find {SaveSettingsAssetName} in resource folder, did you remove it? Using default settings."); savePluginSettings = CreateInstance <SaveSettings>(); } instance = savePluginSettings; return(instance); }
public static SaveSettings CreateFile() { string resourceFolderPath = string.Format("{0}/{1}", Application.dataPath, "Resources"); string filePath = string.Format("{0}/{1}", resourceFolderPath, $"{SaveSettingsAssetName}.asset"); // In case the directory doesn't exist, we create a new one. if (!Directory.Exists(resourceFolderPath)) { UnityEditor.AssetDatabase.CreateFolder("Assets", "Resources"); } // Check if the settings file exists in the resources path // If not, we create a new one. if (!File.Exists(filePath)) { instance = CreateInstance <SaveSettings>(); UnityEditor.AssetDatabase.CreateAsset(instance, $"Assets/Resources/{SaveSettingsAssetName}.asset"); UnityEditor.AssetDatabase.SaveAssets(); UnityEditor.AssetDatabase.Refresh(); return(instance); } else { return(Resources.Load(SaveSettingsAssetName, typeof(SaveSettings)) as SaveSettings); } }
private void OnDestroy() { instance = null; }