浏览代码

Add serialization for blackboard layout

/main
Peter Bay Bastian 7 年前
当前提交
4cfaf738
共有 3 个文件被更改,包括 38 次插入12 次删除
  1. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/Blackboard.cs
  2. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardProvider.cs
  3. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/Blackboard.cs


ClearClassList();
AddToClassList("sgblackboard");
this.AddManipulator(new Dragger { clampToParentEdges = true });
// this.AddManipulator(new Dragger { clampToParentEdges = true });
shadow.Add(new Resizer());
// shadow.Add(new Resizer());
}
}
}

21
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardProvider.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Inspector;
using UnityEngine;
using UnityEngine.Experimental.UIElements;

readonly Texture2D m_ExposedIcon;
readonly Dictionary<Guid, BlackboardRow> m_PropertyRows;
readonly BlackboardSection m_Section;
WindowDraggable m_WindowDraggable;
ResizeBorderFrame m_ResizeBorderFrame;
public Action onDragFinished
{
get { return m_WindowDraggable.OnDragFinished; }
set { m_WindowDraggable.OnDragFinished = value; }
}
public Action onResizeFinished
{
get { return m_ResizeBorderFrame.OnResizeFinished; }
set { m_ResizeBorderFrame.OnResizeFinished = value; }
}
public BlackboardProvider(string assetName, AbstractMaterialGraph graph)
{
m_AssetName = assetName;

addItemRequested = AddItemRequested,
moveItemRequested = MoveItemRequested
};
m_WindowDraggable = new WindowDraggable();
blackboard.AddManipulator(m_WindowDraggable);
m_ResizeBorderFrame = new ResizeBorderFrame(blackboard) { name = "resizeBorderFrame" };
blackboard.shadow.Add(m_ResizeBorderFrame);
m_Section = new BlackboardSection { headerVisible = false };
foreach (var property in graph.properties)

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


class FloatingWindowsLayout
{
public Rect previewLayout;
public Rect blackboardLayout;
}
public class GraphEditorView : VisualElement, IDisposable

BlackboardProvider m_BlackboardProvider;
string m_FloatingWindowsLayoutKey;
FloatingWindowsLayout m_FLoatingWindowsLayout;
FloatingWindowsLayout m_FloatingWindowsLayout;
public Action saveRequested { get; set; }

m_MasterPreviewView = new MasterPreviewView(assetName, previewManager, graph) { name = "masterPreview" };
WindowDraggable masterPreviewViewDraggable = new WindowDraggable();
masterPreviewViewDraggable.OnDragFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.Add(masterPreviewResizeBorderFrame);
m_BlackboardProvider.onDragFinished += UpdateSerializedWindowLayout;
m_BlackboardProvider.onResizeFinished += UpdateSerializedWindowLayout;
masterPreviewViewDraggable.OnDragFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.Add(masterPreviewResizeBorderFrame);
m_GraphView.graphViewChanged = GraphViewChanged;

if (!String.IsNullOrEmpty(serializedWindowLayout))
{
m_FLoatingWindowsLayout = JsonUtility.FromJson<FloatingWindowsLayout>(serializedWindowLayout);
m_MasterPreviewView.layout = m_FLoatingWindowsLayout.previewLayout;
m_FloatingWindowsLayout = JsonUtility.FromJson<FloatingWindowsLayout>(serializedWindowLayout);
m_MasterPreviewView.layout = m_FloatingWindowsLayout.previewLayout;
if (m_FloatingWindowsLayout.blackboardLayout.width > 0)
m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout;
m_FLoatingWindowsLayout = new FloatingWindowsLayout();
m_FloatingWindowsLayout = new FloatingWindowsLayout();
}
}

void OnSpaceDown(KeyDownEvent evt)
{
if( evt.keyCode == KeyCode.Space)
if(evt.keyCode == KeyCode.Space && !evt.shiftKey && !evt.altKey && !evt.ctrlKey && !evt.commandKey)
{
if (graphView.nodeCreationRequest == null)
return;

void UpdateSerializedWindowLayout()
{
m_FLoatingWindowsLayout.previewLayout = m_MasterPreviewView.layout;
m_FloatingWindowsLayout.previewLayout = m_MasterPreviewView.layout;
m_FloatingWindowsLayout.blackboardLayout = m_BlackboardProvider.blackboard.layout;
string serializedWindowLayout = JsonUtility.ToJson(m_FLoatingWindowsLayout);
string serializedWindowLayout = JsonUtility.ToJson(m_FloatingWindowsLayout);
EditorUserSettings.SetConfigValue(m_FloatingWindowsLayoutKey, serializedWindowLayout);
}

正在加载...
取消
保存