Version: 2021.1

HandleUtility.placeObjectCustomPasses

切换到手册

描述

Subscribe to this event to handle object placement in the SceneView.

This delegate is invoked by PlaceObject when drag and dropping objects from the Hierarchy and Project views.

using UnityEditor;
using UnityEngine;

static class PlaceObjectExample { static readonly Plane s_GroundPlane = new Plane(Vector3.up, Vector3.zero);

[InitializeOnLoadMethod] static void InitPlaceObjectHandler() { HandleUtility.placeObjectCustomPasses += PlaneRaycast; }

// In this example, we register a plane at the scene origin to test for object placement. static bool PlaneRaycast(Vector2 mousePosition, out Vector3 position, out Vector3 normal) { Ray worldRay = HandleUtility.GUIPointToWorldRay(mousePosition); float distance;

if (s_GroundPlane.Raycast(worldRay, out distance)) { position = worldRay.GetPoint(distance); normal = s_GroundPlane.normal; return true; }

position = Vector3.zero; normal = Vector3.up; return false; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961