您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

76 行
2.5 KiB

using System;
using System.IO;
using UnityEngine;
using UnityEditor;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
[InitializeOnLoad]
public class HDRPVersion
{
static public int hdrpVersion = 1;
static public int GetCurrentHDRPProjectVersion()
{
string[] version = new string[1];
version[0] = "0"; // Note: When we don't know what a project is, assume worst case 0
try
{
version = File.ReadAllLines("ProjectSettings/HDRPProjectVersion.txt");
}
catch
{
// Don't display warning
//Debug.LogWarning("Unable to read from ProjectSettings/HDRPProjectVersion.txt - Assign default version value");
}
return int.Parse(version[0]);
}
static public void WriteCurrentHDRPProjectVersion()
{
string[] newVersion = new string[1];
newVersion[0] = hdrpVersion.ToString();
try
{
File.WriteAllLines("ProjectSettings/HDRPProjectVersion.txt", newVersion);
}
catch
{
Debug.LogWarning("Unable to write ProjectSettings/HDRPProjectVersion.txt");
}
}
static HDRPVersion()
{
// Compare project version with current version - Trigger an upgrade if user ask for it
if (GetCurrentHDRPProjectVersion() < hdrpVersion)
{
if (EditorUtility.DisplayDialog("A newer version of HDRP has been detected",
"Do you want to upgrade your materials to newer version?\n You can also upgrade manually materials in 'Edit -> Render Pipeline' submenu", "Yes", "No"))
{
UpgradeMenuItems.UpdateMaterialToNewerVersion();
}
}
}
}
public class FileModificationWarning : UnityEditor.AssetModificationProcessor
{
static string[] OnWillSaveAssets(string[] paths)
{
foreach (string path in paths)
{
// Detect when we save project and write our HDRP version at this time.
if (path == "ProjectSettings/ProjectSettings.asset")
{
// Update current project version with HDRP version
HDRPVersion.WriteCurrentHDRPProjectVersion();
}
}
return paths;
}
}
}