浏览代码

[material graph]Slot serialization test

/main
Tim Cooper 8 年前
当前提交
8e31ace1
共有 2 个文件被更改,包括 37 次插入10 次删除
  1. 34
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/IntegrationTests/SerializationTests.cs
  2. 13
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableSlot.cs

34
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Testing/IntegrationTests/SerializationTests.cs


using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;

{
[SerializeField]
public string stringValue;
[SerializeField]
public int[] arrayValue;

{
SimpleSerializeClass.instance
};
var serialized = SerializationHelper.Serialize(toSerialize);
Assert.AreEqual(1, serialized.Count);

Assert.IsInstanceOf<SimpleSerializeClass>(loaded[0]);
loaded[0].AssertAsReference();
}
[Test]
public void TestSerializableSlotCanSerialize()
{
var toSerialize = new List<SerializableSlot>()
{
new SerializableSlot("InSlot", "InSlot", SlotType.Input, 0),
new SerializableSlot("OutSlot", "OutSlot", SlotType.Output, 0),
};
var serialized = SerializationHelper.Serialize(toSerialize);
var loaded = SerializationHelper.Deserialize<SerializableSlot>(serialized);
Assert.AreEqual(2, loaded.Count);
Assert.IsInstanceOf<SerializableSlot>(loaded[0]);
Assert.IsInstanceOf<SerializableSlot>(loaded[1]);
Assert.AreEqual("InSlot", loaded[0].name);
Assert.AreEqual("InSlot", loaded[0].displayName);
Assert.IsTrue(loaded[0].isInputSlot);
Assert.AreEqual(0, loaded[0].priority);
Assert.AreEqual("OutSlot", loaded[1].name);
Assert.AreEqual("OutSlot", loaded[1].displayName);
Assert.IsTrue(loaded[1].isOutputSlot);
Assert.AreEqual(0, loaded[1].priority);
}
}
}

13
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableSlot.cs


using System;
using System.Runtime.InteropServices;
namespace UnityEngine.Graphing
{

private string m_DisplayName = kNotInit;
[SerializeField]
private SlotType m_SlotType;
private SlotType m_SlotType = SlotType.Input;
[SerializeField]
private int m_Priority;

get { return m_Priority; }
set { m_Priority = value; }
}
// used via reflection / serialization after deserialize
// to reconstruct this slot.
public SerializableSlot()
{ }
public SerializableSlot(string name, string displayName, SlotType slotType, int priority)
{

m_Priority = priority;
}
// used via reflection / serialization after deserialize
// to reconstruct this slot.
protected SerializableSlot()
{}
public virtual bool OnGUI()
{

正在加载...
取消
保存