浏览代码

Apply remapping to all serialzied types

/main
Tim Cooper 7 年前
当前提交
7ab634f3
共有 6 个文件被更改,包括 12 次插入14 次删除
  1. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
  3. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/EdgeConnectorListener.cs
  4. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs
  5. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/SerializationTests.cs
  6. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/CopyPasteGraph.cs

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


public virtual void OnAfterDeserialize()
{
// have to deserialize 'globals' before nodes
m_Properties = SerializationHelper.Deserialize<IShaderProperty>(m_SerializedProperties, null);
m_Properties = SerializationHelper.Deserialize<IShaderProperty>(m_SerializedProperties, GraphUtil.GetLegacyTypeRemapping());
var nodes = SerializationHelper.Deserialize<INode>(m_SerializableNodes, GraphUtil.GetLegacyTypeRemapping());
m_Nodes = new List<AbstractMaterialNode>(nodes.Count);
m_NodeDictionary = new Dictionary<Guid, INode>(nodes.Count);

m_SerializableNodes = null;
m_Edges = SerializationHelper.Deserialize<IEdge>(m_SerializableEdges, null);
m_Edges = SerializationHelper.Deserialize<IEdge>(m_SerializableEdges, GraphUtil.GetLegacyTypeRemapping());
m_SerializableEdges = null;
foreach (var edge in m_Edges)
AddEdgeToNodeEdges(edge);

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs


else
m_Guid = Guid.NewGuid();
m_Slots = SerializationHelper.Deserialize<ISlot>(m_SerializableSlots, null);
m_Slots = SerializationHelper.Deserialize<ISlot>(m_SerializableSlots, GraphUtil.GetLegacyTypeRemapping());
m_SerializableSlots = null;
foreach (var s in m_Slots)
s.owner = this;

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/EdgeConnectorListener.cs


using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.Graphing;
using UnityEngine;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs


using System.Text;
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
[ScriptedImporter(4, ShaderGraphImporter.ShaderGraphExtension)]
[ScriptedImporter(10, ShaderGraphImporter.ShaderGraphExtension)]
public class ShaderGraphImporter : ScriptedImporter
{
public const string ShaderGraphExtension = "shadergraph";

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/SerializationTests.cs


var serialized = SerializationHelper.Serialize<SimpleSerializeClass>(toSerialize);
Assert.AreEqual(1, serialized.Count);
var loaded = SerializationHelper.Deserialize<SimpleSerializeClass>(serialized, null);
var loaded = SerializationHelper.Deserialize<SimpleSerializeClass>(serialized, GraphUtil.GetLegacyTypeRemapping());
Assert.AreEqual(1, loaded.Count);
Assert.IsInstanceOf<SimpleSerializeClass>(loaded[0]);
loaded[0].AssertAsReference();

var serialized = SerializationHelper.Serialize<SimpleSerializeClass>(toSerialize);
Assert.AreEqual(3, serialized.Count);
var loaded = SerializationHelper.Deserialize<SimpleSerializeClass>(serialized, null);
var loaded = SerializationHelper.Deserialize<SimpleSerializeClass>(serialized, GraphUtil.GetLegacyTypeRemapping());
Assert.AreEqual(3, loaded.Count);
Assert.IsInstanceOf<SimpleSerializeClass>(loaded[0]);
Assert.IsInstanceOf<ChildClassA>(loaded[1]);

var serialized = SerializationHelper.Serialize<ITestInterface>(toSerialize);
Assert.AreEqual(3, serialized.Count);
var loaded = SerializationHelper.Deserialize<SimpleSerializeClass>(serialized, null);
var loaded = SerializationHelper.Deserialize<SimpleSerializeClass>(serialized, GraphUtil.GetLegacyTypeRemapping());
Assert.AreEqual(3, loaded.Count);
Assert.IsInstanceOf<SimpleSerializeClass>(loaded[0]);
Assert.IsInstanceOf<ChildClassA>(loaded[1]);

var serializedContainer = JsonUtility.ToJson(container, true);
var deserializedContainer = JsonUtility.FromJson<SerializationContainer>(serializedContainer);
var loaded = SerializationHelper.Deserialize<SimpleSerializeClass>(deserializedContainer.serializedElements, null);
var loaded = SerializationHelper.Deserialize<SimpleSerializeClass>(deserializedContainer.serializedElements, GraphUtil.GetLegacyTypeRemapping());
Assert.AreEqual(1, loaded.Count);
Assert.IsInstanceOf<SimpleSerializeClass>(loaded[0]);
loaded[0].AssertAsReference();

};
var serialized = SerializationHelper.Serialize<MaterialSlot>(toSerialize);
var loaded = SerializationHelper.Deserialize<MaterialSlot>(serialized, null);
var loaded = SerializationHelper.Deserialize<MaterialSlot>(serialized, GraphUtil.GetLegacyTypeRemapping());
Assert.AreEqual(2, loaded.Count);
Assert.IsInstanceOf<MaterialSlot>(loaded[0]);

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/CopyPasteGraph.cs


using System.Text;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
namespace UnityEditor.Graphing.Util
{

public void OnAfterDeserialize()
{
var nodes = SerializationHelper.Deserialize<INode>(m_SerializableNodes, null);
var nodes = SerializationHelper.Deserialize<INode>(m_SerializableNodes, GraphUtil.GetLegacyTypeRemapping());
var edges = SerializationHelper.Deserialize<IEdge>(m_SerializableEdges, null);
var edges = SerializationHelper.Deserialize<IEdge>(m_SerializableEdges, GraphUtil.GetLegacyTypeRemapping());
m_Edges.Clear();
foreach (var edge in edges)
m_Edges.Add(edge);

正在加载...
取消
保存