Peter Bay Bastian
7 年前
当前提交
e3aaf843
共有 7 个文件被更改,包括 237 次插入 和 268 次删除
-
206MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/AbstractMaterialGraphTests.cs
-
54MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/SerializedGraphTests.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/TestNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/TestNode.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/SerializableGraph/Implementation/SerializableNode.cs.meta
-
219MaterialGraphProject/Assets/UnityShaderEditor/Editor/SerializableGraph/Implementation/SerializableNode.cs
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public class TestNode : AbstractMaterialNode |
|||
{ |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5b3ff0f8519f4c0aa38ae4251a329e34 |
|||
timeCreated: 1513341923 |
|
|||
fileFormatVersion: 2 |
|||
guid: bd99903e0e5626448a8518284feeb047 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Graphing |
|||
{ |
|||
[Serializable] |
|||
public class SerializableNode : INode, ISerializationCallbackReceiver |
|||
{ |
|||
[NonSerialized] |
|||
private Guid m_Guid; |
|||
|
|||
[SerializeField] |
|||
private string m_GuidSerialized; |
|||
|
|||
[SerializeField] |
|||
private string m_Name; |
|||
|
|||
[SerializeField] |
|||
private DrawState m_DrawState; |
|||
|
|||
[NonSerialized] |
|||
private List<ISlot> m_Slots = new List<ISlot>(); |
|||
|
|||
[SerializeField] |
|||
List<SerializationHelper.JSONSerializedElement> m_SerializableSlots = new List<SerializationHelper.JSONSerializedElement>(); |
|||
|
|||
public IGraph owner { get; set; } |
|||
|
|||
public Guid guid |
|||
{ |
|||
get { return m_Guid; } |
|||
} |
|||
|
|||
public string name |
|||
{ |
|||
get { return m_Name; } |
|||
set { m_Name = value; } |
|||
} |
|||
|
|||
public virtual bool canDeleteNode |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
public DrawState drawState |
|||
{ |
|||
get { return m_DrawState; } |
|||
set |
|||
{ |
|||
m_DrawState = value; |
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
|
|||
public virtual bool hasError { get; protected set; } |
|||
|
|||
public SerializableNode() |
|||
{ |
|||
m_DrawState.expanded = true; |
|||
m_Guid = Guid.NewGuid(); |
|||
} |
|||
|
|||
public Guid RewriteGuid() |
|||
{ |
|||
m_Guid = Guid.NewGuid(); |
|||
return m_Guid; |
|||
} |
|||
|
|||
public virtual void ValidateNode() |
|||
{} |
|||
|
|||
public OnNodeModified onModified { get; set; } |
|||
|
|||
public void GetInputSlots<T>(List<T> foundSlots) where T : ISlot |
|||
{ |
|||
foreach (var slot in m_Slots) |
|||
{ |
|||
if (slot.isInputSlot && slot is T) |
|||
foundSlots.Add((T)slot); |
|||
} |
|||
} |
|||
|
|||
public void GetOutputSlots<T>(List<T> foundSlots) where T : ISlot |
|||
{ |
|||
foreach (var slot in m_Slots) |
|||
{ |
|||
if (slot.isOutputSlot && slot is T) |
|||
foundSlots.Add((T)slot); |
|||
} |
|||
} |
|||
|
|||
public void GetSlots<T>(List<T> foundSlots) where T : ISlot |
|||
{ |
|||
foreach (var slot in m_Slots) |
|||
{ |
|||
if (slot is T) |
|||
foundSlots.Add((T)slot); |
|||
} |
|||
} |
|||
|
|||
public virtual void AddSlot(ISlot slot) |
|||
{ |
|||
if (slot == null) |
|||
return; |
|||
|
|||
m_Slots.RemoveAll(x => x.id == slot.id); |
|||
m_Slots.Add(slot); |
|||
slot.owner = this; |
|||
|
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Topological); |
|||
} |
|||
} |
|||
|
|||
public void RemoveSlot(int slotId) |
|||
{ |
|||
// Remove edges that use this slot
|
|||
// no owner can happen after creation
|
|||
// but before added to graph
|
|||
if (owner != null) |
|||
{ |
|||
var edges = owner.GetEdges(GetSlotReference(slotId)); |
|||
|
|||
foreach (var edge in edges.ToArray()) |
|||
owner.RemoveEdge(edge); |
|||
} |
|||
|
|||
//remove slots
|
|||
m_Slots.RemoveAll(x => x.id == slotId); |
|||
|
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Topological); |
|||
} |
|||
} |
|||
|
|||
public void RemoveSlotsNameNotMatching(IEnumerable<int> slotIds, bool supressWarnings = false) |
|||
{ |
|||
var invalidSlots = m_Slots.Select(x => x.id).Except(slotIds); |
|||
|
|||
foreach (var invalidSlot in invalidSlots.ToArray()) |
|||
{ |
|||
if (!supressWarnings) |
|||
Debug.LogWarningFormat("Removing Invalid MaterialSlot: {0}", invalidSlot); |
|||
RemoveSlot(invalidSlot); |
|||
} |
|||
} |
|||
|
|||
public SlotReference GetSlotReference(int slotId) |
|||
{ |
|||
var slot = FindSlot<ISlot>(slotId); |
|||
if (slot == null) |
|||
throw new ArgumentException("Slot could not be found", "slotId"); |
|||
return new SlotReference(guid, slotId); |
|||
} |
|||
|
|||
public T FindSlot<T>(int slotId) where T : ISlot |
|||
{ |
|||
foreach (var slot in m_Slots) |
|||
{ |
|||
if (slot.id == slotId && slot is T) |
|||
return (T)slot; |
|||
} |
|||
return default(T); |
|||
} |
|||
|
|||
public T FindInputSlot<T>(int slotId) where T : ISlot |
|||
{ |
|||
foreach (var slot in m_Slots) |
|||
{ |
|||
if (slot.isInputSlot && slot.id == slotId && slot is T) |
|||
return (T)slot; |
|||
} |
|||
return default(T); |
|||
} |
|||
|
|||
public T FindOutputSlot<T>(int slotId) where T : ISlot |
|||
{ |
|||
foreach (var slot in m_Slots) |
|||
{ |
|||
if (slot.isOutputSlot && slot.id == slotId && slot is T) |
|||
return (T)slot; |
|||
} |
|||
return default(T); |
|||
} |
|||
|
|||
public virtual IEnumerable<ISlot> GetInputsWithNoConnection() |
|||
{ |
|||
return this.GetInputSlots<ISlot>().Where(x => !owner.GetEdges(GetSlotReference(x.id)).Any()); |
|||
} |
|||
|
|||
public virtual void OnBeforeSerialize() |
|||
{ |
|||
m_GuidSerialized = m_Guid.ToString(); |
|||
m_SerializableSlots = SerializationHelper.Serialize<ISlot>(m_Slots); |
|||
} |
|||
|
|||
public virtual void OnAfterDeserialize() |
|||
{ |
|||
if (!string.IsNullOrEmpty(m_GuidSerialized)) |
|||
m_Guid = new Guid(m_GuidSerialized); |
|||
else |
|||
m_Guid = Guid.NewGuid(); |
|||
|
|||
m_Slots = SerializationHelper.Deserialize<ISlot>(m_SerializableSlots, null); |
|||
m_SerializableSlots = null; |
|||
foreach (var s in m_Slots) |
|||
s.owner = this; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public virtual void UpdateNodeAfterDeserialization() |
|||
{} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue