浏览代码

Add LegacyAttribute for declaring old class names directly on the node class

/main
Peter Bay Bastian 7 年前
当前提交
409a35e4
共有 8 个文件被更改,包括 37 次插入27 次删除
  1. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/NormalVectorNode.cs
  3. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/PositionNode.cs
  4. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ViewDirectionNode.cs
  5. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/SampleCubemapNode.cs
  6. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/SampleTexture2DNode.cs
  7. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/LegacyAttribute.cs
  8. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/LegacyAttribute.cs.meta

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


using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor.Compilation;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.Graphing.Util;

Dictionary<SerializationHelper.TypeSerializationInfo, SerializationHelper.TypeSerializationInfo> GetLegacyTypeRemapping()
{
var result = new Dictionary<SerializationHelper.TypeSerializationInfo, SerializationHelper.TypeSerializationInfo>();
var viewNode = new SerializationHelper.TypeSerializationInfo
{
fullName = "UnityEngine.MaterialGraph.ViewDirectionNode"
};
result[viewNode] = SerializationHelper.GetTypeSerializableAsString(typeof(ViewDirectionNode));
var normalNode = new SerializationHelper.TypeSerializationInfo
{
fullName = "UnityEngine.MaterialGraph.NormalNode"
};
result[normalNode] = SerializationHelper.GetTypeSerializableAsString(typeof(NormalVectorNode));
var worldPosNode = new SerializationHelper.TypeSerializationInfo
{
fullName = "UnityEngine.MaterialGraph.WorldPosNode"
};
result[worldPosNode] = SerializationHelper.GetTypeSerializableAsString(typeof(PositionNode));
var sampleTexture2DNode = new SerializationHelper.TypeSerializationInfo
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
fullName = "UnityEditor.ShaderGraph.Texture2DNode"
};
result[sampleTexture2DNode] = SerializationHelper.GetTypeSerializableAsString(typeof(SampleTexture2DNode));
foreach (var type in assembly.GetTypes())
{
if (type.IsAbstract)
continue;
foreach (var attribute in type.GetCustomAttributes(typeof(LegacyAttribute), false))
{
var legacyAttribute = (LegacyAttribute)attribute;
var serializationInfo = new SerializationHelper.TypeSerializationInfo { fullName = legacyAttribute.fullName };
result[serializationInfo] = SerializationHelper.GetTypeSerializableAsString(type);
}
var sampleCubemapNode = new SerializationHelper.TypeSerializationInfo
{
fullName = "UnityEditor.ShaderGraph.CubemapNode"
};
result[sampleCubemapNode] = SerializationHelper.GetTypeSerializableAsString(typeof(SampleCubemapNode));
}
}
return result;
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/NormalVectorNode.cs


namespace UnityEditor.ShaderGraph
{
[Legacy("UnityEngine.MaterialGraph.NormalNode")]
[Title("Input", "Geometry", "Normal Vector")]
public class NormalVectorNode : GeometryNode, IMayRequireNormal
{

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/PositionNode.cs


namespace UnityEditor.ShaderGraph
{
[Legacy("UnityEngine.MaterialGraph.WorldPosNode")]
[Title("Input", "Geometry", "Position")]
public class PositionNode : GeometryNode, IMayRequirePosition
{

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ViewDirectionNode.cs


namespace UnityEditor.ShaderGraph
{
[Legacy("UnityEngine.MaterialGraph.ViewDirectionNode")]
[Title("Input", "Geometry", "View Direction")]
public class ViewDirectionNode : GeometryNode, IMayRequireViewDirection
{

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/SampleCubemapNode.cs


namespace UnityEditor.ShaderGraph
{
[Legacy("UnityEditor.ShaderGraph.CubemapNode")]
[Title("Input", "Texture", "Sample Cubemap")]
public class SampleCubemapNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireViewDirection, IMayRequireNormal
{

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/SampleTexture2DNode.cs


Normal
};
[Legacy("UnityEditor.ShaderGraph.Texture2DNode")]
[Title("Input", "Texture", "Sample Texture 2D")]
public class SampleTexture2DNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
{

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/LegacyAttribute.cs


using System;
namespace UnityEditor.ShaderGraph
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class LegacyAttribute : Attribute
{
public string fullName { get; private set; }
public LegacyAttribute(string fullName)
{
this.fullName = fullName;
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/LegacyAttribute.cs.meta


fileFormatVersion: 2
guid: ae5b0289aecc42c2b6f5b5b08b80bdd9
timeCreated: 1513592955
正在加载...
取消
保存