浏览代码

[Material graph] Fix up subgraph asset reference serialization.

/main
Tim Cooper 8 年前
当前提交
29600f72
共有 3 个文件被更改,包括 66 次插入28 次删除
  1. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/WithSubGraph.ShaderGraph
  2. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/cracks.ShaderSubGraph
  3. 65
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs

24
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/WithSubGraph.ShaderGraph


m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 562bd27a5e73fc64d80a1d9d936ffbd5, type: 3}
m_Name: New Shader Graph 1
m_Name: WithSubGraph
m_EditorClassIdentifier:
m_MaterialGraph:
m_MaterialOptions:

\ \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n
\ },\\n \\\"m_ConcreteValueType\\\": 2,\\n \\\"m_ShaderOutputName\\\":
\\\"UV\\\"\\n}\"\n }\n ],\n \"m_OutputPrecision\": 1,\n \"m_PropertyName\":
\"\",\n \"m_Description\": \"\",\n \"m_Exposed\": 1,\n \"m_TextureGuid\":
\"76c3d794167d8524481195736f067518\",\n \"m_TextureType\": 0\n}"
\"\",\n \"m_Description\": \"\",\n \"m_Exposed\": 1,\n \"m_SerializedTexture\":
\"{\\n \\\"texture\\\": {\\n \\\"fileID\\\": 2800000,\\n \\\"guid\\\":
\\\"76c3d794167d8524481195736f067518\\\",\\n \\\"type\\\": 3\\n }\\n}\",\n
\ \"m_TextureType\": 0\n}"
- typeInfo:
fullName: UnityEngine.MaterialGraph.Vector1Node
assemblyName: Assembly-CSharp

\ \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n
\ \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\": 4,\\n
\ \\\"m_ShaderOutputName\\\": \\\"Output1\\\"\\n}\"\n }\n ],\n
\ \"m_OutputPrecision\": 1,\n \"m_SubGraphAssetGuid\": \"63179f4461979734ba87324ec6b1268d\"\n}"
\ \"m_OutputPrecision\": 1,\n \"m_SerializedSubGraph\": \"{\\n \\\"subGraph\\\":
{\\n \\\"fileID\\\": 11400000,\\n \\\"guid\\\": \\\"63179f4461979734ba87324ec6b1268d\\\",\\n
\ \\\"type\\\": 2\\n }\\n}\",\n \"m_SubGraphAssetGuid\": \"\",\n
\ \"serializedVersion\": 1\n}"
- typeInfo:
fullName: UnityEngine.MaterialGraph.TextureNode
assemblyName: Assembly-CSharp

\ \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n
\ },\\n \\\"m_ConcreteValueType\\\": 2,\\n \\\"m_ShaderOutputName\\\":
\\\"UV\\\"\\n}\"\n }\n ],\n \"m_OutputPrecision\": 1,\n \"m_PropertyName\":
\"\",\n \"m_Description\": \"\",\n \"m_Exposed\": 1,\n \"m_TextureGuid\":
\"5a5e07ee958edbd468227e1d9ac4726a\",\n \"m_TextureType\": 3\n}"
\"\",\n \"m_Description\": \"\",\n \"m_Exposed\": 1,\n \"m_SerializedTexture\":
\"{\\n \\\"texture\\\": {\\n \\\"fileID\\\": 2800000,\\n \\\"guid\\\":
\\\"65e6d39bbd36f9c45a618111370cb870\\\",\\n \\\"type\\\": 3\\n }\\n}\",\n
\ \"m_TextureType\": 3\n}"
- typeInfo:
fullName: UnityEngine.MaterialGraph.ColorNode
assemblyName: Assembly-CSharp

