获取此编辑器目标的自定义边界。
使用此方法检索从 Editor 类派生的自定义窗口的边界。此方法始终与 Editor.HasFrameBounds 结合使用,后者根据实现返回 true 或 false。
using UnityEngine; using UnityEditor;
// This example traverses all bones in the hierarchy and calculates bounds for the entire object public class GameObjectEditorWindow: Editor { private bool HasFrameBounds() { // the result of this function depends on implementation // it will most likely be used to evaluate whether bounds // can exist for the targets of this Editor Window return Selection.objects.Length > 0; }
public Bounds OnGetFrameBounds() { Transform bone = Selection.activeTransform; Bounds bounds = new Bounds(bone.position, new Vector3(0, 0, 0)); foreach (Transform child in bone) bounds.Encapsulate(child.position);
if (bone.parent) bounds.Encapsulate(bone.parent.position);
return bounds; } }