using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.SceneManagement; using UnityEngine.UI; using System.Linq; /// /// 先民足迹控制类 /// public class XMZJ : MonoBehaviour { public static XMZJ Instance; private void Awake() { Instance = this; } /// /// 需要隐藏的对象 /// public GameObject[] objsToHide; /// /// 返回按钮 /// public GameObject objReturn; /// /// 天空盒子,主场景及先民足迹天空盒 /// public Material[] skyboxs; /// /// 当前先民足迹的索引,默认为0(主场景) /// int currentXMZJIndex; /// /// 先民的足迹场景名称前缀 /// string xmzjScenePre = "XMZJ_Scene"; /// /// 返回主场景 /// 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; } /// /// 加载先民的足迹场景 /// /// 场景索引 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); } } /// /// 加载结束后的事件处理 /// 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; } /// /// 设置摄像机在先民足迹场景中的默认位置 /// 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); } } }