浏览代码

Clean-up MaterialNodeView a bit

/main
Peter Bay Bastian 7 年前
当前提交
b057a909
共有 2 个文件被更改,包括 48 次插入49 次删除
  1. 31
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs
  2. 66
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs

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


[SerializeField]
protected List<GraphControlPresenter> m_Controls = new List<GraphControlPresenter>();
public List<GraphControlPresenter> controls
{
get { return m_Controls; }
}
public NodePreviewPresenter preview
{
get { return m_Preview; }
}
get { return node is IRequiresTime; }
get
{
using (var childrenNodes = ListPool<INode>.GetDisposable())
{
NodeUtils.DepthFirstCollectNodesFromNode(childrenNodes.value, node);
return childrenNodes.value.OfType<IRequiresTime>().Any();
}
}
}
public override bool expanded

if (base.expanded != value)
{
base.expanded = value;
DrawState ds = node.drawState;
var ds = node.drawState;
}
public List<GraphControlPresenter> controls
{
get { return m_Controls; }
}
public NodePreviewPresenter preview
{
get { return m_Preview; }
}
public override UnityEngine.Object[] GetObjectsToWatch()

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


{
public class MaterialNodeView : Node
{
VisualContainer m_ControlsContainer;
List<GraphControlPresenter> m_CurrentControlPresenter;
VisualElement m_ControlsContainer;
List<GraphControlPresenter> m_CurrentControls;
NodePreviewPresenter m_CurrentPreviewData;
NodePreviewPresenter m_CurrentPreview;
bool m_IsScheduled;
public MaterialNodeView()

void CreateContainers()
{
m_ControlsContainer = new VisualContainer
m_ControlsContainer = new VisualElement
m_CurrentControlPresenter = new List<GraphControlPresenter>();
m_CurrentControls = new List<GraphControlPresenter>();
name = "preview", // for USS&Flexbox
name = "preview",
pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};

void InvalidateUIIfNeedsTime(TimerState timerState)
{
var data = GetPresenter<MaterialNodePresenter>();
var childrenNodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(childrenNodes, data.node);
if (childrenNodes.OfType<IRequiresTime>().Any())
var node = GetPresenter<MaterialNodePresenter>();
if (node.requiresTime)
data.OnModified(ModificationScope.Node);
UpdatePreviewTexture(m_CurrentPreviewData);
node.OnModified(ModificationScope.Node);
UpdatePreviewTexture(m_CurrentPreview);
ListPool<INode>.Release(childrenNodes);
void UpdatePreviewTexture(NodePreviewPresenter previewPresenter)
void UpdatePreviewTexture(NodePreviewPresenter preview)
var texture = previewPresenter != null ? previewPresenter.Render(new Vector2(256, 256)) : null;
var texture = preview != null ? preview.Render(new Vector2(256, 256)) : null;
if (texture == null)
{
m_PreviewImage.AddToClassList("inactive");

void UpdateControls(MaterialNodePresenter nodeData)
{
if (nodeData.controls.SequenceEqual(m_CurrentControlPresenter) && nodeData.expanded)
if (nodeData.controls.SequenceEqual(m_CurrentControls) && nodeData.expanded)
m_CurrentControlPresenter.Clear();
m_CurrentControls.Clear();
if (!nodeData.expanded)
return;

m_ControlsContainer.Add(CreateControl(controlData));
m_CurrentControlPresenter.Add(controlData);
m_ControlsContainer.Add(new IMGUIContainer(controlData.OnGUIHandler)
{
name = "element",
executionContext = controlData.GetInstanceID(),
});
m_CurrentControls.Add(controlData);
IMGUIContainer CreateControl(GraphControlPresenter controlPresenter)
{
return new IMGUIContainer(controlPresenter.OnGUIHandler)
{
name = "element",
executionContext = controlPresenter.GetInstanceID(),
};
}
var nodeData = GetPresenter<MaterialNodePresenter>();
var node = GetPresenter<MaterialNodePresenter>();
if (nodeData == null)
if (node == null)
m_CurrentControlPresenter.Clear();
m_CurrentControls.Clear();
m_CurrentPreviewData = null;
UpdatePreviewTexture(m_CurrentPreviewData);
m_CurrentPreview = null;
UpdatePreviewTexture(m_CurrentPreview);
UpdateControls(nodeData);
UpdateControls(node);
m_CurrentPreviewData = nodeData.preview;
UpdatePreviewTexture(m_CurrentPreviewData);
m_CurrentPreview = node.preview;
UpdatePreviewTexture(m_CurrentPreview);
if (nodeData.expanded)
if (node.expanded)
m_PreviewImage.RemoveFromClassList("hidden");
else
m_PreviewImage.AddToClassList("hidden");

正在加载...
取消
保存