- Home /
Editor 3D tools with depth
Currently, something like Handles.PositionHandle has no visual indicator of depth except when the camera moves. This makes visually designing very difficult. Is it possible to make the handle interact with meshes to be semi-transparent when covered by a mesh (like collider gizmos) or change in size based on the distance from the scene camera?
Comment
Answer by Eno-Khaon · Oct 22, 2015 at 11:46 PM
After a bit of repair work done based on an ancient post by @Bunny83, I've put together a simple fixer-upper script which removes the scaling applied to the translation tool in a very basic manner.
Many further adjustments would be necessary to make it reasonably viable for use, but this is more for the proof of concept that it's not impossible to create:
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(GameObject))]
public class HandleScale : Editor
{
void OnSceneGUI()
{
if(Selection.activeGameObject != null)
{
if(Tools.current == Tool.Move)
{
Tools.hidden = true;
Selection.activeGameObject.transform.position = ScaledPositionHandle(Selection.activeGameObject.transform.position, Quaternion.identity, 3.0f);
}
else
{
Tools.hidden = false;
}
if(GUI.changed)
EditorUtility.SetDirty(target);
}
else
{
Tools.hidden = false;
}
}
Vector3 ScaledPositionHandle(Vector3 position, Quaternion rotation, float scale)
{
float handleSize = 1.0f;
Color color = Handles.color;
Handles.color = Handles.xAxisColor;
position = Handles.Slider(position, rotation * Vector3.right, handleSize * scale, new Handles.DrawCapFunction(Handles.ArrowCap), Handles.SnapValue(position.x, 1f));
position = Handles.Slider(position, rotation * Vector3.up, handleSize * scale, new Handles.DrawCapFunction(Handles.ArrowCap), Handles.SnapValue(position.y, 1f));
Handles.color = Handles.zAxisColor;
position = Handles.Slider(position, rotation * Vector3.forward, handleSize * scale, new Handles.DrawCapFunction(Handles.ArrowCap), Handles.SnapValue(position.z, 1f));
Handles.color = Handles.centerColor;
position = Handles.FreeMoveHandle(position, rotation, handleSize * scale * 0.15f, Vector3.zero, new Handles.DrawCapFunction(Handles.RectangleCap));
Handles.color = color;
return position;
}
}