浏览代码

Merge pull request #1218 from Unity-Technologies/decals/ui_use_handles

Add the ability to change decal shape with the handle ui control
/main
GitHub 7 年前
当前提交
a6d193f9
共有 2 个文件被更改,包括 66 次插入3 次删除
  1. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalProjectorComponent.cs
  2. 66
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalProjectorComponent.cs


private void DrawGizmo(bool selected)
{
var col = new Color(0.0f, 0.7f, 1f, 1.0f);
col.a = selected ? 0.3f : 0.1f;
Gizmos.color = col;
Gizmos.DrawCube(Vector3.zero, Vector3.one);
col.a = selected ? 0.5f : 0.2f;
Gizmos.color = col;
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);

66
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

private SerializedProperty m_DrawDistanceProperty;
private SerializedProperty m_FadeScaleProperty;
public class DecalBoundsHandle : BoxBoundsHandle
{
protected override Bounds OnHandleChanged(HandleDirection handle, Bounds boundsOnClick, Bounds newBounds)
{
// special case for Y axis because decal mesh is centered at 0, -0.5, 0
if (handle == HandleDirection.NegativeY)
{
m_Translation = Vector3.zero;
m_Scale = newBounds.size;
}
else if (handle == HandleDirection.PositiveY)
{
m_Translation = (newBounds.center + newBounds.extents - (m_Center + 0.5f * m_Size));
m_Scale = (m_Size + m_Translation);
}
else
{
m_Translation = newBounds.center - m_Center;
m_Scale = newBounds.size;
}
return newBounds;
}
public void SetSizeAndCenter(Vector3 inSize, Vector3 inCenter)
{
// boundsOnClick implies that it gets refreshed only if the handle is clicked on again, but we need actual center and scale which we set before handle is drawn every frame
m_Center = inCenter;
m_Size = inSize;
center = inCenter;
size = inSize;
}
private Vector3 m_Center;
private Vector3 m_Size;
public Vector3 m_Translation;
public Vector3 m_Scale;
}
private DecalBoundsHandle m_Handle = new DecalBoundsHandle();
private void OnEnable()
{

// Update material editor with the new material
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
}
void OnSceneGUI()
{
EditorGUI.BeginChangeCheck();
var mat = Handles.matrix;
var col = Handles.color;
Handles.color = Color.white;
// decal mesh is centered at (0, -0.5, 0)
// zero out the local scale in the matrix so that handle code gives us back the actual scale
Handles.matrix = Matrix4x4.TRS(m_DecalProjectorComponent.transform.position, m_DecalProjectorComponent.transform.rotation, Vector3.one) * Matrix4x4.Translate(new Vector3(0.0f, -0.5f* m_DecalProjectorComponent.transform.localScale.y, 0.0f));
// pass in the scale
m_Handle.SetSizeAndCenter(m_DecalProjectorComponent.transform.localScale, Vector3.zero);
m_Handle.DrawHandle();
if (EditorGUI.EndChangeCheck())
{
// adjust decal transform if handle changed
m_DecalProjectorComponent.transform.Translate(m_Handle.m_Translation);
m_DecalProjectorComponent.transform.localScale = m_Handle.m_Scale;
Repaint();
}
Handles.matrix = mat;
Handles.color = col;
}
public override void OnInspectorGUI()
{

正在加载...
取消
保存