浏览代码

Merge remote-tracking branch 'origin/master' into master-preview-rendertexture-rescale

/main
Jens Holm 7 年前
当前提交
ae1852e9
共有 8 个文件被更改,包括 174 次插入117 次删除
  1. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardField.cs
  2. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardProvider.cs
  3. 59
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs
  4. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  5. 105
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/WindowDockingLayout.cs
  6. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/WindowDockingLayout.cs.meta
  7. 65
      MaterialGraphProject/Assets/TestAssets/RockMaterial1.sbsar.meta

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardField.cs


activeFieldInfo.SetValue(m_SelectionDropper, false);
this.AddManipulator(m_SelectionDropper);
var contextualMenuManipulator = (IManipulator)Activator.CreateInstance(s_ContextualMenuManipulator, (Action<ContextualMenuPopulateEvent>)BuildContextualMenu);
this.AddManipulator(contextualMenuManipulator);
this.AddManipulator((IManipulator)Activator.CreateInstance(s_ContextualMenuManipulator, (Action<ContextualMenuPopulateEvent>)BuildContextualMenu));
}
void BuildContextualMenu(ContextualMenuPopulateEvent evt)

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


moveItemRequested = MoveItemRequested
};
m_WindowDraggable = new WindowDraggable();
m_WindowDraggable = new WindowDraggable(blackboard.shadow.Children().First().Q("header"));
blackboard.AddManipulator(m_WindowDraggable);
m_ResizeBorderFrame = new ResizeBorderFrame(blackboard) { name = "resizeBorderFrame" };

var property = visualElement.userData as IShaderProperty;
if (property == null)
return;
m_Graph.owner.RegisterCompleteObjectUndo("Move Property");
m_Graph.MoveShaderProperty(property, newIndex);
}

var property = (IShaderProperty)field.userData;
if (newText != property.displayName)
{
m_Graph.owner.RegisterCompleteObjectUndo("Edit Property Name");
property.displayName = newText;
field.text = newText;
DirtyNodes();

{
field.RenameGo();
row.expanded = true;
m_Graph.owner.RegisterCompleteObjectUndo("Create Property");
m_Graph.AddShaderProperty(property);
}
}

59
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/WindowDraggable.cs


using System;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

