Version: 2022.3
言語: 日本語
public static Vector3 PositionHandle (Vector3 position, Quaternion rotation);
public static Vector3 PositionHandle (Handles.PositionHandleIds ids, Vector3 position, Quaternion rotation);

パラメーター

position The center of the handle in 3D space.
rotation The orientation of the handle in 3D space.
ids The control IDs of the handles. Use PositionHandleIds.default.

戻り値

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

説明

Make a position handle.

This handle behaves like the built-in move tool in Unity.


Position handle in the Scene View.''

Add the following script to your Assets folder as PositionHandleExample.cs and add the PositionHandleExample component to an object in a Scene.

using UnityEngine;

[ExecuteInEditMode] public class PositionHandleExample : MonoBehaviour { public Vector3 targetPosition { get { return m_TargetPosition; } set { m_TargetPosition = value; } } [SerializeField] private Vector3 m_TargetPosition = new Vector3(1f, 0f, 2f);

public virtual void Update() { transform.LookAt(m_TargetPosition); } }

Add the following script to Assets/Editor as PositionHandleExampleEditor.cs and select the object with the PositionHandleExample component.

using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(PositionHandleExample)), CanEditMultipleObjects] public class PositionHandleExampleEditor : Editor { protected virtual void OnSceneGUI() { PositionHandleExample example = (PositionHandleExample)target;

EditorGUI.BeginChangeCheck(); Vector3 newTargetPosition = Handles.PositionHandle(example.targetPosition, Quaternion.identity); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(example, "Change Look At Target Position"); example.targetPosition = newTargetPosition; example.Update(); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961