57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
public class AddSubCamera : MonoBehaviour
|
|
{
|
|
// ⭐ 相机获取委托:由游戏侧(GameManager)注入,框架层不再反向依赖 GameManager
|
|
public static Func<Camera> GetMainCamera;
|
|
public static Func<Camera> GetBulletCamera;
|
|
|
|
public Camera subCamera;
|
|
|
|
[Tooltip("true=鱼的相机(插入到子弹锁定层cam之前);false=鱼死亡爆奖相机(加到列表末尾,默认)")]
|
|
public bool isFishCamera = false;
|
|
|
|
private void Awake()
|
|
{
|
|
if (subCamera==null)
|
|
{
|
|
subCamera = GetComponent<Camera>();
|
|
}
|
|
}
|
|
private void Start()
|
|
{
|
|
Camera zhuCam = GetMainCamera != null ? GetMainCamera() : null;
|
|
if (zhuCam == null)
|
|
{
|
|
Debug.LogWarning("[AddSubCamera] GetMainCamera 未注入,跳过相机栈配置");
|
|
return;
|
|
}
|
|
|
|
UniversalAdditionalCameraData mainCameraData = zhuCam.GetUniversalAdditionalCameraData();
|
|
|
|
if (isFishCamera)
|
|
{
|
|
// 鱼相机:插到子弹锁定层(子弹层相机)之前,即鱼和爆奖中间夹层的前面
|
|
Camera cam = GetBulletCamera != null ? GetBulletCamera() : null;
|
|
int index = cam != null ? mainCameraData.cameraStack.IndexOf(cam) : -1;
|
|
if (index >= 0)
|
|
{
|
|
mainCameraData.cameraStack.Insert(index, subCamera);
|
|
}
|
|
else
|
|
{
|
|
mainCameraData.cameraStack.Add(subCamera);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 爆奖相机:直接加到列表末尾(cam子弹层保持在它前面)
|
|
mainCameraData.cameraStack.Add(subCamera);
|
|
}
|
|
}
|
|
}
|