Version: 5.4
public static Vector3 PositionHandle (Vector3 position, Quaternion rotation);

パラメーター

position 3D 空間でのハンドルの中心
rotation 3D 空間でのハンドルの向き

戻り値

Vector3 The new value modified by the user's interaction with the handle. If the user has not moved the handle, it returns the same value that you passed into the function.

説明

3D シーンビューの Position ハンドルを作成します。

This behaves like the built-in Move tool in Unity.

ハンドルの向きを制御するには、この関数を呼び出す前に Handles.matrix を設定します。




注意: 画面サイズに対して固定サイズのハンドルを持ちたい場合、HandleUtility.GetHandleSize を使用します。

この例を使用するには、Assets/Editor フォルダーにこのスクリプトを保存します。

using UnityEngine;
using UnityEditor;

[CustomEditor( typeof( PositionHandle ) )] public class PositionHandleEditor : Editor { void OnSceneGUI( ) { PositionHandle t = target as PositionHandle;

// Set the colour of the next handle to be drawn Handles.color = Color.magenta;

EditorGUI.BeginChangeCheck( ); Vector3 lookTarget = Handles.PositionHandle( t.lookTarget, Quaternion.identity );

if( EditorGUI.EndChangeCheck( ) ) { Undo.RecordObject( target, "Changed Look Target" ); t.lookTarget = lookTarget; t.Update( ); } }

}

そして、このスクリプトを LookAt 位置を編集したいオブジェクトに置きます。

using UnityEngine;

[ExecuteInEditMode] public class PositionHandle : MonoBehaviour { public Vector3 lookTarget = new Vector3( 0,2,0 );

public void Update( ) { // Make the object always face the position handle transform.LookAt( lookTarget ); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961