您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
47 行
1.1 KiB
47 行
1.1 KiB
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UInput = UnityEngine.Input;
|
|
|
|
namespace UIWidgetsSample.RaycastableScene
|
|
{
|
|
public class DragRotate : MonoBehaviour
|
|
{
|
|
Vector2? _lastPosition;
|
|
|
|
public static Vector2 mousePosition
|
|
{
|
|
get
|
|
{
|
|
return new Vector2(UInput.mousePosition.x, UInput.mousePosition.y);
|
|
}
|
|
}
|
|
|
|
void OnMouseDown()
|
|
{
|
|
if (EventSystem.current.IsPointerOverGameObject())
|
|
{
|
|
return;
|
|
}
|
|
|
|
_lastPosition = mousePosition;
|
|
}
|
|
|
|
private void OnMouseUp()
|
|
{
|
|
_lastPosition = null;
|
|
}
|
|
|
|
private void OnMouseDrag()
|
|
{
|
|
if (_lastPosition == null)
|
|
{
|
|
return;
|
|
}
|
|
Vector2 direction = mousePosition - _lastPosition.Value;
|
|
_lastPosition = mousePosition;
|
|
|
|
transform.Rotate(-direction.y, -direction.x, 0, Space.World);
|
|
}
|
|
}
|
|
}
|