This commit is contained in:
2025-11-13 17:40:28 +08:00
parent 962ab49609
commit 10156da245
5503 changed files with 805282 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f1e874e4e7d44604da8990a1339cdd15
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,54 @@
using Cysharp.Threading.Tasks;
using System.Collections.Generic;
using UnityEngine;
using YooAsset;
using Tuan.GameFramework;
namespace Tuan.GameScripts.Main
{
public class AssetLoader :Singleton <AssetLoader>
{
Dictionary<string, AssetHandle> assetHandles = new Dictionary<string, AssetHandle>();
public async UniTask<T> LoadAsync<T>(string name, LoadingWindow loadingWindow = null) where T : UnityEngine.Object
{
AssetHandle handle = null;
if (!assetHandles.ContainsKey(name))
{
handle = YooAssets.LoadAssetAsync<T>(name);
await handle.ToUniTask(loadingWindow);
assetHandles.Add(name, handle);
Debug.Log($"AssetLoad:{name}");
}
else
{
handle = assetHandles[name];
Debug.Log($"AssetLoad:{name}(已缓存handle)");
}
if (loadingWindow != null)
UIManager.Inst.CloseUI(loadingWindow);
return handle.AssetObject as T;
}
public T Load<T>(string name) where T : UnityEngine.Object
{
AssetHandle handle = null;
if (!assetHandles.ContainsKey(name))
{
handle = YooAssets.LoadAssetSync<T>(name);
assetHandles.Add(name, handle);
Debug.Log($"AssetLoad:{name}");
}
else
{
handle = assetHandles[name];
Debug.Log($"AssetLoad:{name}(已缓存handle)");
}
return handle.AssetObject as T;
}
public AssetHandle GetHandle(string name)
{
if (assetHandles.ContainsKey(name))
return assetHandles[name];
return null;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 48a875b73eb969f4fa3a19584bba9262

View File

@@ -0,0 +1,23 @@
{
"name": "GameScripts.Main",
"rootNamespace": "",
"references": [
"GUID:921b262766d31374c8fd93ad67954b9c",
"GUID:63f032f8696ad5b4e99c26f7a9f89060",
"GUID:77221876cc6b8244180b96e320b1bcd4",
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:e34a5702dd353724aa315fb8011f08c3",
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:928f8a513cd12e84cb0d3c0a21a84e2f"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a5014882eef2429488110feb660bef0a
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using UnityEngine;
using Cysharp.Threading.Tasks;
using Tuan.GameFramework;
using Tuan.GameScripts.Preload;
using YooAsset;
namespace Tuan.GameScripts.Main
{
public class GameStart : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
async void Start()
{
Debug.Log("GameStart");
GamePreload.Inst.Test("call by GameStart");
_ = LoadSceneTest();
// _ = FrameSplittingTest(1);
SimpleR3Test ui = await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test1", MainUICanvas.Inst.Medium);
UIManager.Inst.CloseUI(ui);
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test2", MainUICanvas.Inst.Medium);
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test3", MainUICanvas.Inst.Medium);
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test1");
}
async UniTask FrameSplittingTest(int delayFrame)
{
for (int i = 0; i < 100; i++)
{
Debug.Log(i);
await UniTask.DelayFrame(delayFrame);
}
}
async UniTask LoadSceneTest()
{
PatchEvent.ClosePatchWindow();
LoadingWindow loadingWindow = await UIManager.Inst.ShowUIAsync<LoadingWindow>("LoadSceneTest",MainUICanvas.Inst.Medium);
await SceneLoader.Inst.LoadSceneAsync("Test", loadingWindow);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e78850d2b34a8e74da183b8235948929

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: faf2114b56c349e4284718b74f73f2ea
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
using static UnityEngine.InputSystem.InputAction;
using UnityEngine;
using UnityEngine.InputSystem;
using YooAsset;
using Cysharp.Threading.Tasks;
namespace Tuan.GameScripts.Main
{
public class ThirdCharacterController : MonoBehaviour
{
public CharacterController characterController;
public Animator animator;
public Transform forward;
public Transform model;
public float moveSpeed = 5f;
public float turnSpeed = 10f;
public float jumpSpeed = 8f;
public float gravity = 20f;
public float minCameraDistance = 2f;
public float maxCameraDistance = 10f;
public float cameraZoomSpeed = 0.1f;
InputActionAsset playerActions;
Vector2 moveInput;
async void Awake()
{
await LoadInputActonAsset();
}
async UniTask LoadInputActonAsset()
{
AssetHandle handle = YooAssets.LoadAssetAsync<InputActionAsset>("PlayerActions");
await handle.ToUniTask();
playerActions = handle.AssetObject as InputActionAsset;
}
public void OnMove(CallbackContext context)
{
moveInput = context.ReadValue<Vector2>();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2d7272fcdcd432041a59c95e74fb41f6

View File

@@ -0,0 +1,51 @@
using UnityEngine;
using System.Collections.Generic;
using YooAsset;
using Cysharp.Threading.Tasks;
using Tuan.GameFramework;
namespace Tuan.GameScripts.Main
{
public class SceneLoader : Singleton<SceneLoader>
{
Dictionary<string, SceneHandle> sceneHandles = new Dictionary<string, SceneHandle>();
public async UniTask LoadSceneAsync(string sceneName, LoadingWindow loadingWindow = null)
{
SceneHandle sceneHandle = null;
if (!sceneHandles.ContainsKey(sceneName))
{
sceneHandle = YooAssets.LoadSceneAsync("Test");
await sceneHandle.ToUniTask(loadingWindow);
sceneHandles[sceneName] = sceneHandle;
}
else
{
sceneHandle = sceneHandles[sceneName];
}
sceneHandle.ActivateScene();
if(loadingWindow != null)
UIManager.Inst.CloseUI(loadingWindow);
}
public void LoadScene(string sceneName)
{
SceneHandle sceneHandle = null;
if (!sceneHandles.ContainsKey(sceneName))
{
sceneHandle = YooAssets.LoadSceneSync("Test");
sceneHandles[sceneName] = sceneHandle;
}
else
{
sceneHandle = sceneHandles[sceneName];
}
sceneHandle.ActivateScene();
}
public SceneHandle GetHandle(string name)
{
if (sceneHandles.ContainsKey(name))
return sceneHandles[name];
return null;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ce14e279825befb4e8d30f8929445030

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 43d2406acc71f48448efde6aa488d064
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Tuan.GameScripts.Main
{
public class LoadingWindow : UIBase, IProgress<float>
{
public Slider slider;
public Text progressText;
public void Report(float value)
{
slider.value = value;
progressText.text = $"{value * 100:F0}%";
Debug.Log($"{gameObject.name};{value}");
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b0cfeb8d9ed2b7d45841727433c72b07

View File

@@ -0,0 +1,19 @@
using R3;
using UnityEngine.UI;
namespace Tuan.GameScripts.Main
{
public class SimpleR3Test : UIBase
{
public SerializableReactiveProperty<float> value = new(0);
public InputField inputField;
public Scrollbar scrollbar;
public override void OnCreate()
{
value.BindToScrollbar(scrollbar).AddTo(this);
value.BindToInputField(inputField).AddTo(this);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5ab3d77b09181e94e9d6303d5dd80174

View File

@@ -0,0 +1,41 @@
using UnityEngine;
namespace Tuan.GameScripts.Main
{
public class UIBase : MonoBehaviour
{
public RectTransform rectTransform
{
get
{
if (_rectTransform == null)
_rectTransform = GetComponent<RectTransform>();
return _rectTransform;
}
}
RectTransform _rectTransform;
public UIBase parent;
public virtual void OnCreate() { }
public virtual void OnShow() { }
public virtual void OnHide() { }
public void SetFull()
{
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
rectTransform.sizeDelta = Vector2.zero;
}
public void SetParent(RectTransform ui, bool isFull = false)
{
rectTransform.SetParent(ui,false);
//rectTransform.localScale = Vector3.one;
//rectTransform.localPosition = Vector3.zero;
//rectTransform.localRotation = Quaternion.identity;
if (isFull)
SetFull();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 11bbb38035ff49641be77ec96d27de0c

View File

@@ -0,0 +1,85 @@
using Cysharp.Threading.Tasks;
using System;
using System.Collections.Generic;
using Tuan.GameFramework;
using UnityEngine;
using YooAsset;
namespace Tuan.GameScripts.Main
{
public class UIManager : Singleton<UIManager>
{
Dictionary<string, UIBase> openedUIs = new Dictionary<string, UIBase>();
LinkedList<UIBase> uiLinkedList = new LinkedList<UIBase>();
public T ShowUI<T>(string uiName, RectTransform parent = null, bool isFull = false) where T : UIBase
{
T ui = null;
string uiType = typeof(T).Name;
if (!openedUIs.ContainsKey(uiName))
{
GameObject uiPrefab = AssetLoader.Inst.Load<GameObject>(uiType);
ui = CreateUI<T>(uiPrefab, uiName, parent, isFull);
openedUIs[uiName] = ui;
}
else
{
ui = openedUIs[uiName] as T;
uiLinkedList.Remove(ui);
}
Debug.Log($"UIManager.ShowUI====>name:{uiName} type:{typeof(T).Name}");
ui.gameObject.SetActive(true);
ui.OnShow();
uiLinkedList.AddLast(ui);
return ui;
}
public async UniTask<T> ShowUIAsync<T>(string uiName, RectTransform parent = null, bool isFull = false) where T : UIBase
{
T ui = null;
string uiType = typeof(T).Name;
if (!openedUIs.ContainsKey(uiName))
{
GameObject uiPrefab = await AssetLoader.Inst.LoadAsync<GameObject>(uiType);
ui = CreateUI<T>(uiPrefab, uiName, parent, isFull);
openedUIs[uiName] = ui;
}
else
{
ui = openedUIs[uiName] as T;
uiLinkedList.Remove(ui);
}
Debug.Log($"UIManager.ShowUIAsync====>name:{uiName} type:{typeof(T).Name}");
ui.gameObject.SetActive(true);
ui.OnShow();
uiLinkedList.AddLast(ui);
return ui;
}
public void CloseUI(string uiName)
{
if (!openedUIs.ContainsKey(uiName)) return;
var ui = openedUIs[uiName];
Debug.Log($"UIManager.CloseUI====>name:{uiName} type:{ui}");
ui.OnHide();
ui.gameObject.SetActive(false);
uiLinkedList.Remove(ui);
}
public void CloseUI(UIBase ui)
{
if (!openedUIs.ContainsKey(ui.gameObject.name)) return;
Debug.Log($"UIManager.CloseUI====>name:{ui.gameObject.name} type:{ui}");
ui.OnHide();
ui.gameObject.SetActive(false);
uiLinkedList.Remove(ui);
}
T CreateUI<T>(GameObject uiPrefab, string uiName, RectTransform parent = null, bool isFull = false) where T : UIBase
{
GameObject uiObj = GameObject.Instantiate(uiPrefab);
uiObj.name = uiName;
T ui = uiObj.GetComponent<T>();
ui.OnCreate();
if (parent) ui.SetParent(parent, isFull);
Debug.Log($"UIManager.CreateUI====>name:{uiName} type:{typeof(T).Name}");
return ui;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a59f1c308a49e0742878b0c58f906538

View File

@@ -0,0 +1,51 @@
using R3;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Tuan.GameScripts.Main
{
public static class UnityUIBindings
{
public static IDisposable SubscribeToScrollbar(this ReactiveProperty<float> source, Scrollbar scrollbar)
{
return source.Subscribe(scrollbar, static (x, s) => s.value = x);
}
public static IDisposable SubscribeToInputField(this ReactiveProperty<float> source, InputField inputField)
{
return source.Subscribe(inputField, static (x, t) => t.text = x.ToString());
}
public static IDisposable BindToScrollbar(this ReactiveProperty<float> source, Scrollbar scrollbar)
{
var disposable = new CompositeDisposable();
// 值 → Scrollbar
source.SubscribeToScrollbar(scrollbar).AddTo(disposable);
// Scrollbar → 值
scrollbar.OnValueChangedAsObservable().Subscribe(_value => { source.Value = _value; }).AddTo(disposable);
return disposable;
}
public static IDisposable BindToInputField(this ReactiveProperty<float> source, InputField inputField)
{
var disposable = new CompositeDisposable();
// 值 → InputField
source.SubscribeToInputField(inputField).AddTo(disposable);
// InputField → 值
inputField.OnValueChangedAsObservable().Subscribe(_value =>
{
float result;
if (float.TryParse(_value,out result))
source.Value = result;
}).AddTo(disposable);
return disposable;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f37692bbbf2a11c48b4cb9f3a32a4a77

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 06ae990509d25664bac3ce979dceadb4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using UnityEngine;
using Tuan.GameFramework;
namespace Tuan.GameScripts.Preload
{
public class GamePreload : Singleton<GamePreload>
{
public void Test(string msg)
{
Debug.Log($"GamePreload.Test:{msg}");
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f70a842d4d8919e41a34b7ad7012e9ff

View File

@@ -0,0 +1,16 @@
{
"name": "GameScripts.Preload",
"rootNamespace": "",
"references": [
"GUID:63f032f8696ad5b4e99c26f7a9f89060"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 921b262766d31374c8fd93ad67954b9c
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
using Tuan.GameFramework;
namespace Tuan.GameScripts.Preload
{
public class PatchWindow : MonoBehaviour
{
public Text statusText;
public Slider progressBar;
public Text downloadSizeText;
public VideoPlayer video;
private void Awake()
{
video.targetCamera = MainUICanvas.Inst.UICamera;
PatchEvent.OnStatusUpdate += OnStatusUpdate;
PatchEvent.OnProgressUpdate += OnProgressUpdate;
PatchEvent.OnDownloadSizeUpdate += OnDownloadSizeUpdate;
PatchEvent.OnClosePatchWindow += OnClosePatchWindow;
}
private void OnDestroy()
{
PatchEvent.OnStatusUpdate -= OnStatusUpdate;
PatchEvent.OnProgressUpdate -= OnProgressUpdate;
PatchEvent.OnDownloadSizeUpdate -= OnDownloadSizeUpdate;
}
private void OnStatusUpdate(string status)
{
if (statusText != null)
statusText.text = status;
}
private void OnProgressUpdate(float progress)
{
if (progressBar != null)
progressBar.value = progress;
}
private void OnDownloadSizeUpdate(string sizeText)
{
if (downloadSizeText != null)
downloadSizeText.text = sizeText;
}
private void OnClosePatchWindow()
{
gameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5a0d239551fa52c4d9907777f1f485bf