71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using PhxhSDK;
|
|
using UnityEngine;
|
|
using Constants = Framework.Constants;
|
|
|
|
namespace Gameplay.Other.HeadCamera
|
|
{
|
|
public class UnitHeadCamera
|
|
{
|
|
public RenderTexture rt;
|
|
private GameObject _cameraObj;
|
|
|
|
public const int RT_WIDTH = 173;
|
|
public const int RT_HEIGHT = 206;
|
|
|
|
public void Init(Transform parent)
|
|
{
|
|
rt = new RenderTexture(RT_WIDTH, RT_HEIGHT, 32);
|
|
|
|
#if UNITY_EDITOR
|
|
if (!Application.isPlaying)
|
|
{
|
|
_Protected(parent);
|
|
}
|
|
#endif
|
|
|
|
var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(Constants.STORY_HEAD_CAMERA_PATH);
|
|
var cameraObj = Object.Instantiate(sampleObj, parent);
|
|
cameraObj.transform.ResetLocals();
|
|
var rawCamera = cameraObj.GetComponentInChildren<Camera>();
|
|
rawCamera.targetTexture = rt;
|
|
_cameraObj = cameraObj;
|
|
}
|
|
|
|
private void _Protected(Transform parent)
|
|
{
|
|
while (true)
|
|
{
|
|
var findTrans = parent.Find("head_camera_neck(Clone)");
|
|
if (findTrans != null)
|
|
{
|
|
Object.DestroyImmediate(findTrans.gameObject);
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
rt.Release();
|
|
rt = null;
|
|
|
|
Object.Destroy(_cameraObj);
|
|
_cameraObj = null;
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
_cameraObj.SetActive(true);
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
_cameraObj.SetActive(false);
|
|
}
|
|
}
|
|
}
|