浏览代码

Remove zooming in inspector preview

/main
Jens Holm 7 年前
当前提交
a4e8458d
共有 5 个文件被更改,包括 1 次插入60 次删除
  1. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.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/GraphInspectorView.cs


m_PreviewTextureView = new PreviewTextureView { name = "preview", image = Texture2D.blackTexture };
m_PreviewTextureView.AddManipulator(new Draggable(OnMouseDrag, true));
m_PreviewTextureView.AddManipulator(new Scrollable(OnMouseScroll));
bottomContainer.Add(m_PreviewTextureView);
m_PreviewScrollPosition = new Vector2(0f, 0f);

masterNode.onModified(masterNode, ModificationScope.Node);
}
void OnMouseScroll(float scrollDelta)
{
m_Graph.previewData.scale -= scrollDelta * .01f;
m_Graph.previewData.scale = Mathf.Clamp(m_Graph.previewData.scale, .1f, 4f);
masterNode.onModified(masterNode, ModificationScope.Node);
}
void OnAddProperty()
{
var gm = new GenericMenu();

if (m_Graph.previewData.serializedMesh.mesh != changedMesh)
{
m_Graph.previewData.rotation = Quaternion.identity;
m_Graph.previewData.scale = 1f;
}
m_Graph.previewData.serializedMesh.mesh = changedMesh;

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


Graphics.Blit(Texture2D.whiteTexture, renderData.renderTexture, m_SceneResources.checkerboardMaterial);
var mesh = (renderData == masterRenderData && m_Graph.previewData.serializedMesh.mesh) ? m_Graph.previewData.serializedMesh.mesh : m_SceneResources.sphere;
Quaternion rotation = (renderData == masterRenderData) ? m_Graph.previewData.rotation : Quaternion.identity;
float scale = (renderData == masterRenderData) ? m_Graph.previewData.scale : 1f;
previewTransform *= Matrix4x4.Scale(Vector3.one * scale * .75f / mesh.bounds.extents.magnitude);
previewTransform *= Matrix4x4.Scale(Vector3.one * 1f / mesh.bounds.extents.magnitude);
previewTransform *= Matrix4x4.Translate(-mesh.bounds.center);
}

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


using System;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing
{
public class Scrollable : MouseManipulator
{
Action<float> m_Handler;
public Scrollable(Action<float> handler)
{
m_Handler = handler;
activators.Add(new ManipulatorActivationFilter()
{
button = MouseButton.LeftMouse
});
}
protected override void RegisterCallbacksOnTarget()
{
target.RegisterCallback(new EventCallback<WheelEvent>(OnMouseWheel), Capture.NoCapture);
}
protected override void UnregisterCallbacksFromTarget()
{
target.UnregisterCallback(new EventCallback<WheelEvent>(OnMouseWheel), Capture.NoCapture);
}
void OnMouseWheel(WheelEvent evt)
{
m_Handler(evt.delta.y);
}
}
}

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


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