浏览代码

Added preview of first selected node in inspector

/main
Peter Bay Bastian 8 年前
当前提交
2483a684
共有 2 个文件被更改,包括 53 次插入3 次删除
  1. 6
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs
  2. 50
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs

6
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs


{
private readonly TypeMapper m_DataMapper = new TypeMapper(typeof(BasicNodeInspector));
[SerializeField] private List<AbstractNodeInspector> m_Inspectors = new List<AbstractNodeInspector>();
[SerializeField] protected List<AbstractNodeInspector> m_Inspectors = new List<AbstractNodeInspector>();
protected abstract void AddTypeMappings(Action<Type, Type> map);

}
}
private void UpdateInspectors()
protected virtual void UpdateInspectors()
{
var asset = target as IGraphAsset;
if (asset == null)

return CreateInstance(type) as AbstractNodeInspector;
}
public void OnEnable()
public virtual void OnEnable()
{
m_DataMapper.Clear();
AddTypeMappings(m_DataMapper.AddMapping);

50
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs


using System.Linq;
using UnityEditor.Graphing.Drawing;
using UnityEditor.MaterialGraph.Drawing.NodeInspectors;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing

{
private AbstractMaterialNode m_PreviewNode;
private NodePreviewDrawData m_NodePreviewPresenter;
public override void OnEnable()
{
base.OnEnable();
m_NodePreviewPresenter = CreateInstance<NodePreviewDrawData>();
}
}
protected override void UpdateInspectors()
{
base.UpdateInspectors();
var newPreviewNode = m_Inspectors.Select(i => i.node).OfType<AbstractMaterialNode>().FirstOrDefault();
if (newPreviewNode != m_PreviewNode)
{
m_PreviewNode = newPreviewNode;
m_NodePreviewPresenter.Initialize(m_PreviewNode);
}
}
public override bool HasPreviewGUI()
{
return m_PreviewNode != null;
}
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
if (Event.current.type == EventType.Repaint)
{
var size = Mathf.Min(r.width, r.height);
var previewDimension = new Vector2(size, size);
var previewPosition = new Vector2(r.x + r.width*0.5f - size*0.5f, r.y + r.height*0.5f - size*0.5f);
var image = m_NodePreviewPresenter.Render(previewDimension);
GUI.DrawTexture(new Rect(previewPosition, previewDimension), image);
m_NodePreviewPresenter.modificationScope = ModificationScope.Node;
}
}
public override bool RequiresConstantRepaint()
{
return true;
}
public override GUIContent GetPreviewTitle()
{
return new GUIContent(m_Inspectors.Select(i => i.node.name).FirstOrDefault());
}
}
}
正在加载...
取消
保存