DragAndDrop.StartDrag

Unity · Версия 2020.3 LTS · Scripting · DragAndDrop

DragAndDrop.StartDrag

Объявление

public static void StartDrag(string title);

Описание

Начать операцию перетаскивания.

Начинает операцию перетаскивания с текущим состоянием перетаскиваемого объекта. Используйте пути и/или objectReferences для настройки состояния перетаскивания.

Смотрите так же: PrepareStartDrag, paths, objectReferences.

using UnityEngine;
using UnityEditor;

public class Example : MonoBehaviour
{
    void OnGUI()
    {
        if (Event.current.type == EventType.MouseDrag)
        {
            // Clear out drag data
            DragAndDrop.PrepareStartDrag();

            // Set up what we want to drag
            DragAndDrop.paths[0] = "/Users/joe/myPath.txt";

            // Start the actual drag
            DragAndDrop.StartDrag("Dragging title");

            // Make sure no one uses the event after us
            Event.current.Use();
        }
    }
}

Обновлено 17 ноября 2026 г.