备份CatanBuilding瘦身独立工程
This commit is contained in:
63
Assets/Scripts/UI/FishingReward/FishIconRT.cs
Normal file
63
Assets/Scripts/UI/FishingReward/FishIconRT.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using cfg;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class FishIconRT : MonoBehaviour
|
||||
{
|
||||
RenderTexture rt;
|
||||
public Camera rtCamera;
|
||||
public Transform avatar;
|
||||
public int fieldOfView = 60;
|
||||
//鱼距离相机的位置
|
||||
public int fishPosZ = 20;
|
||||
GameObject goPrefab;
|
||||
private void Start()
|
||||
{
|
||||
transform.localScale = Vector3.one / transform.lossyScale.x;
|
||||
}
|
||||
public async void SetData(RawImage rawImage, FishData fishData)
|
||||
{
|
||||
RectTransform raw = rawImage.GetComponent<RectTransform>();
|
||||
rt = new RenderTexture((int)raw.rect.width, (int)raw.rect.height, 24, RenderTextureFormat.ARGB32);
|
||||
goPrefab = await Addressables.LoadAssetAsync<GameObject>(fishData.Fbx).Task;
|
||||
if (rt == null)
|
||||
{
|
||||
Addressables.Release(goPrefab);
|
||||
}
|
||||
else if (goPrefab != null)
|
||||
{
|
||||
rtCamera.fieldOfView = fieldOfView;
|
||||
rtCamera.enabled = true;
|
||||
Vector3 posWorld = new Vector3(fishData.TankPosition[0], fishData.TankPosition[1], fishData.TankPosition[2] + fishPosZ);
|
||||
var go = Instantiate(goPrefab, avatar);
|
||||
Fish fish = go.GetComponent<Fish>();
|
||||
fish.animator.transform.localPosition = Vector3.zero;
|
||||
go.transform.rotation = Quaternion.Euler(fishData.TankRotation[0], fishData.TankRotation[1], fishData.TankRotation[2]);
|
||||
go.transform.localScale = Vector3.one * fishData.TankScale;
|
||||
go.transform.localPosition = posWorld;
|
||||
rtCamera.targetTexture = rt;
|
||||
rawImage.texture = rt;
|
||||
rtCamera.Render();
|
||||
}
|
||||
else
|
||||
{
|
||||
rtCamera.enabled = false;
|
||||
}
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
rtCamera.targetTexture = null;
|
||||
if (rt != null)
|
||||
{
|
||||
rt.Release();
|
||||
Destroy(rt);
|
||||
rt = null;
|
||||
}
|
||||
if (goPrefab != null)
|
||||
{
|
||||
Addressables.Release(goPrefab);
|
||||
goPrefab = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user