浏览代码

Add support for setting default input values on material sub graphs (when editing the graph) so there is something to compare with.

/main
Tim Cooper 8 年前
当前提交
17429180
共有 17 个文件被更改,包括 323 次插入62 次删除
  1. 26
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeInspectors/BasicNodeInspector.cs
  2. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
  3. 10
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs
  4. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphInspector.cs
  5. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
  7. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapInputNode.cs
  8. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphInputNode.cs
  9. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphOutputNode.cs
  10. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SubgraphIONodeDrawData.cs
  11. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SubgraphIONodeDrawData.cs.meta
  12. 85
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphInputNodeInspector.cs
  13. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphInputNodeInspector.cs.meta
  14. 76
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphOutputNodeInspector.cs
  15. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphOutputNodeInspector.cs.meta
  16. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z
  17. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z.meta

26
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeInspectors/BasicNodeInspector.cs


public override void OnInspectorGUI()
{
GUILayout.Label(node.name, EditorStyles.boldLabel);
var slots = node.GetInputSlots<MaterialSlot>().Where(x => x.showValue);
var scope = DoSlotsUI();
if (scope == ModificationScope.Graph || scope == ModificationScope.Topological)
node.owner.ValidateGraph();
if (node.onModified != null)
node.onModified(node, scope);
}
protected virtual ModificationScope DoSlotsUI()
{
var slots = node.GetSlots<MaterialSlot>().Where(x => x.showValue);
return;
return ModificationScope.Nothing;
EditorGUI.BeginChangeCheck();
EditorGUI.BeginChangeCheck();
foreach (var slot in node.GetInputSlots<MaterialSlot>().Where(x => x.showValue))
foreach (var slot in node.GetSlots<MaterialSlot>().Where(x => x.showValue))
if (EditorGUI.EndChangeCheck())
node.onModified(node, ModificationScope.Node);
GUILayout.Space(10);
GUILayout.Space(10);
return EditorGUI.EndChangeCheck() ? ModificationScope.Node : ModificationScope.Nothing;
}
}
}

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs


public virtual void OnAfterDeserialize()
{
m_Nodes = SerializationHelper.Deserialize<INode>(m_SerializableNodes, GetLegacyTypeRemapping());
foreach (var node in m_Nodes)
node.owner = this;
foreach (var node in m_Nodes)
{
node.owner = this;
node.UpdateNodeAfterDeserialization ();
}
ValidateGraph();
}

10
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs


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 slots
m_Slots.RemoveAll(x => x.id == slotId);
if (onModified != null)
{
onModified(this, ModificationScope.Topological);
}
}
public void RemoveSlotsNameNotMatching(IEnumerable<int> slotIds)

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphInspector.cs


using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

private bool m_RequiresTime;
protected GUIContent m_Title = new GUIContent();
private NodePreviewDrawData m_NodePreviewPresenter;
private AbstractMaterialNode m_PreviewNode;

m_Title.text = m_PreviewNode.name;
m_RequiresTime = false;
ForEachChild(m_PreviewNode,
(node) =>
{
node.onModified += OnPreviewNodeModified;
m_RequiresTime |= node is IRequiresTime;
});
(node) =>
{
node.onModified += OnPreviewNodeModified;
m_RequiresTime |= node is IRequiresTime;
});
}
}

map(typeof(SubGraphInputNode), typeof(SubgraphInputNodeInspector));
map(typeof(SubGraphOutputNode), typeof(SubgraphOutputNodeInspector));
}
private void OnPreviewNodeModified(INode node, ModificationScope scope)

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs


map(typeof(Vector4Node), typeof(Vector4NodeDrawData));
map(typeof(SubGraphNode), typeof(SubgraphNodeDrawData));
map(typeof(RemapMasterNode), typeof(RemapMasterNodeDrawData));
map(typeof(MasterRemapInputNode), typeof(RemapInputNodeDrawData));
map(typeof(MasterRemapInputNode), typeof(RemapInputNodeDrawData));
map(typeof(AbstractSubGraphIONode), typeof(SubgraphIONodeDrawData));
map(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterDrawData));
map(typeof(EdgeDrawData), typeof(Edge));
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs


public MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue, bool usesDefaultValue)
: base(slotId, displayName, slotType)
{
SharedInitialize(shaderOutputName, valueType, showValue, defaultValue);
SharedInitialize(shaderOutputName, valueType, usesDefaultValue, defaultValue);
}
private void SharedInitialize(string inShaderOutputName, SlotValueType inValueType, bool usesDefaultValue, Vector4 inDefaultValue)

