浏览代码

Fix node compatibility check (#58)

/main
Peter Bay Bastian 7 年前
当前提交
fbc6eeac
共有 2 个文件被更改,包括 47 次插入8 次删除
  1. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  2. 42
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialSlot.cs

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


public override List<NodeAnchorPresenter> GetCompatibleAnchors(NodeAnchorPresenter startAnchor, NodeAdapter nodeAdapter)
{
return allChildren.OfType<NodeAnchorPresenter>()
.Where(nap => nap.IsConnectable() &&
nap.orientation == startAnchor.orientation &&
nap.direction != startAnchor.direction &&
nodeAdapter.GetAdapter(nap.source, startAnchor.source) != null &&
(startAnchor is GraphAnchorPresenter && ((GraphAnchorPresenter)nap).slot is MaterialSlot &&
((MaterialSlot)((GraphAnchorPresenter)startAnchor).slot).IsCompatibleWithInputSlotType(((MaterialSlot)((GraphAnchorPresenter)nap).slot).valueType)))
.Where(nap =>
nap.IsConnectable()
&& nap.orientation == startAnchor.orientation
&& nap.direction != startAnchor.direction
&& nodeAdapter.GetAdapter(nap.source, startAnchor.source) != null && startAnchor is GraphAnchorPresenter && ((GraphAnchorPresenter)nap).slot is MaterialSlot
&& ((GraphAnchorPresenter)startAnchor).slot.owner != ((GraphAnchorPresenter)nap).slot.owner
&& ((MaterialSlot)((GraphAnchorPresenter)startAnchor).slot).IsCompatibleWithInputSlotType(((MaterialSlot)((GraphAnchorPresenter)nap).slot).valueType))
.ToList();
}

42
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialSlot.cs


[SerializeField]
private string m_ShaderOutputName;
public MaterialSlot() {}
public MaterialSlot() { }
public MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue, bool hidden = false)
: base(slotId, displayName, slotType, hidden)

public bool IsCompatibleWithInputSlotType(SlotValueType inputType)
{
return (inputType == SlotValueType.Dynamic || valueType == SlotValueType.Vector1 || valueType <= inputType);
switch (valueType)
{
case SlotValueType.SamplerState:
return inputType == SlotValueType.SamplerState;
case SlotValueType.Matrix4:
return inputType == SlotValueType.Matrix4
|| inputType == SlotValueType.Matrix3
|| inputType == SlotValueType.Matrix2;
case SlotValueType.Matrix3:
return inputType == SlotValueType.Matrix3
|| inputType == SlotValueType.Matrix2;
case SlotValueType.Matrix2:
return inputType == SlotValueType.Matrix2;
case SlotValueType.Texture2D:
return inputType == SlotValueType.Texture2D;
case SlotValueType.Vector4:
return inputType == SlotValueType.Vector4
|| inputType == SlotValueType.Vector3
|| inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
case SlotValueType.Vector3:
return inputType == SlotValueType.Vector3
|| inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
case SlotValueType.Vector2:
return inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
case SlotValueType.Dynamic:
case SlotValueType.Vector1:
return inputType == SlotValueType.Vector4
|| inputType == SlotValueType.Vector3
|| inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
}
return false;
}
public string GetDefaultValue(GenerationMode generationMode)

正在加载...
取消
保存