NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Framework/CameraManager.cs

72 lines
1.6 KiB
C#
Raw Normal View History

2023-08-22 19:08:45 +08:00
using UnityEngine;
2023-10-19 15:00:19 +08:00
namespace PhxhSDK
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
public class CameraManager : Singlenton<CameraManager>, IInitable
2023-08-22 19:08:45 +08:00
{
private Camera _mainCamera;
public Camera MainCamera
{
get
{
if (_mainCamera == null)
{
_mainCamera = Camera.main;
}
return _mainCamera;
}
}
public Camera UICamera
{
get { return UIRoot.Instance.UICamera; }
}
2023-10-19 15:00:19 +08:00
public Camera CreateCamera(string name, string tag = null)
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
var go = new GameObject(name);
var camera = go.AddComponent<Camera>();
if (tag != null)
{
camera.tag = tag;
}
return camera;
2023-08-22 19:08:45 +08:00
}
public void DestroyCamera(Camera camera)
{
if (camera != null)
{
2023-10-19 15:00:19 +08:00
GameObject.Destroy(camera.gameObject);
2023-08-22 19:08:45 +08:00
}
}
public void ReRenderAll()
{
foreach (var c in Camera.allCameras)
{
var oldEnabled = c.enabled;
c.enabled = true;
c.Render();
c.enabled = oldEnabled;
}
}
public void Init()
{
if (MainCamera == null)
{
2023-10-19 15:00:19 +08:00
CreateCamera("Main Camera", "MainCamera");
2023-08-22 19:08:45 +08:00
}
if (MainCamera != null)
{
GameObject.DontDestroyOnLoad(MainCamera.gameObject);
}
}
public void Release()
{
}
}
}