\ \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\": 0.0,\\n
\ \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\": 4,\\n
\ \\\"m_ShaderOutputName\\\": \\\"Output1\\\"\\n}\"\n }\n ],\n
\ \"m_OutputPrecision\": 1,\n \"m_SubGraphAssetGuid\": \"10c41d675e06a124a845154dccbcafa8\"\n}"
\ \"m_OutputPrecision\": 1,\n \"m_SerializedSubGraph\": \"{\\n \\\"subGraph\\\":
{\\n \\\"fileID\\\": 11400000,\\n \\\"guid\\\": \\\"10c41d675e06a124a845154dccbcafa8\\\",\\n
\ \\\"type\\\": 2\\n }\\n}\",\n \"m_SubGraphAssetGuid\": \"\",\n
\ \"serializedVersion\": 1\n}"
m_SerializableEdges:
- typeInfo:
fullName: UnityEngine.Graphing.Edge

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/cracks.ShaderSubGraph


0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
2,\\n \\\"m_ShaderOutputName\\\": \\\"UV\\\"\\n}\"\n }\n ],\n
\ \"m_OutputPrecision\": 1,\n \"m_PropertyName\": \"\",\n \"m_Description\":
\"\",\n \"m_Exposed\": 1,\n \"m_TextureGuid\": \"6e8d12f68bae2294da814f9d4c81b29a\",\n
\ \"m_TextureType\": 0\n}"
\"\",\n \"m_Exposed\": 1,\n \"m_SerializedTexture\": \"{\\n \\\"texture\\\":
{\\n \\\"fileID\\\": 2800000,\\n \\\"guid\\\": \\\"6e8d12f68bae2294da814f9d4c81b29a\\\",\\n
\ \\\"type\\\": 3\\n }\\n}\",\n \"m_TextureType\": 0\n}"
- typeInfo:
fullName: UnityEngine.MaterialGraph.SubtractNode
assemblyName: Assembly-CSharp

65
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs


using System;
#if UNITY_EDITOR
#endif
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

, IOnAssetEnabled
{
[SerializeField]
private string m_SubGraphAssetGuid;
private string m_SerializedSubGraph = string.Empty;
[Serializable]
private class SubGraphHelper
{
public MaterialSubGraphAsset subGraph;
}
#if UNITY_EDITOR
public MaterialSubGraphAsset subGraphAsset

if (string.IsNullOrEmpty(m_SubGraphAssetGuid))
return null;
if (serializedVersion < kCurrentSerializedVersion)
DoUpgrade();
var path = AssetDatabase.GUIDToAssetPath(m_SubGraphAssetGuid);
if (string.IsNullOrEmpty(path))
if (string.IsNullOrEmpty(m_SerializedSubGraph))
return AssetDatabase.LoadAssetAtPath<MaterialSubGraphAsset>(path);
var helper = new SubGraphHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedSubGraph, helper);
return helper.subGraph;
var assetPath = AssetDatabase.GetAssetPath(value);
if (string.IsNullOrEmpty(assetPath))
return;
m_SubGraphAssetGuid = AssetDatabase.AssetPathToGUID(assetPath);
var helper = new SubGraphHelper();
helper.subGraph = value;
m_SerializedSubGraph = EditorJsonUtility.ToJson(helper, true);
#else
public MaterialSubGraphAsset subGraphAsset
// SAVED FOR LATER
[SerializeField]
private string m_SubGraphAssetGuid;
[SerializeField]
private int serializedVersion = 0;
const int kCurrentSerializedVersion = 1;
private void DoUpgrade()
get
{
return null;
}
set
{}
var helper = new SubGraphHelper();
if (string.IsNullOrEmpty(m_SubGraphAssetGuid))
helper.subGraph = null;
var path = AssetDatabase.GUIDToAssetPath(m_SubGraphAssetGuid);
if (string.IsNullOrEmpty(path))
helper.subGraph = null;
helper.subGraph = AssetDatabase.LoadAssetAtPath<MaterialSubGraphAsset>(path);
m_SerializedSubGraph = EditorJsonUtility.ToJson(helper, true);
serializedVersion = kCurrentSerializedVersion;
m_SubGraphAssetGuid = string.Empty;
#else
public MaterialSubGraphAsset subGraphAsset {get; set:}
#endif
private SubGraph subGraph

正在加载...
取消
保存