浏览代码

[Material graph]More tests + fixes along the way.

/main
Tim Cooper 9 年前
当前提交
327231db
共有 4 个文件被更改,包括 90 次插入39 次删除
  1. 22
      UnityProject/Assets/UnityShaderEditor/Editor/Source/SerializableGraph/SerializableNode.cs
  2. 7
      UnityProject/Assets/UnityShaderEditor/Editor/Source/SerializableGraph/SerializableSlot.cs
  3. 92
      UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/SerializedGraphTests.cs
  4. 8
      UnityProject/Assets/UnityShaderEditor/Editor/Source/SerializableGraph/SlotType.cs

22
UnityProject/Assets/UnityShaderEditor/Editor/Source/SerializableGraph/SerializableNode.cs


if (slot == null)
return;
// new MaterialSlot, just add it, we cool
if (!m_Slots.Contains(slot))
{
m_Slots.Add(slot);
return;
}
// old Slot found
// update the default value, and the slotType!
var foundSlots = m_Slots.FindAll(x => x.name == slot.name);
// if we are in a bad state (> 1 slot with same name).
// or our types are differernt now
// reset the slot to the new value
if (foundSlots.Count > 1 || foundSlots[0].GetType() != slot.GetType())
{
Debug.LogWarningFormat("Node {0} has more than one MaterialSlot with the same name, removing.");
m_Slots.RemoveAll(x => x.name == slot.name);
m_Slots.Add(slot);
}
m_Slots.RemoveAll(x => x.name == slot.name);
m_Slots.Add(slot);
}
public void RemoveSlot(string name)

7
UnityProject/Assets/UnityShaderEditor/Editor/Source/SerializableGraph/SerializableSlot.cs


public string displayName
{
get { return m_DisplayName; }
set { m_DisplayName = value; }
}
public bool isInputSlot

{
return false;
}
}
public enum SlotType
{
Input,
Output
}
}

92
UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/SerializedGraphTests.cs


using System;
using System.Linq;
using NUnit.Framework;
using UnityEngine;

}
[Test]
public void TestCreate()
public void TestCanCreateSerializableGraph()
{
var graph = new SerializableGraph();

[Test]
public void TestAddNode()
public void TestCanAddNodeToSerializableGraph()
{
var graph = new SerializableGraph();
var node = new SerializableNode(graph);

}
[Test]
public void TestAddSlot()
public void TestCanFindNodeInSerializableGraph()
{
var graph = new SerializableGraph();
var node = new SerializableNode(graph);
graph.AddNode(node);
Assert.AreEqual(1, graph.nodes.Count());
Assert.IsNotNull(graph.GetNodeFromGuid(node.guid));
Assert.IsNull(graph.GetNodeFromGuid(Guid.NewGuid()));
}
[Test]
public void TestCanAddSlotToSerializableNode()
{
var graph = new SerializableGraph();
var node = new SerializableNode(graph);

Assert.AreEqual(1, graph.nodes.Count());
var found = graph.nodes.FirstOrDefault();
Assert.AreEqual(found.inputSlots.Count(), 1);
Assert.AreEqual(found.outputSlots.Count(), 1);
Assert.AreEqual(found.slots.Count(), 2);
Assert.AreEqual(1, found.inputSlots.Count());
Assert.AreEqual("input", found.outputSlots.FirstOrDefault().name);
Assert.AreEqual(1, found.outputSlots.Count());
Assert.AreEqual("output", found.outputSlots.FirstOrDefault().name);
Assert.AreEqual(2, found.slots.Count());
public void TestCanConnectAndTraverseTwoNodes()
public void TestCanNotAddDuplicateSlotToSerializableNode()
{
var graph = new SerializableGraph();
var node = new SerializableNode(graph);
node.AddSlot(new SerializableSlot(node, "output", "output", SlotType.Output));
node.AddSlot(new SerializableSlot(node, "output", "output", SlotType.Output));
node.name = "Test Node";
graph.AddNode(node);
Assert.AreEqual(1, graph.nodes.Count());
var found = graph.nodes.FirstOrDefault();
Assert.AreEqual(0, found.inputSlots.Count());
Assert.AreEqual(1, found.outputSlots.Count());
Assert.AreEqual(1, found.slots.Count());
}
[Test]
public void TestCanUpdateDisplaynameByReaddingSlotToSerializableNode()
{
var graph = new SerializableGraph();
var node = new SerializableNode(graph);
node.AddSlot(new SerializableSlot(node, "output", "output", SlotType.Output));
node.AddSlot(new SerializableSlot(node, "output", "output_updated", SlotType.Output));
node.name = "Test Node";
graph.AddNode(node);
Assert.AreEqual(1, graph.nodes.Count());
var found = graph.nodes.FirstOrDefault();
Assert.AreEqual(0 ,found.inputSlots.Count());
Assert.AreEqual(1, found.outputSlots.Count());
Assert.AreEqual(1, found.slots.Count());
var slot = found.outputSlots.FirstOrDefault();
Assert.AreEqual("output_updated", slot.displayName);
}
[Test]
public void TestCanFindSlotOnSerializableNode()
{
var node = new SerializableNode(null);
node.AddSlot(new SerializableSlot(node, "output", "output", SlotType.Output));
node.AddSlot(new SerializableSlot(node, "input", "input", SlotType.Input));
Assert.AreEqual(2, node.slots.Count());
Assert.IsNotNull(node.FindInputSlot("input"));
Assert.IsNull(node.FindInputSlot("output"));
Assert.IsNotNull(node.FindOutputSlot("output"));
Assert.IsNull(node.FindOutputSlot("input"));
}
[Test]
public void TestCanConnectAndTraverseTwoNodesOnSerializableGraph()
{
var graph = new SerializableGraph();
var outputNode = new SerializableNode(graph);

var foundOutputNode = graph.GetNodeFromGuid(edge.outputSlot.nodeGuid);
var foundOutputSlot = foundOutputNode.FindOutputSlot(edge.outputSlot.slotName);
Assert.AreEqual(foundOutputNode, outputNode);
Assert.AreEqual(foundOutputSlot, outputSlot);
Assert.AreEqual(outputNode, foundOutputNode);
Assert.AreEqual(outputSlot, foundOutputSlot);
Assert.AreEqual(foundInputNode, inputNode);
Assert.AreEqual(foundInputSlot, inputSlot);
Assert.AreEqual(inputNode, foundInputNode);
Assert.AreEqual(inputSlot, foundInputSlot);
public void TestCanNotConnectTwoOuputSlots()
public void TestCanNotConnectTwoOuputSlotsOnSerializableGraph()
{
var graph = new SerializableGraph();
var outputNode = new SerializableNode(graph);

}
[Test]
public void TestCanNotConnectTwoInputSlots()
public void TestCanNotConnectTwoInputSlotsOnSerializableGraph()
{
var graph = new SerializableGraph();
var inputNode = new SerializableNode(graph);

8
UnityProject/Assets/UnityShaderEditor/Editor/Source/SerializableGraph/SlotType.cs


namespace UnityEditor.MaterialGraph
{
public enum SlotType
{
Input,
Output
}
}
正在加载...
取消
保存