浏览代码

Merge branch 'master' into tidy-master-preview

# Conflicts:
#	MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs
/main
Martin Thorzen 7 年前
当前提交
29361772
共有 16 个文件被更改,包括 96 次插入51 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/UVMaterialSlot.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/ColorNode.cs
  4. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/Blackboard.cs
  5. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardField.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardRow.cs
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardSection.cs
  8. 31
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs
  9. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs
  10. 62
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs
  11. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs
  12. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/SearchWindowProvider.cs
  13. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  14. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  15. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs
  16. 2
      MaterialGraphProject/Assets/UnityShaderEditor/package.json

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


{
if (!node.canDeleteNode)
return;
RemoveNodeNoValidate(node);
ValidateGraph();
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/UVMaterialSlot.cs


[Serializable]
public class UVMaterialSlot : Vector2MaterialSlot, IMayRequireMeshUV
{
private UVChannel m_Channel = UVChannel.UV0;
[SerializeField]
UVChannel m_Channel = UVChannel.UV0;
public UVChannel channel
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/ColorNode.cs


if ((value.color == m_Color.color) && (value.mode == m_Color.mode))
return;
m_Color = value;
Dirty(ModificationScope.Graph);
Dirty(ModificationScope.Node);
}
}

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


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

public Blackboard()
{
AddStyleSheetPath("Styles/Blackboard");
var tpl = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UnityShaderEditor/Editor/Resources/UXML/GraphView/Blackboard.uxml");
var tpl = Resources.Load<VisualTreeAsset>("UXML/GraphView/Blackboard");
m_MainContainer = tpl.CloneTree(null);
m_MainContainer.AddToClassList("mainContainer");

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


public BlackboardField(Texture icon, string text, string typeText)
{
var tpl = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UnityShaderEditor/Editor/Resources/UXML/GraphView/BlackboardField.uxml");
var tpl = Resources.Load<VisualTreeAsset>("UXML/GraphView/BlackboardField");
VisualElement mainContainer = tpl.CloneTree(null);
mainContainer.AddToClassList("mainContainer");

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardRow.cs


public BlackboardRow(VisualElement item, VisualElement propertyView)
{
var tpl = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UnityShaderEditor/Editor/Resources/UXML/GraphView/BlackboardRow.uxml") as VisualTreeAsset;
var tpl = Resources.Load<VisualTreeAsset>("UXML/GraphView/BlackboardRow");
VisualElement mainContainer = tpl.CloneTree(null);
mainContainer.AddToClassList("mainContainer");

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardSection.cs


public BlackboardSection()
{
var tpl = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UnityShaderEditor/Editor/Resources/UXML/GraphView/BlackboardSection.uxml") as VisualTreeAsset;
var tpl = Resources.Load<VisualTreeAsset>("UXML/GraphView/BlackboardSection");
m_MainContainer = tpl.CloneTree(null);
m_MainContainer.AddToClassList("mainContainer");

31
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs


ShowMethod.Invoke(Get(), new object[] { null, typeof(Mesh), null, false, null, (Action<Object>)OnMeshChanged, (Action<Object>)OnMeshChanged });
}
public void RefreshRenderTextureSize()
{
RenderTextureDescriptor descriptor = m_PreviewRenderHandle.renderTexture.descriptor;
var targetWidth = m_PreviewTextureView.contentRect.width;
var targetHeight = m_PreviewTextureView.contentRect.height;
if (Mathf.Approximately(descriptor.width, targetHeight) && Mathf.Approximately(descriptor.height, targetWidth))
{
return;
}
descriptor.width = (int)m_PreviewTextureView.contentRect.width;
descriptor.height = (int)m_PreviewTextureView.contentRect.height;
m_PreviewRenderHandle.renderTexture.Release();
Object.DestroyImmediate(m_PreviewRenderHandle.renderTexture);
m_PreviewRenderHandle.renderTexture = new RenderTexture(descriptor);
}
public void UpdateRenderTextureOnNextLayoutChange()
{
RegisterCallback<PostLayoutEvent>(AdaptRenderTextureOnLayoutChange);
}
void AdaptRenderTextureOnLayoutChange(PostLayoutEvent evt)
{
UnregisterCallback<PostLayoutEvent>(AdaptRenderTextureOnLayoutChange);
RefreshRenderTextureSize();
}
void OnMouseDragPreviewMesh(Vector2 deltaMouse)
{
Vector2 previewSize = m_PreviewTextureView.contentRect.size;

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeBorderFrame.cs


set
{
m_StayWithinParentBounds = value;
foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles)
{
resizeHandle.stayWithinParentBounds = value;
}
}
}
bool m_MaintainApsectRatio;
public bool maintainAspectRatio
{
get { return m_MaintainApsectRatio; }
set
{
m_MaintainApsectRatio = value;
resizeHandle.stayWithinPanretBounds = value;
resizeHandle.maintainAspectRatio = value;
}
}
}

62
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs


bool m_StayWithinParentBounds;
public bool stayWithinPanretBounds
public bool stayWithinParentBounds
}
bool m_MaintainAspectRatio;
public bool maintainAspectRatio
{
get { return m_MaintainAspectRatio; }
set { m_MaintainAspectRatio = value; }
}
public Action OnResizeFinished;