bool m_Active;
bool m_DockLeft;
bool m_DockTop;
WindowDockingLayout m_WindowDockingLayout;
VisualElement m_Handle;
public WindowDraggable(bool resizeWithParentwindow = false)
public WindowDraggable(VisualElement handle = null, bool resizeWithParentwindow = false)
m_Handle = handle;
m_WindowDockingLayout = new WindowDockingLayout();
target.RegisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), Capture.NoCapture);
target.RegisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), Capture.NoCapture);
target.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture);
if (m_Handle == null)
m_Handle = target;
m_Handle.RegisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), Capture.NoCapture);
m_Handle.RegisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), Capture.NoCapture);
m_Handle.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture);
target.UnregisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), Capture.NoCapture);
target.UnregisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), Capture.NoCapture);
target.UnregisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture);
m_Handle.UnregisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), Capture.NoCapture);
m_Handle.UnregisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), Capture.NoCapture);
m_Handle.UnregisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), Capture.NoCapture);
m_LocalMosueOffset = target.WorldToLocal(evt.mousePosition);
m_LocalMosueOffset = m_Handle.WorldToLocal(evt.mousePosition);
target.TakeMouseCapture();
evt.StopPropagation();
m_Handle.TakeMouseCapture();
evt.StopImmediatePropagation();
}
void OnMouseMove(MouseMoveEvent evt)

}
}
void OnMouseUp(MouseUpEvent evt)
{
bool emitDragFinishedEvent = m_Active;

if (target.HasMouseCapture())
if (m_Handle.HasMouseCapture())
target.ReleaseMouseCapture();
m_Handle.ReleaseMouseCapture();
evt.StopPropagation();
evt.StopImmediatePropagation();
RefreshDocking();
m_WindowDockingLayout.CalculateDockingCornerAndOffset(target.layout, target.parent.layout);
if (emitDragFinishedEvent && OnDragFinished != null)
{

void RefreshDocking()
{
Vector2 windowCenter = new Vector2(target.layout.x + target.layout.width * .5f, target.layout.y + target.layout.height * .5f);
windowCenter /= target.parent.layout.size;
m_DockLeft = windowCenter.x < .5f;
m_DockTop = windowCenter.y < .5f;
}
void InitialLayoutSetup(PostLayoutEvent postLayoutEvent)
{
m_PreviousParentRect = target.parent.layout;

RefreshDocking();
m_WindowDockingLayout.CalculateDockingCornerAndOffset(target.layout, target.parent.layout);
}
void OnPostLayout(PostLayoutEvent postLayoutEvent)

}
Vector2 distanceFromParentEdge = Vector2.zero;
distanceFromParentEdge.x = m_DockLeft ? target.layout.x : (m_PreviousParentRect.width - target.layout.x - target.layout.width);
distanceFromParentEdge.y = m_DockTop ? target.layout.y: (m_PreviousParentRect.height - target.layout.y - target.layout.height);
distanceFromParentEdge.x = m_WindowDockingLayout.dockingLeft ? target.layout.x : (m_PreviousParentRect.width - target.layout.x - target.layout.width);
distanceFromParentEdge.y = m_WindowDockingLayout.dockingTop ? target.layout.y: (m_PreviousParentRect.height - target.layout.y - target.layout.height);
Vector2 normalizedDistanceFromEdge = distanceFromParentEdge / m_PreviousParentRect.size;

normalizedDistanceFromEdge = distanceFromParentEdge / target.parent.layout.size;
}
if (m_DockLeft)
if (m_WindowDockingLayout.dockingLeft)
{
windowRect.x = normalizedDistanceFromEdge.x * target.parent.layout.width;
}

}
if (m_DockTop)
if (m_WindowDockingLayout.dockingTop)
{
windowRect.y = normalizedDistanceFromEdge.y * target.parent.layout.height;
}

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


[Serializable]
class FloatingWindowsLayout
{
public Rect previewLayout;
public Rect blackboardLayout;
public WindowDockingLayout previewLayout = new WindowDockingLayout();
public WindowDockingLayout blackboardLayout = new WindowDockingLayout();
}
public class GraphEditorView : VisualElement, IDisposable

m_GraphView.graphViewChanged = GraphViewChanged;
m_FloatingWindowsLayoutKey = "UnityEditor.ShaderGraph.FloatingWindowsLayout";
string serializedWindowLayout = EditorUserSettings.GetConfigValue(m_FloatingWindowsLayoutKey);
if (!String.IsNullOrEmpty(serializedWindowLayout))
{
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;
}
else
{
m_FloatingWindowsLayout = new FloatingWindowsLayout();
}
RegisterCallback<PostLayoutEvent>(ApplySerializewindowLayouts);
}
m_SearchWindowProvider = ScriptableObject.CreateInstance<SearchWindowProvider>();

}
}
void ApplySerializewindowLayouts(PostLayoutEvent evt)
{
UnregisterCallback<PostLayoutEvent>(ApplySerializewindowLayouts);
m_FloatingWindowsLayoutKey = "UnityEditor.ShaderGraph.FloatingWindowsLayout";
string serializedWindowLayout = EditorUserSettings.GetConfigValue(m_FloatingWindowsLayoutKey);
if (!String.IsNullOrEmpty(serializedWindowLayout))
{
m_FloatingWindowsLayout = JsonUtility.FromJson<FloatingWindowsLayout>(serializedWindowLayout);
m_MasterPreviewView.layout = m_FloatingWindowsLayout.previewLayout.GetLayout(layout);
m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout.GetLayout(layout);
}
else
{
m_FloatingWindowsLayout = new FloatingWindowsLayout();
}
}
m_FloatingWindowsLayout.previewLayout = m_MasterPreviewView.layout;
m_FloatingWindowsLayout.blackboardLayout = m_BlackboardProvider.blackboard.layout;
m_FloatingWindowsLayout.previewLayout.CalculateDockingCornerAndOffset(m_MasterPreviewView.layout, layout);
m_FloatingWindowsLayout.blackboardLayout.CalculateDockingCornerAndOffset(m_BlackboardProvider.blackboard.layout, layout);
string serializedWindowLayout = JsonUtility.ToJson(m_FloatingWindowsLayout);
EditorUserSettings.SetConfigValue(m_FloatingWindowsLayoutKey, serializedWindowLayout);

