You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[RequireComponent(typeof(Image))]
public class ImageOp : MonoBehaviour, IBeginDragHandler, IDragHandler
{
// Start is called before the first frame update
public bool dragOnSurfaces = true;
public float scaleSpeed = 0.01f;
public float moveScale = 0.01f;
private Vector2 startPostion;
void Update()
{
float offset = Input.GetAxis("Mouse ScrollWheel");
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
Debug.Log("ScrollWheel<0");
float scale = transform.localScale.x + offset * scaleSpeed;
ScaleImage(scale);
}
}
public void OnBeginDrag(PointerEventData eventData)
{
startPostion = eventData.position;
}
public void OnDrag(PointerEventData eventData)
{
//if (m_DraggingIcons[eventData.pointerId] != null)
// SetDraggedPosition(eventData);
transform.position += new Vector3(eventData.delta.x, eventData.delta.y,0) * moveScale;
}
public void AddScale(float offset)
{
float scale = transform.localScale.x + offset;
ScaleImage(scale);
}
private void ScaleImage(float s)
{
float scale = Mathf.Clamp(s, 0.3f, 10);
transform.localScale = new Vector3(scale, scale, scale);
}
}