|
|
|
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using RMGUI.GraphView; |
|
|
|
using RMGUI.GraphView.Demo; |
|
|
|
|
|
|
|
|
|
|
namespace UnityEditor.Graphing.Drawing |
|
|
|
{ |
|
|
|
class PreviewImage : Image |
|
|
|
{ |
|
|
|
public override void DoRepaint(PaintContext args) |
|
|
|
{ |
|
|
|
Handles.DrawSolidRectangleWithOutline(position, Color.blue, Color.blue); |
|
|
|
base.DoRepaint(args); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[GUISkinStyle("window")] |
|
|
|
public class MaterialGraphNode : GraphElement |
|
|
|
{ |
|
|
|
|
|
|
private List<NodePreviewData> m_currentPreviewData; |
|
|
|
|
|
|
|
public MaterialGraphNode() |
|
|
|
{ |
|
|
|
|
|
|
name = "preview", // for USS&Flexbox
|
|
|
|
pickingMode = PickingMode.Ignore, |
|
|
|
}; |
|
|
|
|
|
|
|
m_currentPreviewData = new List<NodePreviewData>(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void DoRepaint(PaintContext painter) |
|
|
|
|
|
|
|
|
|
|
private void AddPreview(MaterialNodeData nodeData) |
|
|
|
{ |
|
|
|
m_PreviewContainer.ClearChildren(); |
|
|
|
|
|
|
|
|
|
|
|
var previews = nodeData.elements.OfType<NodePreviewData>().ToList(); |
|
|
|
var isSamePreviews = m_currentPreviewData.Count == previews.Count; |
|
|
|
foreach (var preview in nodeData.elements.OfType<NodePreviewData>()) |
|
|
|
if (isSamePreviews) |
|
|
|
{ |
|
|
|
for (int i = 0; i < previews.Count; i++) |
|
|
|
{ |
|
|
|
if (!ReferenceEquals(previews[i], m_currentPreviewData[i])) |
|
|
|
{ |
|
|
|
isSamePreviews = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (isSamePreviews) |
|
|
|
var image = preview.Render(new Vector2(200, 200)); |
|
|
|
var thePreview = new PreviewImage |
|
|
|
for (int i = 0; i < previews.Count; i++) |
|
|
|
image = image, |
|
|
|
name = "image" |
|
|
|
}; |
|
|
|
m_PreviewContainer.AddChild(thePreview); |
|
|
|
var preview = previews[i]; |
|
|
|
var thePreview = m_PreviewContainer.GetChildAtIndex(i) as Image; |
|
|
|
// TODO: Consider null exception
|
|
|
|
// TODO: Need to share the texture
|
|
|
|
// right now it's allocating all the time.
|
|
|
|
thePreview.image = preview.Render(new Vector2(200, 200)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
m_PreviewContainer.ClearChildren(); |
|
|
|
m_currentPreviewData.Clear(); |
|
|
|
foreach (var preview in previews) |
|
|
|
{ |
|
|
|
var image = preview.Render(new Vector2(200, 200)); |
|
|
|
var thePreview = new Image |
|
|
|
{ |
|
|
|
image = image, |
|
|
|
name = "image" |
|
|
|
}; |
|
|
|
m_PreviewContainer.AddChild(thePreview); |
|
|
|
m_currentPreviewData.Add(preview); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
AddChild(m_PreviewContainer); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
ClearChildren(); |
|
|
|
|
|
|
|
m_ControlsContainer.ClearChildren(); |
|
|
|
m_PreviewContainer.ClearChildren(); |
|
|
|
// m_PreviewContainer.ClearChildren();
|
|
|
|
|
|
|
|
var nodeData = dataProvider as MaterialNodeData; |
|
|
|
|
|
|
|