using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
//此脚本挂在 原图bg上
public class Camera_view : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
{
//带有mask 并放大的图片,形成的圆形view
public RectTransform fangdajing;
//ui 坐标差
Vector2 offets;
//进入激活放大镜
public void OnPointerEnter(PointerEventData eventData)
{
fangdajing.gameObject.SetActive(true);
print("enter");
}
//离开失活放大镜
public void OnPointerExit(PointerEventData eventData)
{
fangdajing.gameObject.SetActive(false);
print("exit");
}
// Update is called once per frame
void Update()
{
//使放大镜跟随鼠标移动
fangdajing.transform.position= Input.mousePosition;
//本物体 bg的ui坐标-放大镜的ui坐标得到ui坐标差
offets = transform.GetComponent<RectTransform>().anchoredPosition - fangdajing.transform.GetComponent<RectTransform>().anchoredPosition;
// print(offets);
}
private void LateUpdate()
{
//放大镜子类 放置扩大2倍的原图,并赋予坐标差
fangdajing.transform.GetChild(0).GetComponent<RectTransform>().anchoredPosition = 2*offets;
}
}
2D 放大镜
最新推荐文章于 2024-05-15 19:46:40 发布