40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class IconRodRoot : MonoBehaviour
|
|
{
|
|
public Camera rodCamera;
|
|
public GameObject[] fx_fishingrods;
|
|
public RenderTexture rt;
|
|
//模型存放节点
|
|
public Transform avatar;
|
|
private void Awake()
|
|
{
|
|
transform.localScale = Vector3.one / transform.lossyScale.x;
|
|
transform.position = new Vector3(10000, 0, 0);
|
|
}
|
|
public void SetRawImage(RawImage rawImageRod)
|
|
{
|
|
RectTransform rectTransform = rawImageRod.GetComponent<RectTransform>();
|
|
rt = new RenderTexture((int)rectTransform.rect.width, (int)rectTransform.rect.height, 24, RenderTextureFormat.ARGB32);
|
|
rodCamera.targetTexture = rt;
|
|
rodCamera.Render();
|
|
float fovRad = 30 * Mathf.Deg2Rad;
|
|
float aspectRatio = Screen.width / (float)Screen.height;
|
|
aspectRatio = Mathf.Clamp(aspectRatio, 0, 0.5625f) * 2340 / 1080;
|
|
rodCamera.fieldOfView = 2 * Mathf.Atan(Mathf.Tan(fovRad) * aspectRatio) * Mathf.Rad2Deg;
|
|
rawImageRod.texture = rt;
|
|
rawImageRod.gameObject.SetActive(true);
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
rodCamera.targetTexture = null;
|
|
if (rt != null)
|
|
{
|
|
rt.Release();
|
|
Destroy(rt);
|
|
rt = null;
|
|
}
|
|
}
|
|
}
|