浏览代码

Merge branch 'master' into peter-fixes

# Conflicts:
#	MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
/main
Peter Bay Bastian 7 年前
当前提交
56f2361c
共有 4 个文件被更改,包括 78 次插入38 次删除
  1. 64
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs
  2. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  3. 47
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  4. 4
      MaterialGraphProject/Assets/UnityShaderEditor/package.json

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


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEditor.Experimental.UIElements;
using UnityEngine.Experimental.UIElements;

ObjectField m_PreviewMeshPicker;
MasterNode m_MasterNode;
Mesh m_PreviousMesh;
List<string> m_DoNotShowPrimitives = new List<string>( new string[] {PrimitiveType.Plane.ToString()});
static Type s_ContextualMenuManipulator = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).FirstOrDefault(t => t.FullName == "UnityEngine.Experimental.UIElements.ContextualMenuManipulator");
static Type s_ObjectSelector = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).FirstOrDefault(t => t.FullName == "UnityEditor.ObjectSelector");
this.clippingOptions = ClippingOptions.ClipAndCacheContents;
m_Graph = graph;
AddStyleSheetPath("Styles/MaterialGraph");

var topContainer = new VisualElement() { name = "top" };
{
var title = new Label(assetName + " master node preview") { name = "title" };
var title = new Label(assetName.Split('/').Last()) { name = "title" };
topContainer.Add(title);
}
Add(topContainer);

m_PreviewTextureView = new PreviewTextureView { name = "preview", image = Texture2D.blackTexture };
m_PreviewTextureView.AddManipulator(new Draggable(OnMouseDragPreviwMesh, true));
m_PreviewTextureView.AddManipulator(new Draggable(OnMouseDragPreviewMesh, true));
m_PreviewTextureView.AddManipulator((IManipulator)Activator.CreateInstance(s_ContextualMenuManipulator, (Action<ContextualMenuPopulateEvent>)BuildContextualMenu));
middleContainer.Add(m_PreviewTextureView);
m_PreviewScrollPosition = new Vector2(0f, 0f);

Add(middleContainer);
}
var bottomContainer = new VisualElement() { name = "bottom" };
void BuildContextualMenu(ContextualMenuPopulateEvent evt)
{
foreach (var primitiveTypeName in Enum.GetNames(typeof(PrimitiveType)))
m_PreviewMeshPicker = new ObjectField { name = "picker", objectType = typeof(Mesh) };
m_PreviewMeshPicker.OnValueChanged(OnPreviewMeshChanged);
bottomContainer.Add(m_PreviewMeshPicker);
if(m_DoNotShowPrimitives.Contains(primitiveTypeName))
continue;
evt.menu.AppendAction(primitiveTypeName, e => ChangePrimitiveMesh( primitiveTypeName ), ContextualMenu.MenuAction.AlwaysEnabled);
Add(bottomContainer);
evt.menu.AppendAction("Custom Mesh", e => ChangeMeshCustom(), ContextualMenu.MenuAction.AlwaysEnabled);
}
MasterNode masterNode

m_PreviewTextureView.Dirty(ChangeType.Repaint);
}
void OnPreviewMeshChanged(ChangeEvent<Object> changeEvent)
void ChangePrimitiveMesh(string primitiveName)
Mesh changedMesh = changeEvent.newValue as Mesh;
Mesh changedPrimitiveMesh = Resources.GetBuiltinResource(typeof(Mesh), string.Format("{0}.fbx", primitiveName)) as Mesh;
ChangeMesh(changedPrimitiveMesh);
}
void ChangeMesh(Mesh mesh)
{
Mesh changedMesh = mesh;
masterNode.Dirty(ModificationScope.Node);

m_Graph.previewData.serializedMesh.mesh = changedMesh;
}
private static EditorWindow Get()
{
PropertyInfo P = s_ObjectSelector.GetProperty("get", BindingFlags.Public | BindingFlags.Static);
return P.GetValue(null,null) as EditorWindow;
}
void OnMeshChanged(Object obj)
{
var mesh = obj as Mesh;
if (mesh == null)
mesh = m_PreviousMesh;
ChangeMesh(mesh);
}
void ChangeMeshCustom()
{
MethodInfo ShowMethod = s_ObjectSelector.GetMethod("Show", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly, Type.DefaultBinder, new[] {typeof(Object), typeof(Type), typeof(SerializedProperty), typeof(bool), typeof(List<int>), typeof(Action<Object>), typeof(Action<Object>)}, new ParameterModifier[7]);
m_PreviousMesh = m_Graph.previewData.serializedMesh.mesh;
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;

RefreshRenderTextureSize();
}
void OnMouseDragPreviwMesh(Vector2 deltaMouse)
void OnMouseDragPreviewMesh(Vector2 deltaMouse)
{
Vector2 previewSize = m_PreviewTextureView.contentRect.size;

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


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

47
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


justify-content: flex-start;
min-width: 200;
min-height: 200;
}
border-radius: 6;
border-top-width: 1;
border-bottom-width: 1;
border-left-width: 1;
border-right-width: 1;
border-color: rgb(25,25,25);
MasterPreviewView > #top {
background-color: rgb(64, 64, 64);
}
MasterPreviewView > #top > #title {
font-style: bold;
font-size: 11;
background-color: rgb(64, 64, 64);
border-top-left-radius: 6;
border-top-right-radius: 6;
}
MasterPreviewView > #top > #title {
font-size: 12;
text-color: rgb(180, 180, 180);
padding-top: 1;
padding-bottom: 2;
padding-left: 2;
padding-right: 2;
border-width: 10;
margin-bottom: 40;
border-color: rgb(0,10,190);
}
MasterPreviewView > #bottom {
background-color: rgb(79, 79, 79);
position-type: absolute;
position-bottom: 0;
position-left: 0;
position-right: 0;
padding-left: 10;
padding-right: 10;
padding-top: 8;
padding-bottom: 12;
}
MasterPreviewView > #bottom > #picker > ObjectFieldDisplay > Label {
font-size: 11;
border-width: 10;
border-color: rgb(200,10,190);
}
#resizeBorderFrame > .resize {

4
MaterialGraphProject/Assets/UnityShaderEditor/package.json


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