浏览代码
Change IGeneratesFunction such that a name is provided to a registry, which only allows 1 implementation per name. Includes a validation mode that checks that multiple given functions with the same name are actually the same.
/main
Change IGeneratesFunction such that a name is provided to a registry, which only allows 1 implementation per name. Includes a validation mode that checks that multiple given functions with the same name are actually the same.
/main
Peter Bay Bastian
7 年前
当前提交
41e06942
共有 20 个文件被更改,包括 249 次插入 和 129 次删除
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Interfaces/IGeneratesFunction.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs
-
25MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ChannelMixerNode.cs
-
51MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Mask/ChannelMaskNode.cs
-
28MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Normal/NormalCreateNode.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/FlipNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
-
72MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/FogNode.cs
-
19MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyByVectorNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Matrix/MatrixMultiplyNode.cs
-
15MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Procedural/Noise/SimpleNoiseNode.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Procedural/Noise/VoronoiNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraph.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/GraphUtil.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs
-
36MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderStringBuilder.cs
-
47MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/FunctionRegistry.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/FunctionRegistry.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public class FunctionRegistry |
|||
{ |
|||
Dictionary<string, string> m_Functions = new Dictionary<string, string>(); |
|||
ShaderStringBuilder m_StringBuilder = new ShaderStringBuilder(); |
|||
bool m_ValidationEnabled = false; |
|||
|
|||
public FunctionRegistry(int indentLevel = 0) |
|||
{ |
|||
for (var i = 0; i < indentLevel; i++) |
|||
m_StringBuilder.IncreaseIndent(); |
|||
} |
|||
|
|||
public bool ProvideFunction(string name, Action<ShaderStringBuilder> generator) |
|||
{ |
|||
string functionSource = string.Empty; |
|||
if (m_ValidationEnabled) |
|||
{ |
|||
var ssb = new ShaderStringBuilder(); |
|||
generator(ssb); |
|||
functionSource = ssb.ToString(); |
|||
} |
|||
|
|||
string existingFunctionSource; |
|||
if (m_Functions.TryGetValue(name, out existingFunctionSource)) |
|||
{ |
|||
if (m_ValidationEnabled && functionSource != existingFunctionSource) |
|||
Debug.LogErrorFormat(@"Function `{0}` has varying implementations:{1}{1}{2}{1}{1}{3}", name, Environment.NewLine, functionSource, existingFunctionSource); |
|||
return false; |
|||
} |
|||
generator(m_StringBuilder); |
|||
m_Functions.Add(name, functionSource); |
|||
m_StringBuilder.AppendNewLine(); |
|||
return true; |
|||
} |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return m_StringBuilder.ToString(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7e4fc6f4e30c408f9c0304cbed39a076 |
|||
timeCreated: 1513609614 |
撰写
预览
正在加载...
取消
保存
Reference in new issue