先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|