83 lines
2.2 KiB
C#
83 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
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, (int)RenderTextureFormat.Depth);
|
|
|
|
_Protected(parent);
|
|
|
|
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;
|
|
_cameraObj.SetActive(false);
|
|
}
|
|
|
|
private void _Protected(Transform parent)
|
|
{
|
|
_TryDeleteCamera(parent);
|
|
}
|
|
|
|
private void _TryDeleteCamera(Transform parent)
|
|
{
|
|
var transList = new List<Transform>();
|
|
for (int i = 0; i < parent.childCount; i++)
|
|
{
|
|
var child = parent.GetChild(i);
|
|
if (child.name.Equals("head_camera_neck(Clone)"))
|
|
{
|
|
transList.Add(child);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < transList.Count; i++)
|
|
{
|
|
var trans = transList[i];
|
|
if (UnityEngine.Application.isPlaying)
|
|
{
|
|
Object.Destroy(trans.gameObject);
|
|
}
|
|
else
|
|
{
|
|
Object.DestroyImmediate(trans.gameObject);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
rt.Release();
|
|
rt = null;
|
|
|
|
Object.Destroy(_cameraObj);
|
|
_cameraObj = null;
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
_cameraObj.SetActive(true);
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
_cameraObj.SetActive(false);
|
|
}
|
|
}
|
|
}
|