This commit is contained in:
2025-10-31 15:20:38 +08:00
parent 254e1926cf
commit 5ad8b2b7e1
6502 changed files with 581819 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
public class AudioLoader
{
public static IEnumerator LoadAudio(string auFullName, AudioLoadedEventHandler handler, AudioSource asHandler, AudioType auType = AudioType.MPEG)
{
// Debug.Log(auFullName);
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(auFullName, auType))
{
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.Success)
{
AudioClip auClip = DownloadHandlerAudioClip.GetContent(www);
auClip.name = Path.GetFileNameWithoutExtension(auFullName);
if (handler != null)
{
handler(auClip, asHandler);
}
}
else
{
Debug.Log(string.Format("Error loading remote audio<69><6F>{0}<7D><>:{1} ", auFullName, www.error));
}
}
}
}
/// <summary>
/// <20><>Ƶ<EFBFBD><C6B5><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD>¼<EFBFBD>ί<EFBFBD><CEAF>
/// </summary>
/// <param name="ac"><3E><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD></param>
public delegate void AudioLoadedEventHandler(AudioClip auClip, AudioSource asHandler);

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3d75027cb9e3234e9a7a01a4d44e403
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,139 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
/// <summary>
/// <20><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <typeparam name="T"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></typeparam>
public class DataLoader<T>
{
/// <summary>
/// <20><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD><EFBFBD>б<EFBFBD>
/// </summary>
public static List<T> DataList;
public static Dictionary<string, T> DataDics;
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="dataFileName"><3E><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD></param>
/// <param name="DataLoaded"><3E><><EFBFBD>غ<EFBFBD><D8BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
public static IEnumerator LoadDataDictionary(string dataFileName, UnityAction DataLoaded = null)
{
string filename = CommonData.DataFullPath + dataFileName;
// Debug.Log(filename);
UnityWebRequest www = UnityWebRequest.Get(filename);
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.ConnectionError)
{
Debug.Log(www.error);
}
if (www.isDone)
{
string data = www.downloadHandler.text;
if (!string.IsNullOrEmpty(data))
{
if (DataDics != null)
{
DataDics.Clear();
}
//Debug.Log(filename + ":" + data);
DataDics = JsonTools.DicFromJson<string,T>(data);
}
if (DataLoaded != null)
{
DataLoaded();
}
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="dataFileName"><3E><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD></param>
/// <param name="DataLoaded"><3E><><EFBFBD>غ<EFBFBD><D8BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
public static IEnumerator LoadDataList(string dataFileName, UnityAction DataLoaded = null)
{
string filename = CommonData.DataFullPath + dataFileName;
// Debug.Log(filename);
UnityWebRequest www = UnityWebRequest.Get(filename);
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.ConnectionError)
{
Debug.Log(www.error);
}
if (www.isDone)
{
string data = www.downloadHandler.text;
if (!string.IsNullOrEmpty(data))
{
if (DataList != null)
{
DataList.Clear();
}
//Debug.Log(filename + ":" + data);
DataList = JsonTools.ListFromJson<T>(data);
//Dictionary<string, T> dt = new Dictionary<string, T>();
//foreach (var item in DataList)
//{
// if (item is Data)
// {
// dt.Add((item as Data).ObjectID, item);
// }
//}
// Debug.Log(JsonTools.DicToJson(dt));
if (DataLoaded != null)
{
DataLoaded();
}
}
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="dataFileName"><3E><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD></param>
/// <param name="DataLoaded"><3E><><EFBFBD>غ<EFBFBD><D8BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
public static IEnumerator ListToDic(string dataFileName)
{
string filename = CommonData.DataFullPath + dataFileName;
// Debug.Log(filename);
UnityWebRequest www = UnityWebRequest.Get(filename);
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.ConnectionError)
{
Debug.Log(www.error);
}
if (www.isDone)
{
string data = www.downloadHandler.text;
if (!string.IsNullOrEmpty(data))
{
List<T> DataList = JsonTools.ListFromJson<T>(data);
Dictionary<string, T> dt = new Dictionary<string, T>();
foreach (var item in DataList)
{
if (item is Data)
{
dt.Add((item as Data).ObjectID, item);
}
}
Debug.Log(JsonTools.DicToJson(dt));
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 92ae39733c5a60246a8dbf2cb584f78d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.Events;
public class GameLoaderX : MonoBehaviour
{
public static GameLoaderX Instance;
private void Awake()
{
Instance = this;
}
#region Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD>չʾ<EFBFBD><EFBFBD>
public Transform tranMainScene;
private void Start()
{
Invoke("LoadSpots", 0.5f);
}
void LoadSpots()
{
LoadGame("Spots", "Spots", OnBundleLoaded);
LoadGame("TipPoints", "TipPoints", OnBundleLoaded);
}
void OnBundleLoaded()
{
BundleLoader.CurrentBundleObject.transform.parent = tranMainScene;
}
#endregion
public void LoadGame(string gameName, string bundleName=null, UnityAction BundleLoaded = null)
{
if(bundleName == null)
{
bundleName = gameName;
}
BundleLoader.Instance.LoadBundle( CommonData.DataServer + "/Bundles/" + bundleName + ".assetbundle", gameName, BundleLoaded);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cac8650e17a089f4992dc1bc698b204b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,218 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using DG.Tweening;
using static UnityEngine.Rendering.DebugUI;
/// <summary>
/// ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public class ImageLoader<T> : MonoBehaviour
{
public static Dictionary<string, Texture2D> dicTextures;
static List<string> removeKeys;
static Image progress;
static ImageLoader()
{
dicTextures = new Dictionary<string, Texture2D>();
removeKeys = new List<string>();
if(progress==null) progress = GameObject.Find("progress").GetComponent<Image>();
}
public static void RemoveTexture()
{
if (removeKeys.Count > 0)
{
if (dicTextures.ContainsKey(removeKeys[0]))
{
Destroy(dicTextures[removeKeys[0]]);
dicTextures.Remove(removeKeys[0]);
Resources.UnloadUnusedAssets();
}
Debug.Log("Removed:" + removeKeys[0]);
removeKeys.RemoveAt(0);
}
}
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
///// <summary>
///// <20><><EFBFBD>ⲿָ<E2B2BF><D6B8><EFBFBD>ļ<EFBFBD><C4BC>м<EFBFBD><D0BC><EFBFBD>ͼƬ
///// </summary>
///// <param name="imgFullName"><3E>ļ<EFBFBD>·<EFBFBD><C2B7></param>
///// <returns></returns>
//public static Texture2D LoadTextureByIO(string imgFullName)
//{
// FileStream fs = new FileStream(imgFullName, FileMode.Open, FileAccess.Read);
// fs.Seek(0, SeekOrigin.Begin);//<2F>α<EFBFBD><CEB1>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD>
// byte[] bytes = new byte[fs.Length];//<2F><><EFBFBD><EFBFBD><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B4A2>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ͼƬ<CDBC>ֽ<EFBFBD>
// try
// {
// fs.Read(bytes, 0, bytes.Length);//<2F><>ʼ<EFBFBD><CABC>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>trycatch<63><68><EFBFBD><EFBFBD><E4A3AC>ֹ<EFBFBD><D6B9>ȡʧ<C8A1>ܱ<EFBFBD><DCB1><EFBFBD>
// }
// catch (System.Exception e)
// {
// Debug.Log(e);
// }
// fs.Close();//<2F>мǹر<C7B9>
// int width = 2048;//ͼƬ<CDBC>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>
// int height = 2048;//ͼƬ<CDBC>ĸߣ<C4B8><DFA3><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E2BBB0>pico<63><6F><EFBFBD>صĿ<D8B5><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>4k<34><6B>4k<34><6B>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><ECB3A3><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>pico<63><6F>ʱ<EFBFBD><CAB1>ӦΪ<D3A6><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>6000*3600<30><30><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD><C2B3><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD>ˡ<EFBFBD><CBA1><EFBFBD><EFBFBD><EFBFBD>
// Texture2D texture = new Texture2D(width, height);
// if (texture.LoadImage(bytes))
// {
// //print("ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ");
// return texture;
// }
// else
// {
// //print("ͼƬ<CDBC><C6AC>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>");
// return null;
// }
//}
#endregion
/// <summary>
/// Э<>̼<EFBFBD><CCBC><EFBFBD>ͼ<EFBFBD><CDBC>
/// </summary>
/// <param name="imgFullName">ͼ<><CDBC><EFBFBD><EFBFBD></param>
/// <param name="mat"><3E><><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD></param>
public static IEnumerator LoadImage(string imgFullName, T mat, ImageLoadedEventHandler<T> ImageLoaded = null)
{
// Debug.Log(imgFullName);
//progress.gameObject.SetActive(true);
DOTween.KillAll();
progress.fillAmount = 0;
Texture2D tex = null;
if (dicTextures.ContainsKey(imgFullName))
{
tex = dicTextures[imgFullName];
}
else
{
UnityWebRequest www = UnityWebRequestTexture.GetTexture(imgFullName);
yield return www.SendWebRequest();
// Debug.Log($"<22><><EFBFBD><EFBFBD>{imgFullName}<7D><><EFBFBD>ȣ<EFBFBD>{www.downloadProgress}");
//while (!www.isDone)
//{
// yield return null;
// //GameObject.Find("progress").GetComponent<LoadProgress>().loadWebRequest = www;
// DOTween.To(() => progress.fillAmount, x => progress.fillAmount = x, www.downloadProgress, Time.deltaTime).OnComplete(() =>
// {
// if (progress.fillAmount >= 0.99)
// {
// DOTween.KillAll();
// progress.fillAmount = 0;
// }
// });
// //Tweener tweener = DOTween.To(() => progress.fillAmount, x=> progress.fillAmount, www.downloadProgress,Time.deltaTime);
// //progress.fillAmount = www.downloadProgress;
// //progress.fillAmount = Mathf.Lerp(progress.fillAmount, www.downloadProgress,Time.deltaTime);
// Debug.Log(www.downloadProgress);
//}
//DOTween.KillAll(); progress.fillAmount = 0;
//DOTween.To(() => progress.fillAmount, x => progress.fillAmount = x, 0, 0);
if (www.result == UnityWebRequest.Result.ConnectionError)
{
Debug.Log(www.error);
}
else
{
//progress.gameObject.SetActive(false);
try
{
tex = ((DownloadHandlerTexture)www.downloadHandler).texture;
if (!dicTextures.ContainsKey(imgFullName))
{
dicTextures.Add(imgFullName, tex);
}
}
catch
{
Debug.Log("ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>" + imgFullName);
}
}
www.Dispose();
}
if (ImageLoaded == null)
{
ImageLoaded = DefaultImageLoaded;
}
ImageLoaded(tex, mat);
}
public static void DefaultImageLoaded(Texture2D tex, T mat)
{
if (mat != null)
{
if (mat is Material)
{
Material matTmp = mat as Material;
// <20><><EFBFBD>²<EFBFBD><C2B2><EFBFBD>
matTmp.mainTexture = tex;
if (matTmp.IsKeywordEnabled("_EMISSION"))
{
matTmp.SetTexture("_EmissionMap", tex);
}
}
else if (mat is RawImage)
{
RawImage matTmp = mat as RawImage;
matTmp.texture = tex;
}
else if (mat is Image)
{
Image matTmp = mat as Image;
matTmp.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
}
// ClearImage();
}
}
public static void RemoveImage(string imageName)
{
// removeKeys.Add(imageName);
// Debug.Log("Remove:" + imageName);
if (dicTextures.ContainsKey(imageName))
{
Destroy(dicTextures[imageName]);
dicTextures.Remove(imageName);
}
// Resources.UnloadUnusedAssets();
}
public static void ClearImage()
{
foreach (string key in dicTextures.Keys)
{
Destroy(dicTextures[key]);
}
dicTextures.Clear();
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>Э<EFBFBD><D0AD>
IEnumerator ToDestoryThis(Texture2D thisSprite)
{
yield return new WaitForSeconds(0.1f);
//Destroy(thisSprite);
Resources.UnloadUnusedAssets();//ж<><D0B6>δռ<CEB4>õ<EFBFBD>asset<65><74>Դ
System.GC.Collect();//<2F><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
}
}
/// <summary>
/// ͼƬ<CDBC><C6AC><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD>¼<EFBFBD>ί<EFBFBD><CEAF>
/// </summary>
/// <param name="tex">ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD></param>
public delegate void ImageLoadedEventHandler<T>(Texture2D tex, T mat);

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 00e98a0c612490e4fb0d38c4a1d00dc6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class JsonLoader
{
public static IEnumerator LoadJSON(string jsonURL, OnLoadCompleted onLoadCompleted)
{
UnityWebRequest www = UnityWebRequest.Get(jsonURL);
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.ConnectionError)
{
Debug.LogError(www.error);
}
else
{
onLoadCompleted?.Invoke(www.downloadHandler.text);
}
}
}
public delegate void OnLoadCompleted(string jsonString);

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5e9e6a79a70ed140b597019362bbe7a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,106 @@
/************************
* Json<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *
************************/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
#region
/// <summary>
/// <20><>װ<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>л<EFBFBD><D0BB>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
[Serializable]
public class Serialization<T>
{
[SerializeField]
List<T> target;
public List<T> ToList() { return target; }
public Serialization(List<T> target)
{
this.target = target;
}
}
/// <summary>
/// <20><>װ<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>л<EFBFBD><D0BB>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
[Serializable]
public class Serialization<TKey, TValue> : ISerializationCallbackReceiver
{
[SerializeField]
List<TKey> keys;
[SerializeField]
List<TValue> values;
Dictionary<TKey, TValue> target;
public Dictionary<TKey, TValue> ToDictionary() { return target; }
public Serialization(Dictionary<TKey, TValue> target)
{
this.target = target;
}
public void OnBeforeSerialize()
{
keys = new List<TKey>(target.Keys);
values = new List<TValue>(target.Values);
}
public void OnAfterDeserialize()
{
var count = Math.Min(keys.Count, values.Count);
target = new Dictionary<TKey, TValue>(count);
for (var i = 0; i < count; ++i)
{
target.Add(keys[i], values[i]);
}
}
}
#endregion
/// <summary>
/// JSON<4F><4E><EFBFBD>ݹ<EFBFBD><DDB9><EFBFBD>
/// </summary>
public class JsonTools
{
/// <summary>
/// <20>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>תJSON<4F>ַ<EFBFBD><D6B7><EFBFBD>
/// </summary>
public static string ListToJson<T>(List<T> l)
{
return JsonUtility.ToJson(new Serialization<T>(l));
}
/// <summary>
/// JSON<4F>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public static List<T> ListFromJson<T>(string str)
{
return JsonUtility.FromJson<Serialization<T>>(str).ToList();
}
/// <summary>
/// <20>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>תJSON<4F>ַ<EFBFBD><D6B7><EFBFBD>
/// </summary>
public static string DicToJson<TKey, TValue>(Dictionary<TKey, TValue> dic)
{
return JsonUtility.ToJson(new Serialization<TKey, TValue>(dic));
}
/// <summary>
/// JSON<4F>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public static Dictionary<TKey, TValue> DicFromJson<TKey, TValue>(string str)
{
return JsonUtility.FromJson<Serialization<TKey, TValue>>(str).ToDictionary();
}
/// <summary>
/// JSON<4F>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
/// </summary>
public static T ObjectFromJson<T>(string str)
{
return JsonUtility.FromJson<T>(str);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2edf86f4874ddea4c8cd5bda08d152fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainScene : MonoBehaviour
{
public bool isWB;
bool isEnter;
// Update is called once per frame
void OnTriggerEnter(Collider other)
{
if (other.name.StartsWith("SceneCollider"))
{
BaseController.CanControl = false;
if (isWB)
{
CommonData.MainCamera.GetComponent<NavController>().StopNav();
isEnter = true;
}
BtnController btnCtrl = FindObjectOfType<BtnController>();
if (btnCtrl != null)
{
btnCtrl.OnBtnExLoaderClick();
}
}
}
void Update()
{
if (isEnter)
{
CommonData.MainCamera.transform.localPosition =
Vector3.Lerp(CommonData.MainCamera.transform.localPosition, new Vector3(-111, -8, -111),Time.deltaTime);
CommonData.MainCamera.transform.localRotation =
Quaternion.Euler(
Vector3.Lerp(CommonData.MainCamera.transform.localEulerAngles, new Vector3(0, 50, 0),Time.deltaTime)
);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a87ed46240146b4bbeb6ebbcdfca70d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,181 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class SceneLoader : MonoBehaviour
{
public static SceneLoader Instance;
public List<Vector3> ztPositions;
public List<Vector3> ztRotations;
/// <summary>
/// <20><>ǰչ<C7B0><D5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public static int currentIndex = -1;
public Slider slider; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int currentProgress; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
int targetProgress; // Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public bool isAllLoaded;
void Awake()
{
Instance = this;
}
private void Start()
{
currentProgress = 0;
targetProgress = 0;
GameObject obj = GameObject.Find("BtnExLoader" + currentIndex);
if (obj != null)
{
obj.GetComponent<Image>().color = Color.cyan;
}
}
AsyncOperation asyncOperation;
/// <summary>
/// <20><EFBFBD><ECB2BD><EFBFBD>س<EFBFBD><D8B3><EFBFBD>
/// </summary>
public IEnumerator LoadScene(int index)
{
if (index != currentIndex)
{
if (isAllLoaded)
{
SetCameraPosition(index);
AudioManager.Instance.PlayBg(index);
}
else
{
slider.gameObject.SetActive(true);
asyncOperation = SceneManager.LoadSceneAsync("ZT" + index);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> allowSceneActivation= falseʱ<65><CAB1><EFBFBD><EFBFBD><E1BFA8>0.89999<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ֵ
asyncOperation.allowSceneActivation = false;
// <20><><EFBFBD><EFBFBD><ECB2BD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>0.9f<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
while (asyncOperation.progress < 0.9f)
{
targetProgress = (int)(asyncOperation.progress * 100);
yield return LoadProgress();
}
// ѭ<><D1AD><EFBFBD>󣬵<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD>Ϊ90<39>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD>100<30><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
targetProgress = 100;
yield return LoadProgress();
currentIndex = index;
asyncOperation.allowSceneActivation = true;
asyncOperation.completed += AsyncOperation_completed;
slider.gameObject.SetActive(false);
currentProgress = 0;
targetProgress = 0;
}
}
}
private void AsyncOperation_completed(AsyncOperation obj)
{
AudioManager.Instance.PlayBg(currentIndex);
}
public void SetCameraPosition(int index)
{
NavMeshAgent agent = FindObjectOfType<NavMeshAgent>();
if (agent != null)
agent.enabled = false;
if (ztPositions.Count > index)
{
CommonData.MainCamera.transform.localPosition = ztPositions[index];
}
if (ztRotations.Count > index)
{
CommonData.MainCamera.transform.localRotation = Quaternion.Euler(ztRotations[index]);
}
if (agent != null)
agent.enabled = true;
}
ShowPoint currentSPInfo;
public void SetCameraPosition(ShowPoint info)
{
//if (currentIndex != info.ZT_Index)
//{
// currentIndex = info.ZT_Index;
// AudioManager.Instance.PlayBg(currentIndex);
//}
currentSPInfo = info;
LoadSceneData(info.ZT_Index, SetPostionOnLoaded );
}
void SetPostionOnLoaded()
{
SetCameraPosition(currentSPInfo.Position, currentSPInfo.Rotation);
}
public void SetCameraPosition(Vector3 pos, Vector3 rot)
{
NavMeshAgent agent = FindObjectOfType<NavMeshAgent>();
if (agent != null)
agent.enabled = false;
CommonData.MainCamera.transform.localPosition = pos;
CommonData.MainCamera.transform.localRotation = Quaternion.Euler(rot);
if (agent != null)
agent.enabled = true;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ε<EFBFBD><CEB5>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м򵥷<D0BC>װ
/// </summary>
/// <returns><3E><>һ֡</returns>
private IEnumerator LoadProgress()
{
yield return new WaitForEndOfFrame();
// <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD> < Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
while (currentProgress < targetProgress)
{
++currentProgress;
slider.value = (float)currentProgress / 100;
yield return new WaitForEndOfFrame();
}
}
public void LoadSceneData(int newIndex, UnityAction onDataLoaded)
{
if (newIndex != SceneLoader.currentIndex)
{
SceneLoader.currentIndex = newIndex;
LoadData(newIndex, onDataLoaded);
AudioManager.Instance.PlayBg(newIndex);
}
else
{
if (onDataLoaded != null)
{
onDataLoaded();
}
}
}
void LoadData(int index, UnityAction onDataLoaded)
{
StartCoroutine(DataLoader<Data>.LoadDataDictionary(string.Format("SpotsZT{0}.json", index), onDataLoaded));
StartCoroutine(DataLoader<Data>.LoadDataList(string.Format("Data_ZT{0}.json", index)));
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ccfc014eecc20474d8fce416d725e04a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: