基本思路哦(两相机分别渲染两个物体)
1.两个“RenderTexture ”在这称R1,R2,两个相同的模型M1,M2,两个相机C1,C2,两个“RawImage”, RIm1,
RIm2
2.UI层将不动模型M1应用相机C1渲染到2d平面R1上作为基准view层,将移动模型M2应用相机C2渲染到2d平面R2上备用
3.新建mask层,子集下放至放大的R2,选好角度,并计算当前ui元素与基准的位置差offet1
4.移动M2使之刚好与基准匹配放大的视角,记录M2与M1的位置差为offet2,求出比值offet2/offet1(正负注意)为N
5.代码控制mask层随鼠标移动,并把移动的物体M2位置=N*(鼠标控制的mask层的RectTransform坐标-view的RectTransform坐标)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Test_1 : MonoBehaviour,IPointerEnterHandler
{
//插值
Vector3 offet;
//3d 移动的物体
public GameObject Cube_big;
//放大镜2d mask 层
public GameObject big_camera;
public void OnPointerEnter(PointerEventData eventData)
{
big_camera.SetActive(true);
}
// Update is called once per frame
void Update()
{
big_camera.transform.position = Input.mousePosition;
offet = big_camera.transform.GetComponent<RectTransform>().anchoredPosition - transform.GetComponent<RectTransform>().anchoredPosition;
Cube_big.transform.position = -0.00212f * offet;
}
}