bool moveWhileResizeHorizontal = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.BottomLeft || anchor == ResizeHandleAnchor.Left;
bool moveWhileResizeVertical = anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight || anchor == ResizeHandleAnchor.Top;
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResizeHorizontal, moveWhileResizeVertical)));
this.AddManipulator(new Draggable(mouseDelta => OnResize(mouseDelta, resizeDirection, moveWhileResizeHorizontal, moveWhileResizeVertical, anchor)));
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizeVertical)
void OnResize(Vector2 resizeDelta, ResizeDirection direction, bool moveWhileResizeHorizontal, bool moveWhileresizeVertical, ResizeHandleAnchor anchor)
{
Vector2 normalizedResizeDelta = resizeDelta / 2f;

Rect newLayout = m_ResizeTarget.layout;
// Resize from bottom/right
if (!moveWhileResizeHorizontal)
if (anchor == ResizeHandleAnchor.Left || anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.BottomLeft)
newLayout.width = Mathf.Max(newLayout.width + normalizedResizeDelta.x, minSize.x);
normalizedResizeDelta.x = 0f;
newLayout.xMin = Mathf.Min(newLayout.xMin + normalizedResizeDelta.x, newLayout.xMax - minSize.x);
if (!moveWhileresizeVertical)
else
newLayout.height = Mathf.Max(newLayout.height + normalizedResizeDelta.y, minSize.y);
normalizedResizeDelta.y = 0f;
newLayout.xMax = Mathf.Max(newLayout.xMax + normalizedResizeDelta.x, newLayout.xMin + minSize.x);
float previousFarX = m_ResizeTarget.layout.x + m_ResizeTarget.layout.width;
float previousFarY = m_ResizeTarget.layout.y + m_ResizeTarget.layout.height;
newLayout.width = Mathf.Max(newLayout.width - normalizedResizeDelta.x, minSize.x);
newLayout.height = Mathf.Max(newLayout.height - normalizedResizeDelta.y, minSize.y);
newLayout.x = Mathf.Min(newLayout.x + normalizedResizeDelta.x, previousFarX - minSize.x);
newLayout.y = Mathf.Min(newLayout.y + normalizedResizeDelta.y, previousFarY - minSize.y);
if (m_StayWithinParentBounds)
if (anchor == ResizeHandleAnchor.Top || anchor == ResizeHandleAnchor.TopLeft || anchor == ResizeHandleAnchor.TopRight)
float horizontalTranscendance = Mathf.Min(newLayout.x, 0f) + Mathf.Max(newLayout.xMax - m_ResizeTarget.parent.layout.width, 0f);
float verticalTranscendance = Mathf.Min(newLayout.y, 0f) + Mathf.Max(newLayout.yMax - m_ResizeTarget.parent.layout.height, 0f);
if (moveWhileResizeHorizontal)
{
newLayout.x -= horizontalTranscendance;
}
newLayout.width -= Mathf.Abs(horizontalTranscendance);
newLayout.yMin = Mathf.Min(newLayout.yMin + normalizedResizeDelta.y, newLayout.yMax - minSize.y);
}
else
{
newLayout.yMax = Mathf.Max(newLayout.yMax + normalizedResizeDelta.y, newLayout.yMin + minSize.y);
}
if (moveWhileresizeVertical)
{
newLayout.y -= verticalTranscendance;
}
newLayout.height -= Mathf.Abs(verticalTranscendance);
if (stayWithinParentBounds)
{
newLayout.xMin = Mathf.Max(newLayout.xMin, 0f);
newLayout.yMin = Mathf.Max(newLayout.yMin, 0f);
newLayout.xMax = Mathf.Min(newLayout.xMax, m_ResizeTarget.parent.layout.width);
newLayout.yMax = Mathf.Min(newLayout.yMax, m_ResizeTarget.parent.layout.height);
}
m_ResizeTarget.layout = newLayout;

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs


