142 lines
3.5 KiB
C#
142 lines
3.5 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.Events;
|
|||
|
|
using UnityEngine.Networking;
|
|||
|
|
using UnityEngine.SceneManagement;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
public class LoadNight : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
public GameObject objXMZJ_Scene2;
|
|||
|
|
|
|||
|
|
public GameObject objBtnReturn;
|
|||
|
|
|
|||
|
|
bool loading;
|
|||
|
|
|
|||
|
|
private void OnMouseDown()
|
|||
|
|
{
|
|||
|
|
if (!loading)
|
|||
|
|
{
|
|||
|
|
loading = true;
|
|||
|
|
|
|||
|
|
string sceneName = "XMZJ_Scene2_2";
|
|||
|
|
|
|||
|
|
string abName = Application.isEditor ? sceneName + "_win" : sceneName;
|
|||
|
|
|
|||
|
|
string abPath = Application.streamingAssetsPath + "/Bundles/" + abName + ".unity3d";
|
|||
|
|
|
|||
|
|
StartCoroutine(LoadAssetBundle_Scene(abPath, sceneName, scene2_2Loaded));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
GameObject objReturn;
|
|||
|
|
void scene2_2Loaded()
|
|||
|
|
{
|
|||
|
|
objXMZJ_Scene2.SetActive(false);
|
|||
|
|
objBtnReturn.SetActive(true);
|
|||
|
|
|
|||
|
|
objReturn = GameObject.Find("BtnXMZJReturn");
|
|||
|
|
if (objReturn != null)
|
|||
|
|
{
|
|||
|
|
objReturn.SetActive(false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SetCameraPosition();
|
|||
|
|
|
|||
|
|
loading = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Return()
|
|||
|
|
{
|
|||
|
|
objXMZJ_Scene2.SetActive(true);
|
|||
|
|
objBtnReturn.SetActive(false);
|
|||
|
|
if (currentSceneName != null)
|
|||
|
|
{
|
|||
|
|
currentSceneBundle.Unload(true);
|
|||
|
|
SceneManager.UnloadSceneAsync(currentSceneName);
|
|||
|
|
}
|
|||
|
|
if (objReturn != null)
|
|||
|
|
{
|
|||
|
|
objReturn.SetActive(true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SetCameraPosition();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public Slider sliderProgress;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
void ShowSlider()
|
|||
|
|
{
|
|||
|
|
if (sliderProgress.value != 1)
|
|||
|
|
{
|
|||
|
|
sliderProgress.gameObject.SetActive(true);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
AssetBundle oldSceneBundle;
|
|||
|
|
AssetBundle currentSceneBundle;
|
|||
|
|
string oldSceneName;
|
|||
|
|
string currentSceneName;
|
|||
|
|
public IEnumerator LoadAssetBundle_Scene(string abPath, string sceneName,
|
|||
|
|
UnityAction BundleLoaded = null, LoadSceneMode mode = LoadSceneMode.Additive)
|
|||
|
|
{
|
|||
|
|
sliderProgress.value = 0;
|
|||
|
|
ShowSlider();
|
|||
|
|
|
|||
|
|
// Caching.ClearCache();
|
|||
|
|
|
|||
|
|
UnityWebRequest download = UnityWebRequestAssetBundle.GetAssetBundle(abPath);
|
|||
|
|
download.SendWebRequest();
|
|||
|
|
while (!download.isDone)
|
|||
|
|
{
|
|||
|
|
sliderProgress.value = download.downloadProgress;
|
|||
|
|
yield return null;
|
|||
|
|
}
|
|||
|
|
yield return download;
|
|||
|
|
|
|||
|
|
oldSceneBundle = currentSceneBundle;
|
|||
|
|
currentSceneBundle = DownloadHandlerAssetBundle.GetContent(download);
|
|||
|
|
|
|||
|
|
// <20>첽<EFBFBD><ECB2BD><EFBFBD>س<EFBFBD><D8B3><EFBFBD>
|
|||
|
|
var sceneAsync = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
|
|||
|
|
currentSceneName = sceneName;
|
|||
|
|
while (!sceneAsync.isDone)
|
|||
|
|
{
|
|||
|
|
yield return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
sliderProgress.value = 1;
|
|||
|
|
sliderProgress.gameObject.SetActive(false);
|
|||
|
|
|
|||
|
|
if (BundleLoaded != null)
|
|||
|
|
{
|
|||
|
|
BundleLoaded();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
oldSceneName = sceneName;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㼣<EFBFBD><E3BCA3><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>Ĭ<EFBFBD><C4AC>λ<EFBFBD><CEBB>
|
|||
|
|
/// </summary>
|
|||
|
|
void SetCameraPosition()
|
|||
|
|
{
|
|||
|
|
GameObject objSP = GameObject.Find("StartPosition2");
|
|||
|
|
if (objSP != null)
|
|||
|
|
{
|
|||
|
|
Camera cam = Camera.main;
|
|||
|
|
cam.gameObject.SetActive(false);
|
|||
|
|
cam.transform.position = objSP.transform.position;
|
|||
|
|
cam.transform.rotation = objSP.transform.rotation;
|
|||
|
|
cam.gameObject.SetActive(true);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|