浏览代码

Add initial preview hiding (still being rendered behind the scenes)

/main
Peter Bay Bastian 7 年前
当前提交
d0f20689
共有 5 个文件被更改,包括 73 次插入32 次删除
  1. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  2. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs
  3. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  4. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  5. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


public void RemoveElements(IEnumerable<MaterialNodePresenter> nodes, IEnumerable<GraphEdgePresenter> edges)
{
graph.RemoveElements(nodes.Select(x => x.node), edges.Select(x => x.edge));
graph.RemoveElements(nodes.Select(x => x.node as INode), edges.Select(x => x.edge));
graph.ValidateGraph();
}

return;
var addedNodes = new List<INode>();
var nodeGuidMap = new Dictionary<Guid, Guid>();
foreach (var node in copyGraph.GetNodes<INode>())
{

// only connect edges within pasted elements, discard
// external edges.
var addedEdges = new List<IEdge>();
foreach (var edge in copyGraph.edges)
{
var outputSlot = edge.outputSlot;

{
var outputSlotRef = new SlotReference(remappedOutputNodeGuid, outputSlot.slotId);
var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId);
addedEdges.Add(graph.Connect(outputSlotRef, inputSlotRef));
graph.Connect(outputSlotRef, inputSlotRef);
//TODO: Fix this
//drawingData.selection = addedNodes.Select(n => n.guid);
if (onSelectionChanged != null)
onSelectionChanged(addedNodes);
}
public bool canCopy

if (graph == null)
return;
if (onSelectionChanged != null)
onSelectionChanged(presenters.Select(x => x.node));
onSelectionChanged(presenters.Select(x => x.node as INode));
}
public override void AddElement(GraphElementPresenter element)

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs


[Serializable]
public class MaterialNodePresenter : NodePresenter, IDisposable
{
public INode node { get; private set; }
public AbstractMaterialNode node { get; private set; }
[SerializeField]
protected List<GraphControlPresenter> m_Controls = new List<GraphControlPresenter>();

public virtual void Initialize(INode inNode, PreviewSystem previewSystem)
{
node = inNode;
node = inNode as AbstractMaterialNode;
if (node == null)
return;

53
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;

{
VisualElement m_ControlsContainer;
List<GraphControlPresenter> m_CurrentControls;
VisualElement m_PreviewContainer;
VisualElement m_PreviewToggle;
Image m_PreviewImage;
bool m_IsScheduled;

leftContainer.Add(m_ControlsContainer);
m_CurrentControls = new List<GraphControlPresenter>();
m_PreviewContainer = new VisualElement { name = "preview" };
m_PreviewToggle = new VisualElement { name = "toggle", text = "" };
m_PreviewToggle.AddManipulator(new Clickable(OnPreviewToggle));
leftContainer.Add(m_PreviewToggle);
m_PreviewImage = new Image
m_PreviewImage = new Image
{
pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
}
leftContainer.Add(m_PreviewContainer);
name = "preview",
pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
leftContainer.Add(m_PreviewImage);
}
void OnPreviewToggle()
{
var node = GetPresenter<MaterialNodePresenter>().node;
node.previewExpanded = !node.previewExpanded;
m_PreviewToggle.text = node.previewExpanded ? "▲" : "▼";
}
void UpdatePreviewTexture(Texture previewTexture)

m_PreviewContainer.Clear();
m_PreviewImage.visible = false;
m_PreviewImage.RemoveFromClassList("visible");
m_PreviewImage.AddToClassList("hidden");
if (m_PreviewContainer.childCount == 0)
m_PreviewContainer.Add(m_PreviewImage);
m_PreviewImage.visible = true;
m_PreviewImage.AddToClassList("visible");
m_PreviewImage.RemoveFromClassList("hidden");
Dirty(ChangeType.Repaint | ChangeType.Layout);
Dirty(ChangeType.Repaint);
}
void UpdateControls(MaterialNodePresenter nodeData)

{
m_ControlsContainer.Clear();
m_CurrentControls.Clear();
m_PreviewContainer.Clear();
m_PreviewToggle.text = nodePresenter.node.previewExpanded ? "▲" : "▼";
if (nodePresenter.node.hasPreview)
m_PreviewToggle.RemoveFromClassList("inactive");
else
m_PreviewToggle.AddToClassList("inactive");
// if (nodePresenter.expanded)
UpdatePreviewTexture(nodePresenter.previewTexture);
// else
// m_PreviewContainer.Clear();
UpdatePreviewTexture(nodePresenter.node.previewExpanded ? nodePresenter.previewTexture : null);
}
}
}

24
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


width: 400;
}
MaterialNodeView > .mainContainer > #left > #preview > Image {
MaterialNodeView > .mainContainer > #left > #preview.active {
width: 200;
}
MaterialNodeView > .mainContainer > #left > #preview.visible {
width: 200;
}
MaterialNodeView > .mainContainer > #left > #toggle {
text-color: rgb(153, 153, 153);
text-alignment: middle-center;
}
MaterialNodeView > .mainContainer > #left > #toggle.inactive {
height: 0;
}
MaterialNodeView > .mainContainer > #left > #toggle:hover {
background-color: rgba(0, 0, 0, 0.33);
}
MaterialNodeView > .mainContainer > #left > #toggle:active {
background-color: rgba(0, 0, 0, 0.66);
}
GridBackground {

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

//[SerializeField]
private OutputPrecision m_OutputPrecision = OutputPrecision.@float;
[SerializeField]
bool m_PreviewExpanded;
public bool previewExpanded
{
get { return m_PreviewExpanded; }
set { m_PreviewExpanded = value; }
}
// Nodes that want to have a preview area can override this and return true
public virtual bool hasPreview

正在加载...
取消
保存