浏览代码

Add rate limiting for preview updates

/main
Peter Bay Bastian 7 年前
当前提交
65e94a0c
共有 7 个文件被更改,包括 45 次插入15 次删除
  1. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs
  2. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs
  3. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs
  4. 20
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  5. 2
      MaterialGraphProject/ProjectSettings/ProjectVersion.txt
  6. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewRate.cs
  7. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewRate.cs.meta

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs


void Repaint();
void ToggleRequiresTime();
void ToSubGraph();
void Show();

public abstract AbstractMaterialGraph GetMaterialGraph();
public abstract void PingAsset();
public abstract void UpdateAsset();
public abstract void ToggleRequiresTime();
public abstract void ToSubGraph();
public abstract Object selected { get; set; }
public abstract void ChangeSelection(Object newSelection);

graphEditorView.onUpdateAssetClick += UpdateAsset;
graphEditorView.onConvertToSubgraphClick += ToSubGraph;
graphEditorView.onShowInProjectClick += PingAsset;
graphEditorView.onTimeClick += ToggleRequiresTime;
rootVisualContainer.Add(graphEditorView);
}

File.WriteAllText(path, EditorJsonUtility.ToJson(inMemoryAsset, true));
shaderImporter.SaveAndReimport();
AssetDatabase.ImportAsset(path);
}
public override void ToggleRequiresTime()
{
allowAlwaysRepaint = !allowAlwaysRepaint;
}
public override void ChangeSelection(Object newSelection)

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs


PreviewSystem m_PreviewSystem;
public PreviewRate previewRate
{
get { return m_PreviewSystem.previewRate; }
set { m_PreviewSystem.previewRate = value; }
}
public MaterialGraphPresenter graphPresenter
{
get { return m_GraphPresenter; }

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs


MaterialPropertyBlock m_PreviewPropertyBlock;
MaterialGraphPreviewGenerator m_PreviewGenerator = new MaterialGraphPreviewGenerator();
Texture2D m_ErrorTexture;
DateTime m_LastUpdate;
public PreviewRate previewRate { get; set; }
public PreviewSystem(AbstractMaterialGraph graph)
{

public void Update()
{
if (previewRate == PreviewRate.Off)
return;
var updateTime = DateTime.Now;
if (previewRate == PreviewRate.Throttled && (updateTime - m_LastUpdate) < TimeSpan.FromSeconds(1.0 / 10.0))
return;
m_LastUpdate = updateTime;
PropagateNodeSet(m_DirtyShaders);
foreach (var nodeGuid in m_DirtyShaders)
{

20
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


public Action onUpdateAssetClick { get; set; }
public Action onConvertToSubgraphClick { get; set; }
public Action onShowInProjectClick { get; set; }
public Action onTimeClick { get; set; }
public GraphEditorView()
{

m_ToolbarView.Add(new ToolbarSpaceView());
m_ToolbarView.Add(new ToolbarSeparatorView());
var timeButton = new ToolbarButtonView { text = "Time" };
timeButton.AddManipulator(new Clickable(() =>
m_TimeButton = new ToolbarButtonView { text = "" };
m_TimeButton.AddManipulator(new Clickable(() =>
if (onTimeClick != null) onTimeClick();
if (presenter == null)
return;
if (presenter.previewRate == PreviewRate.Full)
presenter.previewRate = PreviewRate.Throttled;
else if (presenter.previewRate == PreviewRate.Throttled)
presenter.previewRate = PreviewRate.Off;
else if (presenter.previewRate == PreviewRate.Off)
presenter.previewRate = PreviewRate.Full;
m_TimeButton.text = "Preview rate: " + presenter.previewRate;
m_ToolbarView.Add(timeButton);
m_ToolbarView.Add(m_TimeButton);
m_ToolbarView.Add(new ToolbarSeparatorView());
}

{
m_GraphView.presenter = m_Presenter.graphPresenter;
m_GraphInspectorView.presenter = m_Presenter.graphInspectorPresenter;
m_TimeButton.text = "Preview rate: " + presenter.previewRate;
ToolbarButtonView m_TimeButton;
public GraphEditorPresenter presenter
{

onUpdateAssetClick = null;
onConvertToSubgraphClick = null;
onShowInProjectClick = null;
onTimeClick = null;
if (m_GraphInspectorView != null) m_GraphInspectorView.Dispose();
}
}

2
MaterialGraphProject/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2017.3.0b1
m_EditorVersion: 2018.1.0a1

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewRate.cs


namespace UnityEditor.MaterialGraph.Drawing
{
public enum PreviewRate
{
Full,
Throttled,
Off
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewRate.cs.meta


fileFormatVersion: 2
guid: fa070520993a4b839e705dcd7f22e4d6
timeCreated: 1506421104
正在加载...
取消
保存