PropagateNodeSet(m_DirtyPreviews);
m_NodesWith3DPreview.Clear();
foreach (var index in m_DirtyPreviews)
foreach (var node in m_Graph.GetNodes<AbstractMaterialNode>())
var node = (AbstractMaterialNode)m_Graph.GetNodeFromTempId(m_Identifiers[index]);
if (node.previewMode == PreviewMode.Preview3D)
m_NodesWith3DPreview.Add(node.tempId.index);
}

void DestroyRenderData(PreviewRenderData renderData)
{
if (renderData.shaderData != null
&& renderData.shaderData.shader != null
&& renderData.shaderData.shader != null
if (renderData.shaderData != null && renderData.shaderData.node != null)
renderData.shaderData.node.onModified -= OnNodeModified;
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/SearchWindowProvider.cs


var nodeEntries = new List<NodeEntry>();
foreach (var type in Assembly.GetAssembly(typeof(AbstractMaterialNode)).GetTypes())
{
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode))))
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode))) && type != typeof(PropertyNode))
{
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[];
if (attrs != null && attrs.Length > 0)

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


ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView) { name = "resizeBorderFrame" };
masterPreviewResizeBorderFrame.stayWithinParentBounds = true;
masterPreviewResizeBorderFrame.maintainAspectRatio = true;
masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;
m_MasterPreviewView.Add(masterPreviewResizeBorderFrame);

m_MasterPreviewView.layout = m_FloatingWindowsLayout.previewLayout.GetLayout(layout);
m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout.GetLayout(layout);
m_MasterPreviewView.UpdateRenderTextureOnNextLayoutChange();
}
else
{

string serializedWindowLayout = JsonUtility.ToJson(m_FloatingWindowsLayout);
EditorUserSettings.SetConfigValue(m_FloatingWindowsLayoutKey, serializedWindowLayout);
m_MasterPreviewView.RefreshRenderTextureSize();
}
public void Dispose()

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


var height = previewNode.height;
m_PreviewTextureView.style.height = height;
m_PreviewTextureView.style.width = width;
}
public void Dispose()

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs


using UnityEditor.Experimental.AssetImporters;
using UnityEditor.ShaderGraph.Drawing;
[ScriptedImporter(10, ShaderGraphImporter.ShaderGraphExtension)]
[ScriptedImporter(11, ShaderGraphImporter.ShaderGraphExtension)]
public class ShaderGraphImporter : ScriptedImporter
{
public const string ShaderGraphExtension = "shadergraph";

var text = GetShaderText<MaterialGraph>(ctx.assetPath, out configuredTextures);
if (text == null)
text = errorShader;
var name = Path.GetFileNameWithoutExtension(ctx.assetPath);
string shaderName = string.Format("graphs/{0}", name);
text = text.Replace("Hidden/GraphErrorShader2", shaderName);

}
RegisterShaders(importedAssets);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/package.json


{
"name": "com.unity.shadergraph",
"description": "Shader Graph",
"version": "0.1.14",
"version": "0.1.16",
"unity": "2018.1",
"dependencies": {
}
正在加载...
取消
保存