You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.0 KiB
71 lines
2.0 KiB
using System.IO; |
|
using UnityEngine; |
|
using UnityEditorInternal; |
|
|
|
namespace UnityEditor.Rendering.Universal |
|
{ |
|
internal class UniversalProjectSettings : ScriptableObject |
|
{ |
|
public static string filePath => "ProjectSettings/URPProjectSettings.asset"; |
|
|
|
//preparing to eventual migration later |
|
enum Version |
|
{ |
|
None, |
|
First |
|
} |
|
|
|
[SerializeField] |
|
int m_LastMaterialVersion = k_NeverProcessedMaterialVersion; |
|
|
|
internal const int k_NeverProcessedMaterialVersion = -1; |
|
|
|
public static int materialVersionForUpgrade |
|
{ |
|
get => instance.m_LastMaterialVersion; |
|
set |
|
{ |
|
instance.m_LastMaterialVersion = value; |
|
} |
|
} |
|
|
|
//singleton pattern |
|
static UniversalProjectSettings s_Instance; |
|
static UniversalProjectSettings instance => s_Instance ?? CreateOrLoad(); |
|
UniversalProjectSettings() |
|
{ |
|
s_Instance = this; |
|
} |
|
|
|
static UniversalProjectSettings CreateOrLoad() |
|
{ |
|
//try load |
|
InternalEditorUtility.LoadSerializedFileAndForget(filePath); |
|
|
|
//else create |
|
if (s_Instance == null) |
|
{ |
|
UniversalProjectSettings created = CreateInstance<UniversalProjectSettings>(); |
|
created.hideFlags = HideFlags.HideAndDontSave; |
|
} |
|
|
|
System.Diagnostics.Debug.Assert(s_Instance != null); |
|
return s_Instance; |
|
} |
|
|
|
internal static void Save() |
|
{ |
|
if (s_Instance == null) |
|
{ |
|
Debug.Log("Cannot save ScriptableSingleton: no instance!"); |
|
return; |
|
} |
|
|
|
string folderPath = Path.GetDirectoryName(filePath); |
|
if (!Directory.Exists(folderPath)) |
|
Directory.CreateDirectory(folderPath); |
|
|
|
InternalEditorUtility.SaveToSerializedFileAndForget(new[] { s_Instance }, filePath, allowTextSerialization: true); |
|
} |
|
} |
|
}
|
|
|