Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Handles.PositionHandle

マニュアルに切り替える
public static Vector3 PositionHandle(Vector3 position, Quaternion rotation);

パラメーター

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

戻り値

Vector3 ユーザーのハンドル操作によって更新された値。ユーザーがハンドルを操作しない場合は、関数に渡した値と同じ値が返されます。

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

説明

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

これは Unityのビルトインにある Move ツールのように動作します。 ハンドルの向きを制御するには、この関数を呼び出す前に Handles.matrix を設定します。


オブジェクトを常に Position ハンドルを向くように作成します。

この例を使用するには、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( ) { transform.LookAt( lookTarget ); } }