105
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/WindowDockingLayout.cs


using System;
using UnityEngine;
namespace UnityEditor.ShaderGraph.Drawing
{
[Serializable]
public class WindowDockingLayout
{
[SerializeField]
bool m_DockingLeft;
public bool dockingLeft
{
get { return m_DockingLeft; }
}
[SerializeField]
bool m_DockingTop;
public bool dockingTop
{
get { return m_DockingTop; }
}
[SerializeField]
float m_VerticalOffset;
public float verticalOffset
{
get { return m_VerticalOffset; }
}
[SerializeField]
float m_HorizontalOffset;
public float horizontalOffset
{
get { return m_HorizontalOffset; }
}
[SerializeField]
Vector2 m_Size;
public Vector2 size
{
get { return m_Size; }
}
public void CalculateDockingCornerAndOffset(Rect layout, Rect parentLayout)
{
Vector2 layoutCenter = new Vector2(layout.x + layout.width * .5f, layout.y + layout.height * .5f);
layoutCenter /= parentLayout.size;
m_DockingLeft = layoutCenter.x < .5f;
m_DockingTop = layoutCenter.y < .5f;
if (m_DockingLeft)
{
m_HorizontalOffset = layout.x;
}
else
{
m_HorizontalOffset = parentLayout.width - layout.x - layout.width;
}
if (m_DockingTop)
{
m_VerticalOffset = layout.y;
}
else
{
m_VerticalOffset = parentLayout.height - layout.y - layout.height;
}
m_Size = layout.size;
}
public Rect GetLayout(Rect parentLayout)
{
Rect layout = new Rect();
layout.size = size;
if (dockingLeft)
{
layout.x = horizontalOffset;
}
else
{
layout.x = parentLayout.width - size.x - horizontalOffset;
}
if (dockingTop)
{
layout.y = verticalOffset;
}
else
{
layout.y = parentLayout.height - size.y - verticalOffset;
}
return layout;
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/WindowDockingLayout.cs.meta


fileFormatVersion: 2
guid: 5f70875ecccbc924b8f9f0d58bbb37e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

65
MaterialGraphProject/Assets/TestAssets/RockMaterial1.sbsar.meta


fileFormatVersion: 2
guid: b69a7e88e13e24260acb38513f619ff2
timeCreated: 1495753980
licenseType: Pro
SubstanceImporter:
serializedVersion: 5
materialInstances:
- serializedVersion: 16
name: RockMaterial1
prototypeName: RockMaterial1
shaderName:
shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
shaderKeywords:
renderQueue: -1
lightmapFlags: 4
inputs: []
materialInformation:
serializedVersion: 5
offset: {x: 0, y: 0}
scale: {x: 1, y: 1}
generateMipmaps: 1
generateAllOutputs: 0
animationUpdateRate: 0
materialProperties:
serializedVersion: 3
texEnvs: []
floats: []
colors: []
textureParameters:
- name: RockMaterial1_basecolor
alphaSource: 6
filterMode: 1
aniso: 1
wrapMode: 0
- name: RockMaterial1_normal
alphaSource: 0
filterMode: 1
aniso: 1
wrapMode: 0
- name: RockMaterial1_metallic
alphaSource: 7
filterMode: 1
aniso: 1
wrapMode: 0
textureAssignments:
- shaderProp: _MainTex
material: {instanceID: 0}
baseUID: 779270956
- shaderProp: _BumpMap
material: {instanceID: 0}
baseUID: 779270958
- shaderProp: _MetallicGlossMap
material: {instanceID: 0}
baseUID: 779270954
buildTargetSettings:
- serializedVersion: 2
buildTarget:
textureWidth: 512
textureHeight: 512
textureFormat: 0
loadingBehavior: 1
deletedPrototypes: []
userData:
assetBundleName:
assetBundleVariant:

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存