浏览代码

Merge pull request #211 from Unity-Technologies/master-preview-zoom

Master preview zoom
/main
GitHub 7 年前
当前提交
341a6fc3
共有 5 个文件被更改,包括 59 次插入2 次删除
  1. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/MasterPreviewView.cs
  3. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs
  4. 34
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Scrollable.cs
  5. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Scrollable.cs.meta

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


[NonSerialized]
public Quaternion rotation = Quaternion.identity;
[NonSerialized]
public float scale = 1f;
}
}

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


m_PreviewScrollPosition = new Vector2(0f, 0f);
middleContainer.Add(m_PreviewTextureView);
middleContainer.AddManipulator(new Scrollable(OnScroll));
void OnScroll(float scrollValue)
{
float rescaleAmount = -scrollValue * .03f;
m_Graph.previewData.scale = Mathf.Clamp(m_Graph.previewData.scale + rescaleAmount, 0.2f, 5f);
}
{
{
foreach (var primitiveTypeName in Enum.GetNames(typeof(PrimitiveType)))
{
if(m_DoNotShowPrimitives.Contains(primitiveTypeName))

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


{
var mesh = m_Graph.previewData.serializedMesh.mesh ? m_Graph.previewData.serializedMesh.mesh : m_SceneResources.sphere;
var previewTransform = Matrix4x4.Rotate(m_Graph.previewData.rotation);
previewTransform *= Matrix4x4.Scale(Vector3.one * (Vector3.one).magnitude / mesh.bounds.size.magnitude);
var scale = m_Graph.previewData.scale;
previewTransform *= Matrix4x4.Scale(scale * Vector3.one * (Vector3.one).magnitude / mesh.bounds.size.magnitude);
previewTransform *= Matrix4x4.Translate(-mesh.bounds.center);
RenderPreview(masterRenderData, mesh, previewTransform);
}

34
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Scrollable.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using System;
namespace UnityEditor.ShaderGraph.Drawing
{
public class Scrollable : MouseManipulator
{
Action<float> m_Handler;
public Scrollable(Action<float> handler)
{
m_Handler = handler;
}
protected override void RegisterCallbacksOnTarget()
{
target.RegisterCallback<WheelEvent>(HandleMouseWheelEvent);
}
protected override void UnregisterCallbacksFromTarget()
{
target.UnregisterCallback<WheelEvent>(HandleMouseWheelEvent);
}
void HandleMouseWheelEvent(WheelEvent evt)
{
m_Handler(evt.delta.y);
evt.StopPropagation();
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Scrollable.cs.meta


fileFormatVersion: 2
guid: 9ea23c5e75fdbea49824261efe5fc133
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存