浏览代码

ColorNodeData now re-uses the underlying list returned by GetControlData()

MaterialNodeData.Initialize(INode) is now virtual, so that e.g. ColorNodeData can override and do initialization of it's own first.

Implemented item reference checking for lists in NodeDrawer and MaterialNodeDrawer
/main
Peter Bay Bastian 8 年前
当前提交
60926063
共有 6 个文件被更改,包括 133 次插入63 次删除
  1. 1
      .gitignore
  2. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs
  3. 119
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
  4. 37
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs
  5. 25
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/UIUtilities.cs
  6. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/UIUtilities.cs.meta

1
.gitignore


MaterialGraphProject/.vs
MaterialGraphProject/.vscode
MaterialGraphProject/Library
MaterialGraphProject/MaterialGraphProject.CSharp.csproj
*.csproj

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs


//position
}
}
}
}

119
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs


using System.Collections.Generic;
using UnityEditor.Graphing.Util;
namespace UnityEditor.Graphing.Drawing
{

VisualContainer m_SlotContainer;
List<NodeAnchorData> m_currentAnchors;
List<ControlDrawData> m_currentControlDrawData;
m_SlotContainer = new VisualContainer
{
name = "slots", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_ControlsContainer = new VisualContainer
{
name = "controls", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
AddContainers();
AddToClassList("NodeDrawer");
}

}
}
private void AddSlots(NodeDrawData nodeData)
private void AddContainers()
m_SlotContainer.ClearChildren();
if (!nodeData.elements.OfType<NodeAnchorData>().Any())
return;
// Add slots (with input & output sub-containers) container
m_SlotContainer = new VisualContainer
{
name = "slots", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
AddChild(m_SlotContainer);
var inputs = new VisualContainer
{

m_SlotContainer.AddChild(inputs);
// put a spacer here?
//m_SlotContainer.AddChild(new f);
var outputs = new VisualContainer
{
name = "output", // for USS&Flexbox

content = new GUIContent(nodeData.name);
foreach (var anchor in nodeData.elements.OfType<NodeAnchorData>())
m_currentAnchors = new List<NodeAnchorData>();
// Add controls container
m_ControlsContainer = new VisualContainer
if (anchor.direction == Direction.Input)
inputs.AddChild(new NodeAnchor(anchor));
else
outputs.AddChild(new NodeAnchor(anchor));
name = "controls", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
AddChild(m_ControlsContainer);
m_currentControlDrawData = new List<ControlDrawData>();
}
private void AddSlots(NodeDrawData nodeData)
{
var anchors = nodeData.elements.OfType<NodeAnchorData>().ToList();
if (anchors.Count == 0)
return;
var inputsContainer = m_SlotContainer.GetChildAtIndex(0) as VisualContainer;
var outputsContainer = m_SlotContainer.GetChildAtIndex(1) as VisualContainer;
if (!anchors.ItemsReferenceEquals(m_currentAnchors))
{
m_currentAnchors = anchors;
inputsContainer.ClearChildren();
outputsContainer.ClearChildren();
foreach (var anchor in nodeData.elements.OfType<NodeAnchorData>())
{
if (anchor.direction == Direction.Input)
inputsContainer.AddChild(new NodeAnchor(anchor));
else
outputsContainer.AddChild(new NodeAnchor(anchor));
}
AddChild(m_SlotContainer);
content = new GUIContent(nodeData.name);
m_ControlsContainer.ClearChildren();
var controlDrawData = nodeData.elements.OfType<ControlDrawData>().ToList();
if (!nodeData.elements.OfType<ControlDrawData>().Any())
if (controlDrawData.Count == 0)
foreach (var controlData in nodeData.elements.OfType<ControlDrawData>())
if (controlDrawData.ItemsReferenceEquals(m_currentControlDrawData))
var imContainer = new IMGUIContainer
for (int i = 0; i < controlDrawData.Count; i++)
name = "element",
OnGUIHandler = controlData.OnGUIHandler,
pickingMode = PickingMode.Position,
height = controlData.GetHeight(),
};
m_ControlsContainer.AddChild(imContainer);
var controlData = controlDrawData[i];
var imContainer = m_ControlsContainer.GetChildAtIndex(i) as IMGUIContainer;
imContainer.OnGUIHandler = controlData.OnGUIHandler;
imContainer.height = controlData.GetHeight();
}
else
{
m_ControlsContainer.ClearChildren();
m_currentControlDrawData.Clear();
AddChild(m_ControlsContainer);
foreach (var controlData in controlDrawData)
{
var imContainer = new IMGUIContainer()
{
name = "element",
OnGUIHandler = controlData.OnGUIHandler,
pickingMode = PickingMode.Position,
height = controlData.GetHeight()
};
m_ControlsContainer.AddChild(imContainer);
m_currentControlDrawData.Add(controlData);
}
}
ClearChildren();
m_ControlsContainer.ClearChildren();
{
ClearChildren();
AddContainers();
}
AddSlots(nodeData);
AddControls(nodeData);

37
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs


using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEngine.RMGUI;
using UnityEditor.Graphing.Util;
namespace UnityEditor.MaterialGraph.Drawing
{

public MaterialNodeDrawer()
{
CreateContainers();
onEnter += SchedulePolling;
onLeave += UnschedulePolling;
}
private void CreateContainers()
{
m_PreviewContainer = new VisualContainer
{
name = "preview", // for USS&Flexbox

m_currentPreviewData = new List<NodePreviewDrawData>();
onEnter += SchedulePolling;
onLeave += UnschedulePolling;
}
private void SchedulePolling()

return;
var previews = nodeData.elements.OfType<NodePreviewDrawData>().ToList();
var isSamePreviews = m_currentPreviewData.Count == previews.Count;
if (isSamePreviews)
{
for (int i = 0; i < previews.Count; i++)
{
if (!ReferenceEquals(previews[i], m_currentPreviewData[i]))
{
isSamePreviews = false;
break;
}
}
}
if (isSamePreviews)
if (previews.ItemsReferenceEquals(m_currentPreviewData))
var thePreview = m_PreviewContainer.GetChildAtIndex(i) as Image;
// TODO: Consider null exception
thePreview.image = preview.Render(new Vector2(200, 200));
preview.Render(new Vector2(200, 200));
m_currentPreviewData.Clear();
m_currentPreviewData = previews;
foreach (var preview in previews)
{

name = "image"
};
m_PreviewContainer.AddChild(thePreview);
m_currentPreviewData.Add(preview);
}
}

var nodeData = dataProvider as MaterialNodeDrawData;
if (nodeData == null)
{
CreateContainers();
}
AddPreview(nodeData);
}

25
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/UIUtilities.cs


using System.Collections.Generic;
namespace UnityEditor.Graphing.Util
{
public static class UIUtilities
{
public static bool ItemsReferenceEquals<T>(this IList<T> first, IList<T> second)
{
if (first.Count != second.Count)
{
return false;
}
for (int i = 0; i < first.Count; i++)
{
if (!ReferenceEquals(first[i], second[i]))
{
return false;
}
}
return true;
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/UIUtilities.cs.meta


fileFormatVersion: 2
guid: 60ebb16e194464bce8a4975da8fd215a
timeCreated: 1476782702
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存