Version: 2017.3

EditorWindow.OnInspectorUpdate()

切换到手册

描述

OnInspectorUpdate 以每秒 10 帧的速度调用,以便检视面板有机会进行更新。

\ 对齐选定对象的位置。

// Simple script that aligns the position of several selected GameObjects
// with the first selected one.

class AlignPosition extends EditorWindow { var alignToX = true;var alignToY = true; var alignToZ = true; var selected = ""; var alignTo = "";

@MenuItem("Example/Align position") static function Init() { var window = GetWindow(AlignPosition); window.Show(); } function OnInspectorUpdate() { // Call Repaint on OnInspectorUpdate as it repaints the windows // less times as if it was OnGUI/Update Repaint(); } function OnGUI() { GUILayout.Label("Select various Objects in the Hierarchy view"); selected = Selection.activeTransform ? Selection.activeTransform.name : ""; for(var t : Transform in Selection.transforms) if(t.GetInstanceID() != Selection.activeTransform.GetInstanceID()) alignTo += t.name + " "; EditorGUILayout.LabelField("Align: ", alignTo); alignTo = ""; EditorGUILayout.LabelField("With: ", selected);

alignToX = EditorGUILayout.Toggle("X", alignToX); alignToY = EditorGUILayout.Toggle("Y", alignToY); alignToZ = EditorGUILayout.Toggle("Z", alignToZ); if(GUILayout.Button("Align")) Align(); } function Align() { if(selected == "" || alignTo == "") Debug.LogError("No objects selected to align"); for(var t : Transform in Selection.transforms) { var alignementPosition = Selection.activeTransform.position; var newPosition : Vector3; newPosition.x = alignToX ? alignementPosition.x : t.position.x; newPosition.y = alignToY ? alignementPosition.y : t.position.y; newPosition.z = alignToZ ? alignementPosition.z : t.position.z; t.position = newPosition; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961