浏览代码

Improve upgrade material system + Add versionning via HDRPProjectVersion.txt to project settings

/main
sebastienlagarde 7 年前
当前提交
56693471
共有 10 个文件被更改,包括 111 次插入4 次删除
  1. 9
      com.unity.render-pipelines.core/CoreRP/Editor/CoreEditorUtils.cs
  2. 16
      com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/UpgradeMenuItem.cs
  3. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader
  4. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
  5. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader
  6. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader
  7. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
  8. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Unlit/Unlit.shader
  9. 61
      com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/HDRPVersion.cs
  10. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/HDRPVersion.cs.meta

9
com.unity.render-pipelines.core/CoreRP/Editor/CoreEditorUtils.cs


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

static public GameObject CreateGameObject(GameObject parent, string name, params Type[] types)
{
return ObjectFactory.CreateGameObject(GameObjectUtility.GetUniqueNameForSibling(parent != null ? parent.transform : null, name), types);
}
static public string GetCurrentProjectVersion()
{
string[] readText = File.ReadAllLines("ProjectSettings/ProjectVersion.txt");
// format is m_EditorVersion: 2018.2.0b7
string[] versionText = readText[0].Split(' ');
return versionText[1];
}
}

16
com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/UpgradeMenuItem.cs


using System;
using System.IO;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

// Update EmissiveColor after we remove EmissiveIntensity from all shaders in 2018.2
// Now EmissiveColor is HDR and it must be update to the value new EmissiveColor = old EmissiveColor * EmissiveIntensity
static bool UpdateMaterial_EmissiveColor_2018_2(string path, Material mat)
static bool UpdateMaterial_EmissiveColor(string path, Material mat)
{
// Find the missing property in the file and update EmissiveColor
string[] readText = File.ReadAllLines(path);

return false;
}
static void UpdateMaterialFile_EmissiveColor_2018_2(string path)
static void UpdateMaterialFile_EmissiveColor(string path)
{
string[] readText = File.ReadAllLines(path);

}
[MenuItem("Edit/Render Pipeline/Update all Materials to latest version", priority = CoreUtils.editMenuPriority3)]
static void UpdateMaterialToNewerVersion()
static public void UpdateMaterialToNewerVersion()
UpdateMaterialToNewerVersion("(EmissiveColor)", UpdateMaterial_EmissiveColor_2018_2, UpdateMaterialFile_EmissiveColor_2018_2);
// Caution: All the functions here MUST be re-entrant (call multiple time) without failing.
float currentVersion = HDRPVersion.GetCurrentHDRPProjectVersion();
if (currentVersion < 1.0)
{
// Appear in hdrp version 1.0
UpdateMaterialToNewerVersion("(EmissiveColor)", UpdateMaterial_EmissiveColor, UpdateMaterialFile_EmissiveColor);
}
}
}
}

3
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader


{
Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

3
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader


{
Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

3
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader


{
Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

3
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader


{
Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

3
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader


{
Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.

3
com.unity.render-pipelines.high-definition/HDRP/Material/Unlit/Unlit.shader


{
Properties
{
// Versioning of material to help for upgrading
[HideInInspector] _HdrpVersion("_HdrpVersion", Float) = 1
// Be careful, do not change the name here to _Color. It will conflict with the "fake" parameters (see end of properties) required for GI.
_UnlitColor("Color", Color) = (1,1,1,1)
_UnlitColorMap("ColorMap", 2D) = "white" {}

61
com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/HDRPVersion.cs


using System;
using System.IO;
using UnityEngine;
using UnityEditor;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
[InitializeOnLoad]
public class HDRPVersion
{
static public float hdrpVersion = 1.0f;
static public float GetCurrentHDRPProjectVersion()
{
string[] version = new string[1];
version[0] = "0.9"; // Note: When we don't know what a project is, assume worst case
try
{
version = File.ReadAllLines("ProjectSettings/HDRPProjectVersion.txt");
}
catch
{
Debug.LogWarning("Unable to read from ProjectSettings/HDRPProjectVersion.txt - Assign default version value");
}
return float.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 Unity 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();
}
}
// Update current project version with HDRP version
WriteCurrentHDRPProjectVersion();
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/HDRPVersion.cs.meta


fileFormatVersion: 2
guid: 15eef13f7728c874da10e59d60aac6fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存