119 lines
2.9 KiB
C#
119 lines
2.9 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Networking;
|
||
using UnityEngine.SceneManagement;
|
||
using UnityEngine.UI;
|
||
using System.Linq;
|
||
|
||
/// <summary>
|
||
/// 先民足迹控制类
|
||
/// </summary>
|
||
public class XMZJ : MonoBehaviour
|
||
{
|
||
public static XMZJ Instance;
|
||
|
||
private void Awake()
|
||
{
|
||
Instance = this;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 需要隐藏的对象
|
||
/// </summary>
|
||
public GameObject[] objsToHide;
|
||
|
||
/// <summary>
|
||
/// 返回按钮
|
||
/// </summary>
|
||
public GameObject objReturn;
|
||
|
||
/// <summary>
|
||
/// 天空盒子,主场景及先民足迹天空盒
|
||
/// </summary>
|
||
public Material[] skyboxs;
|
||
|
||
/// <summary>
|
||
/// 当前先民足迹的索引,默认为0(主场景)
|
||
/// </summary>
|
||
int currentXMZJIndex;
|
||
|
||
/// <summary>
|
||
/// 先民的足迹场景名称前缀
|
||
/// </summary>
|
||
string xmzjScenePre = "XMZJ_Scene";
|
||
|
||
/// <summary>
|
||
/// 返回主场景
|
||
/// </summary>
|
||
public void ReturnToMain()
|
||
{
|
||
foreach (var obj in objsToHide)
|
||
{
|
||
obj.SetActive(true);
|
||
}
|
||
|
||
objReturn.SetActive(false);
|
||
RenderSettings.skybox = skyboxs[0];
|
||
SceneLoader.Instance.SetCameraPosition(new Vector3(20, 0.515f, 48), new Vector3(0, -10, 0));
|
||
|
||
BundleLoader.Instance.UnLoadCurrentScene();
|
||
|
||
currentXMZJIndex = 0;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 加载先民的足迹场景
|
||
/// </summary>
|
||
/// <param name="index">场景索引</param>
|
||
public void LoadXMZJ(int index)
|
||
{
|
||
if (currentXMZJIndex != index)
|
||
{
|
||
BaseController.CanControl = false;
|
||
currentXMZJIndex = index;
|
||
string sceneName = xmzjScenePre + currentXMZJIndex;
|
||
BundleLoader.Instance.LoadScene(Application.isEditor ? sceneName + "_win" : sceneName, sceneName, XMZJLoaded);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 加载结束后的事件处理
|
||
/// </summary>
|
||
void XMZJLoaded()
|
||
{
|
||
// 设置天空盒
|
||
RenderSettings.skybox = skyboxs[currentXMZJIndex];
|
||
|
||
foreach (var obj in objsToHide)
|
||
{
|
||
obj.SetActive(false);
|
||
}
|
||
objReturn.SetActive(true);
|
||
|
||
|
||
// 卸载旧场景资源
|
||
BundleLoader.Instance.UnLoadOldScene();
|
||
|
||
SetCameraPosition();
|
||
|
||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(xmzjScenePre + currentXMZJIndex));
|
||
|
||
BaseController.CanControl = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置摄像机在先民足迹场景中的默认位置
|
||
/// </summary>
|
||
void SetCameraPosition()
|
||
{
|
||
GameObject objSP = GameObject.Find("StartPosition" + currentXMZJIndex);
|
||
if (objSP != null)
|
||
{
|
||
CommonData.MainCamera.gameObject.SetActive(false);
|
||
CommonData.MainCamera.transform.position = objSP.transform.position;
|
||
CommonData.MainCamera.transform.rotation = objSP.transform.rotation;
|
||
CommonData.MainCamera.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
} |