Tim Cooper
8 年前
当前提交
0e9ee494
共有 49 个文件被更改,包括 1047 次插入 和 472 次删除
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs
-
4MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/UnitTests/SerializedGraphTests.cs
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Assets/SerializableGraphAsset.cs
-
21MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs
-
25MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/ColorNodeUI.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/CombineNodeUI.cs
-
20MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/PixelShaderNodeUI.cs
-
14MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphIONodeUI.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/SubGraphNodeUI.cs
-
13MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/TextureNodeUI.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector1NodeUI.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector2NodeUI.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector3NodeUI.cs
-
14MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/Vector4NodeUI.cs
-
149MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs
-
39MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ColorNode.cs
-
60MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs
-
18MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector1Node.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector2Node.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector3Node.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Vector4Node.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ViewDirectionNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraph.cs
-
209MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
-
170MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/FixedSlotTests.cs
-
150MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs
-
118MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs.meta
-
38MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs.meta
-
30MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs.meta
-
27MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyChunk.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyChunk.cs.meta
-
58MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs.meta
-
58MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TexturePropertyChunk.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TexturePropertyChunk.cs.meta
-
10MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TextureType.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/TextureType.cs.meta
-
38MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/VectorPropertyChunk.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/VectorPropertyChunk.cs.meta
|
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.UnitTests |
|||
{ |
|||
[TestFixture] |
|||
public class FixedSlotTests |
|||
{ |
|||
private PixelGraph m_Graph; |
|||
private TestNode m_NodeA; |
|||
private TestNode m_NodeB; |
|||
|
|||
class TestNode : AbstractMaterialNode |
|||
{ |
|||
public const int V1Out = 0; |
|||
public const int V2Out = 1; |
|||
public const int V3Out = 2; |
|||
public const int V4Out = 3; |
|||
|
|||
|
|||
public const int V1In = 4; |
|||
public const int V2In = 5; |
|||
public const int V3In = 6; |
|||
public const int V4In = 7; |
|||
|
|||
public TestNode() |
|||
{ |
|||
AddSlot(new MaterialSlot(V1Out, "V1Out", "V1Out", SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(V2Out, "V2Out", "V2Out", SlotType.Output, SlotValueType.Vector2, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(V3Out, "V3Out", "V3Out", SlotType.Output, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(V4Out, "V4Out", "V4Out", SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
|
|||
AddSlot(new MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(V2In, "V2In", "V2In", SlotType.Input, SlotValueType.Vector2, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(V3In, "V3In", "V3In", SlotType.Input, SlotValueType.Vector3, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(V4In, "V4In", "V4In", SlotType.Input, SlotValueType.Vector4, Vector4.zero)); |
|||
} |
|||
} |
|||
|
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
[SetUp] |
|||
public void TestSetUp() |
|||
{ |
|||
m_Graph = new PixelGraph(); |
|||
m_NodeA = new TestNode(); |
|||
m_NodeB = new TestNode(); |
|||
m_Graph.AddNode(m_NodeA); |
|||
m_Graph.AddNode(m_NodeB); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV1ToV1Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V1In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV1ToV2Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V2In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV1ToV3Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V3In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV1ToV4Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V1Out), m_NodeB.GetSlotReference(TestNode.V4In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV2ToV1Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V1In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV2ToV2Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V2In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV2ToV3Fails() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V3In)); |
|||
Assert.IsTrue(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV2ToV4Fails() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V2Out), m_NodeB.GetSlotReference(TestNode.V4In)); |
|||
Assert.IsTrue(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV3ToV1Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V1In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV3ToV2Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V2In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV3ToV3Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V3In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV3ToV4Fails() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V3Out), m_NodeB.GetSlotReference(TestNode.V4In)); |
|||
Assert.IsTrue(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV4ToV1Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V1In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV4ToV2Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V2In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV4ToV3Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V3In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConnectV4ToV4Works() |
|||
{ |
|||
m_Graph.Connect(m_NodeA.GetSlotReference(TestNode.V4Out), m_NodeB.GetSlotReference(TestNode.V4In)); |
|||
Assert.IsFalse(m_NodeB.hasError); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Linq; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.UnitTests |
|||
{ |
|||
[TestFixture] |
|||
public class MaterialSlotTests |
|||
{ |
|||
private PixelGraph m_Graph; |
|||
private TestNode m_NodeA; |
|||
|
|||
class TestNode : AbstractMaterialNode |
|||
{ |
|||
public const int V1In = 1; |
|||
|
|||
public readonly MaterialSlot slot; |
|||
|
|||
public TestNode() |
|||
{ |
|||
slot = new MaterialSlot(V1In, "V1In", "V1In", SlotType.Input, SlotValueType.Vector1, Vector4.zero); |
|||
AddSlot(slot); |
|||
} |
|||
} |
|||
|
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
[SetUp] |
|||
public void TestSetUp() |
|||
{ |
|||
m_Graph = new PixelGraph(); |
|||
m_NodeA = new TestNode(); |
|||
m_Graph.AddNode(m_NodeA); |
|||
} |
|||
|
|||
[Test] |
|||
public void CanUpdateMaterialSlotDisplayName() |
|||
{ |
|||
var displayName = "New Display Name"; |
|||
|
|||
var slot = m_NodeA.slot; |
|||
slot.displayName = displayName; |
|||
|
|||
slot.valueType = SlotValueType.Vector1; |
|||
Assert.AreEqual(displayName + "(1)", slot.displayName); |
|||
|
|||
slot.valueType = SlotValueType.Vector2; |
|||
Assert.AreEqual(displayName + "(2)", slot.displayName); |
|||
|
|||
slot.valueType = SlotValueType.Vector3; |
|||
Assert.AreEqual(displayName + "(3)", slot.displayName); |
|||
|
|||
slot.valueType = SlotValueType.Vector4; |
|||
Assert.AreEqual(displayName + "(4)", slot.displayName); |
|||
|
|||
slot.valueType = SlotValueType.Dynamic; |
|||
Assert.AreEqual(displayName + "(4)", slot.displayName); |
|||
} |
|||
|
|||
[Test] |
|||
public void CanUpdateMaterialSlotDefaultValue() |
|||
{ |
|||
var slot = m_NodeA.slot; |
|||
slot.defaultValue = Vector4.one; |
|||
Assert.AreEqual(Vector4.one, slot.defaultValue); |
|||
} |
|||
|
|||
[Test] |
|||
public void CanUpdateMaterialSlotCurrentValue() |
|||
{ |
|||
var slot = m_NodeA.slot; |
|||
slot.currentValue = Vector4.one; |
|||
Assert.AreEqual(Vector4.one, slot.currentValue); |
|||
} |
|||
|
|||
[Test] |
|||
public void CanUpdateMaterialSlotValueType() |
|||
{ |
|||
var slot = m_NodeA.slot; |
|||
slot.valueType = SlotValueType.Vector3; |
|||
Assert.AreEqual(SlotValueType.Vector3, slot.valueType); |
|||
} |
|||
|
|||
[Test] |
|||
public void CanUpdateMaterialShaderOutputName() |
|||
{ |
|||
var shaderName = "NewShaderOutputName"; |
|||
|
|||
var slot = m_NodeA.slot; |
|||
slot.shaderOutputName = shaderName; |
|||
Assert.AreEqual(shaderName, slot.shaderOutputName); |
|||
} |
|||
|
|||
[Test] |
|||
public void MaterialSlotCanGeneratePropertyUsagesForPreview() |
|||
{ |
|||
string expected = string.Format("{0} {1};\r\n", m_NodeA.precision, m_NodeA.GetVariableNameForSlot(TestNode.V1In)); |
|||
|
|||
var slot = m_NodeA.slot; |
|||
var visitor = new ShaderGenerator(); |
|||
slot.GeneratePropertyUsages(visitor, GenerationMode.Preview2D); |
|||
Assert.AreEqual(expected, visitor.GetShaderString(0)); |
|||
} |
|||
|
|||
[Test] |
|||
public void MaterialSlotReturnsValidDefaultValue() |
|||
{ |
|||
string expected = string.Format("{0}", m_NodeA.GetVariableNameForSlot(TestNode.V1In)); |
|||
|
|||
var slot = m_NodeA.slot; |
|||
var result = slot.GetDefaultValue(GenerationMode.Preview2D); |
|||
Assert.AreEqual(expected, result); |
|||
|
|||
slot.valueType = SlotValueType.Vector1; |
|||
slot.currentValue = new Vector4(6, 6, 6, 1); |
|||
result = slot.GetDefaultValue(GenerationMode.SurfaceShader); |
|||
Assert.AreEqual("6", result); |
|||
|
|||
slot.valueType = SlotValueType.Vector2; |
|||
slot.currentValue = new Vector4(6, 6, 6, 1); |
|||
result = slot.GetDefaultValue(GenerationMode.SurfaceShader); |
|||
Assert.AreEqual("half2 (6,6)", result); |
|||
|
|||
slot.valueType = SlotValueType.Vector3; |
|||
slot.currentValue = new Vector4(6, 6, 6, 1); |
|||
result = slot.GetDefaultValue(GenerationMode.SurfaceShader); |
|||
Assert.AreEqual("half3 (6,6,6)", result); |
|||
|
|||
slot.valueType = SlotValueType.Vector4; |
|||
slot.currentValue = new Vector4(6, 6, 6, 1); |
|||
result = slot.GetDefaultValue(GenerationMode.SurfaceShader); |
|||
Assert.AreEqual("half4 (6,6,6,1)", result); |
|||
} |
|||
|
|||
[Test] |
|||
public void MaterialSlotThrowsWhenNoOwner() |
|||
{ |
|||
var slot = new MaterialSlot(0, string.Empty, string.Empty, SlotType.Input, SlotValueType.Vector1, Vector4.zero); |
|||
Assert.Throws<Exception>(() => slot.GeneratePropertyUsages(new ShaderGenerator(), GenerationMode.Preview2D)); |
|||
Assert.Throws<Exception>(() => slot.GetDefaultValue(GenerationMode.Preview2D)); |
|||
} |
|||
} |
|||
} |
|
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.UnitTests |
|||
{ |
|||
[TestFixture] |
|||
public class PropertyChunkTests |
|||
{ |
|||
|
|||
class TestPropertyChunch : PropertyChunk |
|||
{ |
|||
public TestPropertyChunch(string propertyName, string propertyDescription, HideState hideState) |
|||
: base(propertyName, propertyDescription, hideState) |
|||
{} |
|||
|
|||
public override string GetPropertyString() |
|||
{ |
|||
return propertyName; |
|||
} |
|||
} |
|||
|
|||
[TestFixtureSetUp] |
|||
public void RunBeforeAnyTests() |
|||
{ |
|||
Debug.logger.logHandler = new ConsoleLogHandler(); |
|||
} |
|||
|
|||
[SetUp] |
|||
public void TestSetUp() |
|||
{ |
|||
|
|||
} |
|||
|
|||
private const string kPropertyName = "ThePropertyName"; |
|||
private const string kPropertyDescription = "ThePropertyDescription"; |
|||
|
|||
[Test] |
|||
public void TestSimplePropertyChunkIsConstructedProperly() |
|||
{ |
|||
var chunk = new TestPropertyChunch(kPropertyName, kPropertyDescription, PropertyChunk.HideState.Visible); |
|||
Assert.AreEqual(kPropertyName, chunk.propertyName); |
|||
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription); |
|||
Assert.AreEqual(kPropertyName, chunk.GetPropertyString()); |
|||
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestColorChunkReturnsValidValues() |
|||
{ |
|||
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", Color) = (1,0,0,1)"; |
|||
var chunk = new ColorPropertyChunk(kPropertyName, kPropertyDescription, Color.red, PropertyChunk.HideState.Visible); |
|||
Assert.AreEqual(kPropertyName, chunk.propertyName); |
|||
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription); |
|||
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString()); |
|||
Assert.AreEqual(Color.red, chunk.defaultColor); |
|||
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestFloatChunkReturnsValidValues() |
|||
{ |
|||
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", Float) = 0.5"; |
|||
var chunk = new FloatPropertyChunk(kPropertyName, kPropertyDescription, 0.5f, PropertyChunk.HideState.Visible); |
|||
Assert.AreEqual(kPropertyName, chunk.propertyName); |
|||
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription); |
|||
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString()); |
|||
Assert.AreEqual(0.5f, chunk.defaultValue); |
|||
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestVectorChunkReturnsValidValues() |
|||
{ |
|||
var vector = new Vector4(0.2f, 0.4f, 0.66f, 1.0f); |
|||
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", Vector) = (0.2,0.4,0.66,1)"; |
|||
var chunk = new VectorPropertyChunk(kPropertyName, kPropertyDescription, vector, PropertyChunk.HideState.Visible); |
|||
Assert.AreEqual(kPropertyName, chunk.propertyName); |
|||
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription); |
|||
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString()); |
|||
Assert.AreEqual(vector, chunk.defaultValue); |
|||
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestTextureChunkReturnsValidValues() |
|||
{ |
|||
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", 2D) = \"bump\" {}"; |
|||
var chunk = new TexturePropertyChunk(kPropertyName, kPropertyDescription, null, TextureType.Bump, PropertyChunk.HideState.Visible, TexturePropertyChunk.ModifiableState.Modifiable); |
|||
Assert.AreEqual(kPropertyName, chunk.propertyName); |
|||
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription); |
|||
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString()); |
|||
Assert.AreEqual(null, chunk.defaultTexture); |
|||
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestTexturePropertyChunkGeneratesValidPropertyStringVisibleNotModifiable() |
|||
{ |
|||
var expectedPropertyString = "[NonModifiableTextureData] ThePropertyName(\"ThePropertyDescription\", 2D) = \"gray\" {}"; |
|||
var chunk = new TexturePropertyChunk(kPropertyName, kPropertyDescription, null, TextureType.Gray, PropertyChunk.HideState.Visible, TexturePropertyChunk.ModifiableState.NonModifiable); |
|||
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString()); |
|||
Assert.AreEqual(TexturePropertyChunk.ModifiableState.NonModifiable, chunk.modifiableState); |
|||
Assert.AreEqual(PropertyChunk.HideState.Visible, chunk.hideState); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestTexturePropertyChunkGeneratesValidPropertyStringHiddenNotModifiable() |
|||
{ |
|||
var expectedPropertyString = "[HideInInspector] [NonModifiableTextureData] ThePropertyName(\"ThePropertyDescription\", 2D) = \"white\" {}"; |
|||
var chunk = new TexturePropertyChunk(kPropertyName, kPropertyDescription, null, TextureType.White, PropertyChunk.HideState.Hidden, TexturePropertyChunk.ModifiableState.NonModifiable); |
|||
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString()); |
|||
Assert.AreEqual(TexturePropertyChunk.ModifiableState.NonModifiable, chunk.modifiableState); |
|||
Assert.AreEqual(PropertyChunk.HideState.Hidden, chunk.hideState); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 816037e003cccbc4b8a61ec1bf91ab0c |
|||
timeCreated: 1469695793 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Text; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public class ColorPropertyChunk : PropertyChunk |
|||
{ |
|||
private Color m_DefaultColor; |
|||
|
|||
public ColorPropertyChunk(string propertyName, string propertyDescription, Color defaultColor, HideState hideState) |
|||
: base(propertyName, propertyDescription, hideState) |
|||
{ |
|||
m_DefaultColor = defaultColor; |
|||
} |
|||
|
|||
public Color defaultColor |
|||
{ |
|||
get { return m_DefaultColor; } |
|||
} |
|||
|
|||
public override string GetPropertyString() |
|||
{ |
|||
var result = new StringBuilder(); |
|||
result.Append(propertyName); |
|||
result.Append("(\""); |
|||
result.Append(propertyDescription); |
|||
result.Append("\", Color) = ("); |
|||
result.Append(defaultColor.r); |
|||
result.Append(","); |
|||
result.Append(defaultColor.g); |
|||
result.Append(","); |
|||
result.Append(defaultColor.b); |
|||
result.Append(","); |
|||
result.Append(defaultColor.a); |
|||
result.Append(")"); |
|||
return result.ToString(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c55a60f83c47c3940b74e5a1f53d69aa |
|||
timeCreated: 1469695793 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Text; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public class FloatPropertyChunk : PropertyChunk |
|||
{ |
|||
private readonly float m_DefaultValue; |
|||
public FloatPropertyChunk(string propertyName, string propertyDescription, float defaultValue, HideState hideState) |
|||
: base(propertyName, propertyDescription, hideState) |
|||
{ |
|||
m_DefaultValue = defaultValue; |
|||
} |
|||
|
|||
public float defaultValue |
|||
{ |
|||
get { return m_DefaultValue; } |
|||
} |
|||
|
|||
public override string GetPropertyString() |
|||
{ |
|||
var result = new StringBuilder(); |
|||
result.Append(propertyName); |
|||
result.Append("(\""); |
|||
result.Append(propertyDescription); |
|||
result.Append("\", Float) = "); |
|||
result.Append(defaultValue); |
|||
return result.ToString(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5165619d6635ec146aa7014ac39356cd |
|||
timeCreated: 1469695793 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public abstract class PropertyChunk |
|||
{ |
|||
public enum HideState |
|||
{ |
|||
Hidden, |
|||
Visible |
|||
} |
|||
|
|||
private readonly string m_PropertyName; |
|||
private readonly string m_PropertyDescription; |
|||
private readonly HideState m_HideState; |
|||
|
|||
protected PropertyChunk(string propertyName, string propertyDescription, HideState hideState) |
|||
{ |
|||
m_PropertyName = propertyName; |
|||
m_PropertyDescription = propertyDescription; |
|||
m_HideState = hideState; |
|||
} |
|||
|
|||
public abstract string GetPropertyString(); |
|||
public string propertyName { get { return m_PropertyName; } } |
|||
public string propertyDescription { get { return m_PropertyDescription; } } |
|||
public HideState hideState { get { return m_HideState; } } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e3bc93a0908e88743a7f24757b2a85f4 |
|||
timeCreated: 1469695793 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public class PropertyGenerator |
|||
{ |
|||
public struct TextureInfo |
|||
{ |
|||
public string name; |
|||
public int textureId; |
|||
public TexturePropertyChunk.ModifiableState modifiable; |
|||
} |
|||
|
|||
private readonly List<PropertyChunk> m_Properties = new List<PropertyChunk>(); |
|||
|
|||
public void AddShaderProperty(PropertyChunk chunk) |
|||
{ |
|||
m_Properties.Add(chunk); |
|||
} |
|||
|
|||
public string GetShaderString(int baseIndentLevel) |
|||
{ |
|||
var sb = new StringBuilder(); |
|||
foreach (var prop in m_Properties) |
|||
{ |
|||
for (var i = 0; i < baseIndentLevel; i++) |
|||
{ |
|||
sb.Append("\t"); |
|||
} |
|||
sb.Append(prop.GetPropertyString()); |
|||
sb.Append("\n"); |
|||
} |
|||
return sb.ToString(); |
|||
} |
|||
|
|||
public List<TextureInfo> GetConfiguredTexutres() |
|||
{ |
|||
var result = new List<TextureInfo>(); |
|||
|
|||
foreach (var prop in m_Properties.OfType<TexturePropertyChunk>()) |
|||
{ |
|||
if (prop.propertyName != null) |
|||
{ |
|||
var textureInfo = new TextureInfo |
|||
{ |
|||
name = prop.propertyName, |
|||
textureId = prop.defaultTexture != null ? prop.defaultTexture.GetInstanceID() : 0, |
|||
modifiable = prop.modifiableState |
|||
}; |
|||
result.Add(textureInfo); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ca768a19c7caa844c83fceae4a411f04 |
|||
timeCreated: 1469695793 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Text; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public class TexturePropertyChunk : PropertyChunk |
|||
{ |
|||
public enum ModifiableState |
|||
{ |
|||
Modifiable, |
|||
NonModifiable |
|||
} |
|||
|
|||
private readonly Texture m_DefaultTexture; |
|||
private readonly TextureType m_DefaultTextureType; |
|||
private readonly ModifiableState m_Modifiable; |
|||
|
|||
public TexturePropertyChunk(string propertyName, string propertyDescription, Texture defaultTexture, TextureType defaultTextureType, HideState hidden, ModifiableState modifiableState) |
|||
: base(propertyName, propertyDescription, hidden) |
|||
{ |
|||
m_DefaultTexture = defaultTexture; |
|||
m_DefaultTextureType = defaultTextureType; |
|||
m_Modifiable = modifiableState; |
|||
} |
|||
|
|||
public override string GetPropertyString() |
|||
{ |
|||
var result = new StringBuilder(); |
|||
if (hideState == HideState.Hidden) |
|||
result.Append("[HideInInspector] "); |
|||
if (m_Modifiable == ModifiableState.NonModifiable) |
|||
result.Append("[NonModifiableTextureData] "); |
|||
|
|||
result.Append(propertyName); |
|||
result.Append("(\""); |
|||
result.Append(propertyDescription); |
|||
result.Append("\", 2D) = \""); |
|||
result.Append(Enum.GetName(typeof(TextureType), m_DefaultTextureType).ToLower()); |
|||
result.Append("\" {}"); |
|||
return result.ToString(); |
|||
} |
|||
|
|||
public Texture defaultTexture |
|||
{ |
|||
get |
|||
{ |
|||
return m_DefaultTexture; |
|||
} |
|||
} |
|||
public ModifiableState modifiableState |
|||
{ |
|||
get |
|||
{ |
|||
return m_Modifiable; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2ac615170ebfd804eb0e5dbd753d73e9 |
|||
timeCreated: 1469695793 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public enum TextureType |
|||
{ |
|||
White, |
|||
Gray, |
|||
Black, |
|||
Bump |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 70e84ad0d8e6f4947a8e6aa53984bf2a |
|||
timeCreated: 1469695793 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Text; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public class VectorPropertyChunk : PropertyChunk |
|||
{ |
|||
private readonly Vector4 m_DefaultVector; |
|||
|
|||
public VectorPropertyChunk(string propertyName, string propertyDescription, Vector4 defaultVector, HideState hideState) |
|||
: base(propertyName, propertyDescription, hideState) |
|||
{ |
|||
m_DefaultVector = defaultVector; |
|||
} |
|||
|
|||
public Vector4 defaultValue |
|||
{ |
|||
get { return m_DefaultVector; } |
|||
} |
|||
|
|||
public override string GetPropertyString() |
|||
{ |
|||
var result = new StringBuilder(); |
|||
result.Append(propertyName); |
|||
result.Append("(\""); |
|||
result.Append(propertyDescription); |
|||
result.Append("\", Vector) = ("); |
|||
result.Append(defaultValue.x); |
|||
result.Append(","); |
|||
result.Append(defaultValue.y); |
|||
result.Append(","); |
|||
result.Append(defaultValue.z); |
|||
result.Append(","); |
|||
result.Append(defaultValue.w); |
|||
result.Append(")"); |
|||
return result.ToString(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f215325849c67a741994a3bade6cdda6 |
|||
timeCreated: 1469695793 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue