using UnityEngine; using UnityEngine.UI; public class IconRodRoot : MonoBehaviour { public Camera rodCamera; public GameObject[] fx_fishingrods; public RenderTexture rt; //模型存放节点 public Transform avatar; public GameObject fishrodback; private void Awake() { transform.localScale = Vector3.one / transform.lossyScale.x; transform.position = new Vector3(0, 0, 0); if (fishrodback != null) { int level = QualitySettings.GetQualityLevel(); fishrodback.SetActive(level > 1); } } public void SetRawImage(RawImage rawImageRod) { RectTransform rectTransform = rawImageRod.GetComponent(); 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; } } }