138 lines
3.6 KiB
C#
138 lines
3.6 KiB
C#
using Gameplay;
|
|
using PhxhSDK.Res;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using Button = UnityEngine.UI.Button;
|
|
|
|
public class UI_CampController : UIWindow
|
|
{
|
|
/// <summary>
|
|
/// 返回按钮
|
|
/// </summary>
|
|
private Button buttonBack;
|
|
/// <summary>
|
|
/// 主页按钮
|
|
/// </summary>
|
|
private Button buttonHome;
|
|
/// <summary>
|
|
/// 技能树按钮
|
|
/// </summary>
|
|
private Button buttonSkill;
|
|
/// <summary>
|
|
/// 切换上一个相机点位
|
|
/// </summary>
|
|
private Button buttonLastCamera;
|
|
/// <summary>
|
|
/// 切换下一个相机点位
|
|
/// </summary>
|
|
private Button buttonNextCamera;
|
|
|
|
/// <summary>
|
|
/// 相机点位
|
|
/// </summary>
|
|
private readonly List<CameraStand> listCameraStand = new();
|
|
private CameraRoot cameraRoot;
|
|
/// <summary>
|
|
/// 当前相机点位索引
|
|
/// </summary>
|
|
private int curCameraIndex;
|
|
|
|
public override void OnInit()
|
|
{
|
|
buttonBack = GetComponent<Button>("Button_Back/Button_back");
|
|
buttonHome = GetComponent<Button>("Button_Back/Button_Home");
|
|
buttonSkill = GetComponent<Button>("Button_Skill");
|
|
buttonLastCamera = GetComponent<Button>("Button_Left");
|
|
buttonNextCamera = GetComponent<Button>("Button_Right");
|
|
|
|
BindButton(buttonBack, OnClickBack);
|
|
BindButton(buttonHome, OnClickBack);
|
|
BindButton(buttonSkill, OnSkill);
|
|
BindButton(buttonLastCamera, OnLastCamera);
|
|
BindButton(buttonNextCamera, OnNextCamera);
|
|
}
|
|
|
|
protected override void OnShowWindow(object data = null)
|
|
{
|
|
SceneHandle sceneHandle = GameSceneHelper.Instance.GetCurrentUIViewScene();
|
|
if (sceneHandle == null)
|
|
{
|
|
DebugUtil.LogError("未获取到营地场景");
|
|
return;
|
|
}
|
|
|
|
GameObject[] gos = sceneHandle.Scene.GetRootGameObjects(); // TODO 临时获取方法
|
|
foreach (GameObject go in gos)
|
|
{
|
|
if (go.name.Equals("CameraStands"))
|
|
{
|
|
listCameraStand.AddRange(go.GetComponentsInChildren<CameraStand>());
|
|
continue;
|
|
}
|
|
|
|
if (go.name.Equals("CameraRoot"))
|
|
cameraRoot = go.GetComponent<CameraRoot>();
|
|
}
|
|
|
|
if (listCameraStand.Count <= 0)
|
|
{
|
|
DebugUtil.LogError("未获取到相机点位");
|
|
return;
|
|
}
|
|
|
|
ApplyCameraPoint(0);
|
|
}
|
|
|
|
private void ApplyCameraPoint(int index)
|
|
{
|
|
curCameraIndex = index;
|
|
|
|
listCameraStand[curCameraIndex].Apply(cameraRoot.Camera);
|
|
}
|
|
|
|
#region 回调
|
|
/// <summary>
|
|
/// 点击退出
|
|
/// </summary>
|
|
private void OnClickBack()
|
|
{
|
|
GameStateManager.Instance.ChangeState(new GameStateMainScene());
|
|
//await CommonUtils.CloseUIWithScene(UINameConst.UI_Camp);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 技能养成
|
|
/// </summary>
|
|
private async void OnSkill()
|
|
{
|
|
await UI_CommandSkillCultivateController.Open();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换上一个相机
|
|
/// </summary>
|
|
private void OnLastCamera()
|
|
{
|
|
if (listCameraStand.Count <= 0)
|
|
return;
|
|
|
|
if (curCameraIndex > 0)
|
|
ApplyCameraPoint(curCameraIndex - 1);
|
|
else
|
|
ApplyCameraPoint(listCameraStand.Count - 1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换下一个相机
|
|
/// </summary>
|
|
private void OnNextCamera()
|
|
{
|
|
if (listCameraStand.Count <= 0)
|
|
return;
|
|
|
|
ApplyCameraPoint((curCameraIndex + 1) % listCameraStand.Count);
|
|
}
|
|
#endregion
|
|
} |