11
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapInputNode.cs


{
var nextSlotId = GetOutputSlots<ISlot>().Count() + 1;
AddSlot(new MaterialSlot(-nextSlotId, "Input " + nextSlotId, "Input" + nextSlotId, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
if (onModified != null)
{
onModified(this, ModificationScope.Topological);
}
return -nextSlotId;
}

return;
RemoveSlot(-lastSlotId);
if (onModified != null)
{
onModified(this, ModificationScope.Topological);
}
}
public void DepthFirstCollectNodesFromNodeSlotList(List<INode> nodeList, NodeUtils.IncludeSelf includeSelf)

39
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphInputNode.cs


public override int AddSlot()
{
var nextSlotId = GetOutputSlots<ISlot>().Count() + 1;
AddSlot(new MaterialSlot(-nextSlotId, "Input " + nextSlotId, "Input" + nextSlotId, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
return -nextSlotId;
AddSlot(new MaterialSlot(-nextSlotId, "Input " + nextSlotId, "Input" + nextSlotId, SlotType.Output, SlotValueType.Vector4, Vector4.zero, true));
return -nextSlotId;
}
public override void RemoveSlot()

RemoveSlot(-lastSlotId);
}
public override void UpdateNodeAfterDeserialization()
{
base.UpdateNodeAfterDeserialization();
foreach (var slot in GetOutputSlots<MaterialSlot>())
{
slot.showValue = true;
}
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (generationMode == GenerationMode.ForReals)

public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
foreach (var slot in GetOutputSlots<MaterialSlot>())
{
properties.Add(
new PreviewProperty
{
m_Name = GetVariableNameForSlot(slot.id),
m_PropType = PropertyType.Vector4,
m_Vector4 = slot.defaultValue
}
);
}
foreach (var s in GetOutputSlots<MaterialSlot>())
{
properties.Add
(
new PreviewProperty
{
m_Name = GetVariableNameForSlot (s.id),
m_PropType = ConvertConcreteSlotValueTypeToPropertyType (s.concreteValueType),
m_Vector4 = s.currentValue,
m_Float = s.currentValue.x,
m_Color = s.currentValue
}
);
}
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphOutputNode.cs


public override int AddSlot()
{
var index = GetInputSlots<ISlot>().Count() + 1;
AddSlot(new MaterialSlot(index, "Output " + index, "Output" + index, SlotType.Input, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(index, "Output " + index, "Output" + index, SlotType.Input, SlotValueType.Vector4, Vector4.zero, true));
public override void UpdateNodeAfterDeserialization()
{
base.UpdateNodeAfterDeserialization();
foreach (var slot in GetInputSlots<MaterialSlot>())
{
slot.showValue = true;
}
}
public override void RemoveSlot()
{

43
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SubgraphIONodeDrawData.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class SubgraphIONodeControlDrawData : ControlDrawData
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var ioNode = node as AbstractSubGraphIONode;
if (ioNode == null)
return;
if (GUILayout.Button("Add Slot"))
ioNode.AddSlot();
if (GUILayout.Button("Remove Slot"))
ioNode.RemoveSlot();
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight * 2 + 3 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class SubgraphIONodeDrawData : MaterialNodeDrawData
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<SubgraphIONodeControlDrawData>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/SubgraphIONodeDrawData.cs.meta


fileFormatVersion: 2
guid: b8c4dd0c197664d5ebf80f433981c6b4
timeCreated: 1483804520
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

85
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphInputNodeInspector.cs


using System.Linq;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.Graphing.Drawing
{
public class SubgraphInputNodeInspector : BasicNodeInspector
{
protected enum UISlotValueType
{
Vector4,
Vector3,
Vector2,
Vector1
}
private static UISlotValueType ToUISlot(SlotValueType slot)
{
switch (slot)
{
case SlotValueType.Vector1:
return UISlotValueType.Vector1;
case SlotValueType.Vector2:
return UISlotValueType.Vector2;
case SlotValueType.Vector3:
return UISlotValueType.Vector3;
case SlotValueType.Vector4:
return UISlotValueType.Vector4;
}
return UISlotValueType.Vector4;
}
private static SlotValueType ToSlotValueType(UISlotValueType slot)
{
switch (slot)
{
case UISlotValueType.Vector1:
return SlotValueType.Vector1;
case UISlotValueType.Vector2:
return SlotValueType.Vector2;
case UISlotValueType.Vector3:
return SlotValueType.Vector3;
case UISlotValueType.Vector4:
return SlotValueType.Vector4;
}
return SlotValueType.Vector4;
}
protected override ModificationScope DoSlotsUI()
{
var slots = node.GetSlots<MaterialSlot>().Where(x => x.showValue);
if (!slots.Any())
return ModificationScope.Node;
GUILayout.Label("Default Slot Values", EditorStyles.boldLabel);
bool valueChanged = false;
bool typeChanged = false;
foreach (var slot in node.GetSlots<MaterialSlot>().Where(x => x.showValue))
{
EditorGUI.BeginChangeCheck();
GUILayout.Label(slot.displayName);
slot.currentValue = EditorGUILayout.Vector4Field("", slot.currentValue);
if (EditorGUI.EndChangeCheck())
valueChanged |= true;
EditorGUI.BeginChangeCheck();
var result = (UISlotValueType)EditorGUILayout.EnumPopup(ToUISlot(slot.valueType));
slot.valueType = ToSlotValueType(result);
if (EditorGUI.EndChangeCheck())
typeChanged |= true;
}
GUILayout.Space(10);
if (typeChanged)
return ModificationScope.Topological;
if (valueChanged)
return ModificationScope.Node;
return ModificationScope.Node;
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphInputNodeInspector.cs.meta


fileFormatVersion: 2
guid: cd0ffd0e21a6644488dda4d0470a30c6
timeCreated: 1483808306
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

76
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphOutputNodeInspector.cs


using System.Linq;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.Graphing.Drawing
{
public class SubgraphOutputNodeInspector : BasicNodeInspector
{
protected enum UISlotValueType
{
Vector4,
Vector3,
Vector2,
Vector1
}
private static UISlotValueType ToUISlot(SlotValueType slot)
{
switch (slot)
{
case SlotValueType.Vector1:
return UISlotValueType.Vector1;
case SlotValueType.Vector2:
return UISlotValueType.Vector2;
case SlotValueType.Vector3:
return UISlotValueType.Vector3;
case SlotValueType.Vector4:
return UISlotValueType.Vector4;
}
return UISlotValueType.Vector4;
}
private static SlotValueType ToSlotValueType(UISlotValueType slot)
{
switch (slot)
{
case UISlotValueType.Vector1:
return SlotValueType.Vector1;
case UISlotValueType.Vector2:
return SlotValueType.Vector2;
case UISlotValueType.Vector3:
return SlotValueType.Vector3;
case UISlotValueType.Vector4:
return SlotValueType.Vector4;
}
return SlotValueType.Vector4;
}
protected override ModificationScope DoSlotsUI()
{
var slots = node.GetSlots<MaterialSlot>().Where(x => x.showValue);
if (!slots.Any())
return ModificationScope.Node;
GUILayout.Label("Default Slot Values", EditorStyles.boldLabel);
bool typeChanged = false;
foreach (var slot in node.GetSlots<MaterialSlot>().Where(x => x.showValue))
{
EditorGUI.BeginChangeCheck();
var result = (UISlotValueType)EditorGUILayout.EnumPopup(ToUISlot(slot.valueType));
slot.valueType = ToSlotValueType(result);
if (EditorGUI.EndChangeCheck())
typeChanged |= true;
}
GUILayout.Space(10);
if (typeChanged)
return ModificationScope.Topological;
return ModificationScope.Node;
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphOutputNodeInspector.cs.meta


fileFormatVersion: 2
guid: 0c7c4f1421dbb4c02a4a08f0ea8aec55
timeCreated: 1483811239
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z


7z��'�$�"
#$�~":��V�N�q$P�ߩ7G�*�~�oO��� ��N�1`�w�+���k=�0wJ���{X<P��i�,�������N*�d�=u�J6X� �MK��YW���N�Z�s<��22q@dJ�»Ps� !���u�Y��}��^A�8?���Ȩ�B�Cd��g�0-~�|8��e6̣i�T�s�M!�囖.R��?�<;p'�OM����ò""W)C���G�������98~[�m]x��wY �c2I�������F�/�jy8p�����m�=�?xE�%O�t��칂f�%oS8�W�᪗=Iכ���K��R7U�����UlS�-;�,�C3N�r��1g�.uf��Ng.��l,1 �o�b����s���2s��t����$�o��~�Lp,pT'UWWz!�|e�jO��� �vϦ�Z,��?�)���ٳ-��#�HЦ��⁃�Lql����������:��!_o!j槨�_VJ���'�6I���p^'aI:���EL���SV����@N��~������S�i�S;�O,;.��*�*�w�i�~*'�������p蕿�9�b&���Gۿ��I2m�gi�u���|�͏iB1��WAǧ�����6T�����Fk��� �c��"�9MM�*��" Ci��t�� H����{��A�P���&�qó�� ~m�{��v�����w2���Hc%%����H��{����gC�a ����zT�~��g��;Ŷ^ �Ec���Ǧ����)s�$K����( ׳��!�x���\��i:��ѡ&A�F$����Y�K�_���W�|���|��D��ՃT;�Aє���o�%Q��}�����LAQJ5�7�sTQ$*����!�b��4E�F�Kׯ-McR�3{����/��RV{���<J�ʀL����V����%L���fT���q�P��>�#���tswX=�AW���Lr�^�~|%I ��|�\O���_2O�_JD궟@�U>���$e����Up�Z���.���Ho����7�������tc�ASn׺��a�A��S a�����D�U[K�:"�ͩSZrliӥ�AN�p�m0& :xZ���q����@LK\�k%Q�<T� 8��o�4�ʣf�L&��ׂʾ03 ����}ӝd"��L%0���B5]���v67]��A^xx8���t�cG��2^6pDQ�N�w�]��K�H'�w �C�:0\��ʍ�sk�n"�N1�^9��K� ]θ��b~��7z���׺��]ٜ��عos�Y����$��8�����`JLY�˽�kOG���]=|�٭OC�0`*
���4���vv>*��5��%�7!��]JщȻUӽ�SH`C��J�}��n����ࡕZ�r�b�T SQ�ՒA��ވ�`�;XD�W5�_�x�X�~M�I)��U�2�rb�E���:%�c}m������xsk�ⵖ�+
]�3{ђ����=h?J�t�,v~{��"٦�xZܝӖ0 ܖ�]�\�c�vD�=}�ZlN��Z������Wi��|s�{�ۿt�A�HW*Qv@����}=�&��V$���W������g��p�Hk.���S�3i��8U suM�� 79��<�|� �dLn9���Qr9��Un�L��`|=�1s����^N �I�3b��y�� ^�ŝ0�ZY��ܧ/X��' k��u��=-nLz�����d�G��X.0�b����bą2Nov y[Q��B2��[<i�GP5/뻻ꀄk7�kK�T��E �U�ǡ~@a�ԣD!�������hg/�7��Yj�Y6/,:��]�D!9#�9��2��K������W6��A���Y�v�E�j�+p"��U?���1#���$ :5�s�LNr�Ap!�~?�r�bl�k[����L��r-_� U���#� ���b�� ;<ȣ����}0dg�yMd�Jy���$J�B�o|T ��%@�_ �jC�'X!���o��l����B���a���0.
l+ �M�ݪC_�AtzU�z�+��Iv� �����0��X�� 3�(57�z�_y��F�!�5�{���=�
��L�!�!���g�bC~7,�V���<����ZP4��A�8y�����h�dݴXc����D�;4SNָ�������U�#v�!p�4��3�Շ���l)H+A2h��M�z�@�";Km�,������
>=�̨���%�4.�n�7hm,S��+^��ۊb�L�,�]*s���k�n�&Y�~��cΆr��mOk�r� �ff���Q�ԓ � x�Ć[t��q�&�0�@G�`� Ӥ�iLie�X�AE0�O�9�Z�5�Ż��E��<fCIJ��1la]qCcu�6�_ھ�8A�niy �r3�y,�+����~��ZQ:�)��=��7�f
0���.w�U��c]BnM% �6���Ն���Y�8mDH�e%�5zX�$�:~Dž��p"�Ŝ6ɴ���AB(���J�0��J.n �\x
[q]�S���T�$hN��W���^ �x�#݋*�\�u���������"�%U���. 6�$M˴�;�� �� #] ��
��$

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z.meta


fileFormatVersion: 2
guid: bde27ac8743925a4dbb92de71afc2e31
timeCreated: 1475825200
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存