验证是否可以为该编辑器计算自定义边界。
使用此方法验证是否应为该窗口调用 Editor.OnGetFrameBounds。场景视图在调用框架操作时会调用 `HasFrameBounds` 和 `OnGetFrameBounds`。框架操作可以从任何地方调用,但通常在按下 F 键以对选定游戏对象进行框架时调用。
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; } }