浏览代码

* Add individual properties to node search

* Remove dropdown from property node
* Add all compatible slots to node search when dragging into empty space
*
/main
Peter Bay Bastian 7 年前
当前提交
484b4f58
共有 5 个文件被更改,包括 65 次插入97 次删除
  1. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PropertyNode.cs
  2. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardProvider.cs
  3. 82
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/SearchWindowProvider.cs
  4. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs.meta
  5. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs

21
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PropertyNode.cs


if (property is FloatShaderProperty)
{
AddSlot(new Vector1MaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, 0));
AddSlot(new Vector2MaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector2MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector3MaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector3MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, Vector4.zero));
AddSlot(new Vector4MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, Vector4.zero));
AddSlot(new Texture2DMaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output));
AddSlot(new Texture2DMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
AddSlot(new CubemapMaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output));
AddSlot(new CubemapMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
AddSlot(new Vector1MaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, 0));
AddSlot(new BooleanMaterialSlot(OutputSlotId, "Out", "Out", SlotType.Output, false));
AddSlot(new BooleanMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, false));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
}

}
}
[PropertyControl]
public Guid propertyGuid
{
get { return m_PropertyGuid; }

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardProvider.cs


void DirtyNodes()
{
foreach (var node in m_Graph.GetNodes<PropertyNode>())
{
node.OnEnable();
}
}
}
}

82
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/SearchWindowProvider.cs


using UnityEditor.Graphing;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using INode = UnityEditor.Graphing.INode;
namespace UnityEditor.ShaderGraph.Drawing
{

public int compatibleSlotId;
}
List<int> m_Ids;
List<ISlot> m_Slots = new List<ISlot>();
public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context)

if (attrs != null && attrs.Length > 0)
{
var node = (AbstractMaterialNode) Activator.CreateInstance(type);
var compatibleSlotId = -1;
if (connectedPort != null)
{
compatibleSlotId = GetFirstCompatibleSlotId(node);
if (compatibleSlotId == -1)
continue;
}
nodeEntries.Add(new NodeEntry { title = attrs[0].title, node = node, compatibleSlotId = compatibleSlotId});
AddEntries(node, attrs[0].title, nodeEntries);
}
}
}

var asset = AssetDatabase.LoadAssetAtPath<MaterialSubGraphAsset>(AssetDatabase.GUIDToAssetPath(guid));
var node = Activator.CreateInstance<SubGraphNode>();
node.subGraphAsset = asset;
var compatibleSlotId = -1;
if (connectedPort != null)
{
compatibleSlotId = GetFirstCompatibleSlotId(node);
if (compatibleSlotId == -1)
continue;
}
nodeEntries.Add(new NodeEntry
{
title = new[] { "Sub-graph Assets", asset.name },
node = node,
compatibleSlotId = compatibleSlotId
});
var node = new SubGraphNode { subGraphAsset = asset };
AddEntries(node, new [] { "Sub-graph Assets", asset.name }, nodeEntries);
}
foreach (var property in m_Graph.properties)
{
var node = new PropertyNode();
var property1 = property;
node.owner = m_Graph;
node.propertyGuid = property1.guid;
node.owner = null;
AddEntries(node, new [] { "Properties", "Property: " + property.displayName }, nodeEntries);
}
// Sort the entries lexicographically by group then title with the requirement that items always comes before sub-groups in the same group.

return tree;
}
int GetFirstCompatibleSlotId(AbstractMaterialNode node)
void AddEntries(AbstractMaterialNode node, string[] title, List<NodeEntry> nodeEntries)
if (connectedPort == null)
{
nodeEntries.Add(new NodeEntry
{
node = node,
title = title,
compatibleSlotId = -1
});
return;
}
var hasSingleSlot = m_Slots.Count(s => s.isOutputSlot != connectedSlot.isOutputSlot) == 1;
m_Slots.RemoveAll(slot =>
{
var materialSlot = (MaterialSlot)slot;
return !materialSlot.IsCompatibleWith(connectedSlot);
});
if (hasSingleSlot && m_Slots.Count == 1)
{
nodeEntries.Add(new NodeEntry
{
node = node,
title = title,
compatibleSlotId = m_Slots.First().id
});
return;
}
var materialSlot = (MaterialSlot)slot;
if (materialSlot.IsCompatibleWith(connectedSlot))
var entryTitle = new string[title.Length];
title.CopyTo(entryTitle, 0);
entryTitle[entryTitle.Length - 1] += ": " + slot.displayName;
nodeEntries.Add(new NodeEntry
return materialSlot.id;
}
title = entryTitle,
node = node,
compatibleSlotId = slot.id
});
return -1;
}
public bool OnSelectEntry(SearchTreeEntry entry, SearchWindowContext context)

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs.meta


fileFormatVersion: 2
guid: bb1167be0ec94c0a849394d34df45a98
timeCreated: 1507819549

53
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs


using System;
using System.Linq;
using System.Reflection;
using UnityEditor.Graphing;
using UnityEngine.Experimental.UIElements;
using UnityEditor.ShaderGraph;
namespace UnityEditor.ShaderGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class PropertyControlAttribute : Attribute, IControlAttribute
{
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new PropertyControlView(node);
}
}
public class PropertyControlView : VisualElement, INodeModificationListener
{
PropertyNode m_Node;
public PropertyControlView(AbstractMaterialNode node)
{
m_Node = (PropertyNode)node;
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
var graph = m_Node.owner as AbstractMaterialGraph;
var currentGUID = m_Node.propertyGuid;
var properties = graph.properties.ToList();
var propertiesGUID = properties.Select(x => x.guid).ToList();
var currentSelectedIndex = propertiesGUID.IndexOf(currentGUID);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
var value = EditorGUILayout.Popup(currentSelectedIndex, properties.Select(x => x.displayName).ToArray());
if (changeCheckScope.changed)
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_Node.propertyGuid = propertiesGUID[value];
}
}
}
public void OnNodeModified(ModificationScope scope)
{
Dirty(ChangeType.Repaint);
}
}
}
正在加载...
取消
保存