我想用Handles.Label()
在一些rect转换上显示一些标签。它显示默认字体大小的文本,而不管场景窗口中的缩放级别如何。
public class NodeWrapper : MonoBehaviour {
public Node node;
void OnDrawGizmos()
{
Handles.Label(transform.position + new Vector3(-.9f, .5f), node.Name);
Handles.Label(transform.position + new Vector3(-.9f, .4f), node.Info);
...
}
}
所以当我放大到场景窗口时,标签就会越来越近,在某个时候它们会变得不可读。当缩放级别改变时,我想显示/隐藏一些线条。我怎样才能做到这一点?是否有可能得到当前的放大水平的场景?
PS。我正在为另一个游戏开发一个节点编辑器,我使用场景窗口来创建和序列化一些对象。我的目标仅仅是使用2D配置的场景窗口。
发布于 2017-02-17 02:48:22
要使Handles.Label
函数在不同的缩放级别上工作,您需要更改两件事:
GUIStyle
的函数签名fontSize
时,计算orthographicSize
。例如:
// this is the internal camera rendering the scene view, not the main camera!
float zoom = SceneView.currentDrawingSceneView.camera.orthographicSize;
// the style object allows you to control font size, among many other settings
var style = new GUIStyle();
// this value depends on your scene, tweak it to match the other objects
int fontSize = 70;
// as you zoom out, the ortho size actually increases,
// so dividing by it makes the font smaller which is exactly what we need
style.fontSize = Mathf.FloorToInt(fontSize / zoom);
Handles.Label(transform.position + new Vector3(-.9f, .5f), node.Name, style);
发布于 2016-07-04 03:09:09
docs.unity3d.com/ScriptReference/Camera-orthographicSize.html,orthographicSize值是您的缩放,创建一个脚本从main.camera获取该值,并根据该值操作标签。
小小的例子,
public Camera cam;
private float orthoZoom;
void Update() {
orthoZoom = cam.orthographicSize;
}
发布于 2021-08-02 20:16:14
我测试过了,结果成功了!
float zoom = SceneView.currentDrawingSceneView.size;
float fontSize = 300f;
var style = new GUIStyle();
style.fontSize = Mathf.FloorToInt(fontSize / zoom);
https://gamedev.stackexchange.com/questions/124864
复制