111
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c"
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:928f8a513cd12e84cb0d3c0a21a84e2f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -1,29 +1,27 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using YooAsset;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Tuan.GameFramework;
|
||||
using Tuan.GameScripts.Preload;
|
||||
|
||||
public class GameStart : MonoBehaviour
|
||||
namespace Tuan.GameScripts.Main
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
async void Start()
|
||||
public class GameStart : MonoBehaviour
|
||||
{
|
||||
Debug.Log("GameStart");
|
||||
GamePreload.Inst.Test("call by GameStart");
|
||||
_=FrameSplittingTest(1);
|
||||
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test1", MainUICanvas.Inst.Medium);
|
||||
}
|
||||
async UniTask FrameSplittingTest(int delayFrame)
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
async void Start()
|
||||
{
|
||||
Debug.Log(i);
|
||||
await UniTask.DelayFrame(delayFrame);
|
||||
Debug.Log("GameStart");
|
||||
GamePreload.Inst.Test("call by GameStart");
|
||||
// _ = FrameSplittingTest(1);
|
||||
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test1", MainUICanvas.Inst.Medium);
|
||||
}
|
||||
async UniTask FrameSplittingTest(int delayFrame)
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
Debug.Log(i);
|
||||
await UniTask.DelayFrame(delayFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,43 @@
|
||||
using static UnityEngine.InputSystem.InputAction;
|
||||
using UnityEngine;
|
||||
using R3;
|
||||
using UnityEngine.InputSystem;
|
||||
using YooAsset;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
public class ThirdCharacterController : MonoBehaviour
|
||||
namespace Tuan.GameScripts.Main
|
||||
{
|
||||
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;
|
||||
|
||||
Vector2 moveInput;
|
||||
|
||||
public void OnMove(CallbackContext context)
|
||||
public class ThirdCharacterController : MonoBehaviour
|
||||
{
|
||||
moveInput = context.ReadValue<Vector2>();
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
using R3;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SimpleR3Test : UIBase
|
||||
namespace Tuan.GameScripts.Main
|
||||
{
|
||||
public SerializableReactiveProperty<float> value = new(0);
|
||||
|
||||
public InputField inputField;
|
||||
public Scrollbar scrollbar;
|
||||
|
||||
public override void OnCreate()
|
||||
public class SimpleR3Test : UIBase
|
||||
{
|
||||
value.BindToScrollbar(scrollbar).AddTo(this);
|
||||
value.BindToInputField(inputField).AddTo(this);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class UIBase : MonoBehaviour
|
||||
namespace Tuan.GameScripts.Main
|
||||
{
|
||||
public RectTransform rectTransform
|
||||
public class UIBase : MonoBehaviour
|
||||
{
|
||||
get
|
||||
public RectTransform rectTransform
|
||||
{
|
||||
if (_rectTransform == null)
|
||||
_rectTransform = GetComponent<RectTransform>();
|
||||
return _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);
|
||||
rectTransform.localScale = Vector3.one;
|
||||
rectTransform.localPosition = Vector3.zero;
|
||||
rectTransform.localRotation = Quaternion.identity;
|
||||
if (isFull)
|
||||
SetFull();
|
||||
}
|
||||
}
|
||||
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);
|
||||
rectTransform.localScale = Vector3.one;
|
||||
rectTransform.localPosition = Vector3.zero;
|
||||
rectTransform.localRotation = Quaternion.identity;
|
||||
if (isFull)
|
||||
SetFull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,156 +1,160 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Tuan.GameFramework;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class UIManager : Singleton<UIManager>
|
||||
namespace Tuan.GameScripts.Main
|
||||
{
|
||||
Dictionary<string, UIBase> openedUIs = new Dictionary<string, UIBase>();
|
||||
Dictionary<string, AssetHandle> assetHandles = new Dictionary<string, AssetHandle>();
|
||||
Stack<UIBase> uiStack = new Stack<UIBase>();
|
||||
public class UIManager : Singleton<UIManager>
|
||||
{
|
||||
Dictionary<string, UIBase> openedUIs = new Dictionary<string, UIBase>();
|
||||
Dictionary<string, AssetHandle> assetHandles = new Dictionary<string, AssetHandle>();
|
||||
Stack<UIBase> uiStack = new Stack<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))
|
||||
public T ShowUI<T>(string uiName, RectTransform parent = null, bool isFull = false) where T : UIBase
|
||||
{
|
||||
GameObject uiPrefab = LoadUI(uiType);
|
||||
ui = CreateUI<T>(uiPrefab, uiName, parent, isFull);
|
||||
openedUIs[uiName] = ui;
|
||||
uiStack.Push(ui);
|
||||
T ui = null;
|
||||
string uiType = typeof(T).Name;
|
||||
if (!openedUIs.ContainsKey(uiName))
|
||||
{
|
||||
GameObject uiPrefab = LoadUI(uiType);
|
||||
ui = CreateUI<T>(uiPrefab, uiName, parent, isFull);
|
||||
openedUIs[uiName] = ui;
|
||||
uiStack.Push(ui);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui = openedUIs[uiName] as T;
|
||||
}
|
||||
Debug.Log($"ShowUI====>name:{uiName} type:{typeof(T).Name}");
|
||||
ui.OnShow();
|
||||
return ui;
|
||||
}
|
||||
else
|
||||
public async UniTask<T> ShowUIAsync<T>(string uiName, RectTransform parent = null, bool isFull = false) where T : UIBase
|
||||
{
|
||||
ui = openedUIs[uiName] as T;
|
||||
T ui = null;
|
||||
string uiType = typeof(T).Name;
|
||||
if (!openedUIs.ContainsKey(uiName))
|
||||
{
|
||||
GameObject uiPrefab = await LoadUIAsync(uiType);
|
||||
ui = CreateUI<T>(uiPrefab, uiName, parent, isFull);
|
||||
openedUIs[uiName] = ui;
|
||||
uiStack.Push(ui);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui = openedUIs[uiName] as T;
|
||||
}
|
||||
Debug.Log($"ShowUIAsync====>name:{uiName} type:{typeof(T).Name}");
|
||||
ui.OnShow();
|
||||
return ui;
|
||||
}
|
||||
Debug.Log($"ShowUI====>name:{uiName} type:{typeof(T).Name}");
|
||||
ui.OnShow();
|
||||
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))
|
||||
T CreateUI<T>(GameObject uiPrefab, string uiName, RectTransform parent = null, bool isFull = false) where T : UIBase
|
||||
{
|
||||
GameObject uiPrefab = await LoadUIAsync(uiType);
|
||||
ui = CreateUI<T>(uiPrefab, uiName, parent, isFull);
|
||||
openedUIs[uiName] = ui;
|
||||
uiStack.Push(ui);
|
||||
GameObject uiObj = GameObject.Instantiate(uiPrefab);
|
||||
uiObj.name = uiName;
|
||||
T ui = uiObj.GetComponent<T>();
|
||||
ui.OnCreate();
|
||||
if (parent) ui.SetParent(parent, isFull);
|
||||
Debug.Log($"CreateUI====>name:{uiName} type:{typeof(T).Name}");
|
||||
return ui;
|
||||
}
|
||||
else
|
||||
GameObject LoadUI(string uiType)
|
||||
{
|
||||
ui = openedUIs[uiName] as T;
|
||||
if (!assetHandles.ContainsKey(uiType))
|
||||
{
|
||||
AssetHandle uiHandle = YooAssets.LoadAssetSync<GameObject>(uiType);
|
||||
assetHandles.Add(uiType, uiHandle);
|
||||
return (GameObject)uiHandle.AssetObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetHandle uiHandle = assetHandles[uiType];
|
||||
return (GameObject)uiHandle.AssetObject;
|
||||
}
|
||||
}
|
||||
Debug.Log($"ShowUIAsync====>name:{uiName} type:{typeof(T).Name}");
|
||||
ui.OnShow();
|
||||
return 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($"CreateUI====>name:{uiName} type:{typeof(T).Name}");
|
||||
return ui;
|
||||
}
|
||||
GameObject LoadUI(string uiType)
|
||||
{
|
||||
if (!assetHandles.ContainsKey(uiType))
|
||||
async UniTask<GameObject> LoadUIAsync(string uiType)
|
||||
{
|
||||
AssetHandle uiHandle = YooAssets.LoadAssetSync<GameObject>(uiType);
|
||||
assetHandles.Add(uiType, uiHandle);
|
||||
return (GameObject)uiHandle.AssetObject;
|
||||
if (!assetHandles.ContainsKey(uiType))
|
||||
{
|
||||
AssetHandle uiHandle = YooAssets.LoadAssetAsync<GameObject>(uiType);
|
||||
await uiHandle.ToUniTask();
|
||||
assetHandles.Add(uiType, uiHandle);
|
||||
return (GameObject)uiHandle.AssetObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetHandle uiHandle = assetHandles[uiType];
|
||||
return (GameObject)uiHandle.AssetObject;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetHandle uiHandle = assetHandles[uiType];
|
||||
return (GameObject)uiHandle.AssetObject;
|
||||
}
|
||||
}
|
||||
async UniTask<GameObject> LoadUIAsync(string uiType)
|
||||
{
|
||||
if (!assetHandles.ContainsKey(uiType))
|
||||
{
|
||||
AssetHandle uiHandle = YooAssets.LoadAssetAsync<GameObject>(uiType);
|
||||
await uiHandle.ToUniTask();
|
||||
assetHandles.Add(uiType, uiHandle);
|
||||
return (GameObject)uiHandle.AssetObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetHandle uiHandle = assetHandles[uiType];
|
||||
return (GameObject)uiHandle.AssetObject;
|
||||
}
|
||||
}
|
||||
|
||||
#region 用于测试没挂载UIBase的
|
||||
Dictionary<string, GameObject> testOpenedUIs = new Dictionary<string, GameObject>();
|
||||
Stack<GameObject> testUIStack = new Stack<GameObject>();
|
||||
public GameObject TestShowUI(string path, string uiName, RectTransform parent = null, bool isFull = false)
|
||||
{
|
||||
GameObject ui = null;
|
||||
if (!testOpenedUIs.ContainsKey(uiName))
|
||||
#region 用于测试没挂载UIBase的
|
||||
Dictionary<string, GameObject> testOpenedUIs = new Dictionary<string, GameObject>();
|
||||
Stack<GameObject> testUIStack = new Stack<GameObject>();
|
||||
public GameObject TestShowUI(string path, string uiName, RectTransform parent = null, bool isFull = false)
|
||||
{
|
||||
GameObject uiPrefab = LoadUI(path);
|
||||
ui = TestCreateUI(uiPrefab, uiName, parent, isFull);
|
||||
testOpenedUIs[uiName] = ui;
|
||||
testUIStack.Push(ui);
|
||||
GameObject ui = null;
|
||||
if (!testOpenedUIs.ContainsKey(uiName))
|
||||
{
|
||||
GameObject uiPrefab = LoadUI(path);
|
||||
ui = TestCreateUI(uiPrefab, uiName, parent, isFull);
|
||||
testOpenedUIs[uiName] = ui;
|
||||
testUIStack.Push(ui);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui = testOpenedUIs[uiName];
|
||||
}
|
||||
Debug.Log($"TestShowUI====>name:{uiName}");
|
||||
return ui;
|
||||
}
|
||||
else
|
||||
public async UniTask<GameObject> TestShowUIAsync(string path, string uiName, RectTransform parent = null, bool isFull = false)
|
||||
{
|
||||
ui = testOpenedUIs[uiName];
|
||||
GameObject ui = null;
|
||||
if (!testOpenedUIs.ContainsKey(uiName))
|
||||
{
|
||||
GameObject uiPrefab = await LoadUIAsync(path);
|
||||
ui = TestCreateUI(uiPrefab, uiName, parent, isFull);
|
||||
testOpenedUIs[uiName] = ui;
|
||||
testUIStack.Push(ui);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui = testOpenedUIs[uiName];
|
||||
}
|
||||
Debug.Log($"TestShowUI====>name:{uiName}");
|
||||
return ui;
|
||||
}
|
||||
Debug.Log($"TestShowUI====>name:{uiName}");
|
||||
return ui;
|
||||
}
|
||||
public async UniTask< GameObject> TestShowUIAsync(string path, string uiName, RectTransform parent = null, bool isFull = false)
|
||||
{
|
||||
GameObject ui = null;
|
||||
if (!testOpenedUIs.ContainsKey(uiName))
|
||||
GameObject TestCreateUI(GameObject uiPrefab, string uiName, RectTransform parent = null, bool isFull = false)
|
||||
{
|
||||
GameObject uiPrefab = await LoadUIAsync(path);
|
||||
ui = TestCreateUI(uiPrefab, uiName, parent, isFull);
|
||||
testOpenedUIs[uiName] = ui;
|
||||
testUIStack.Push(ui);
|
||||
GameObject uiObj = GameObject.Instantiate(uiPrefab);
|
||||
uiObj.name = uiName;
|
||||
RectTransform ui = uiObj.GetComponent<RectTransform>();
|
||||
if (parent) TestSetParent(ui, parent, isFull);
|
||||
Debug.Log($"TestCreateUI====>name:{uiName}");
|
||||
return uiObj;
|
||||
}
|
||||
else
|
||||
void TestSetFull(RectTransform rectTransform)
|
||||
{
|
||||
ui = testOpenedUIs[uiName];
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.anchorMax = Vector2.one;
|
||||
rectTransform.offsetMin = Vector2.zero;
|
||||
rectTransform.offsetMax = Vector2.zero;
|
||||
rectTransform.sizeDelta = Vector2.zero;
|
||||
}
|
||||
Debug.Log($"TestShowUI====>name:{uiName}");
|
||||
return ui;
|
||||
}
|
||||
GameObject TestCreateUI(GameObject uiPrefab, string uiName, RectTransform parent = null, bool isFull = false)
|
||||
{
|
||||
GameObject uiObj = GameObject.Instantiate(uiPrefab);
|
||||
uiObj.name = uiName;
|
||||
RectTransform ui = uiObj.GetComponent<RectTransform>();
|
||||
if (parent) TestSetParent(ui, parent, isFull);
|
||||
Debug.Log($"TestCreateUI====>name:{uiName}");
|
||||
return uiObj;
|
||||
}
|
||||
void TestSetFull(RectTransform rectTransform)
|
||||
{
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.anchorMax = Vector2.one;
|
||||
rectTransform.offsetMin = Vector2.zero;
|
||||
rectTransform.offsetMax = Vector2.zero;
|
||||
rectTransform.sizeDelta = Vector2.zero;
|
||||
}
|
||||
|
||||
void TestSetParent(RectTransform ui, RectTransform parent, bool isFull = false)
|
||||
{
|
||||
ui.SetParent(parent);
|
||||
ui.localScale = Vector3.one;
|
||||
ui.localPosition = Vector3.zero;
|
||||
ui.localRotation = Quaternion.identity;
|
||||
if (isFull)
|
||||
TestSetFull(ui);
|
||||
void TestSetParent(RectTransform ui, RectTransform parent, bool isFull = false)
|
||||
{
|
||||
ui.SetParent(parent);
|
||||
ui.localScale = Vector3.one;
|
||||
ui.localPosition = Vector3.zero;
|
||||
ui.localRotation = Quaternion.identity;
|
||||
if (isFull)
|
||||
TestSetFull(ui);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace R3
|
||||
namespace Tuan.GameScripts.Main
|
||||
{
|
||||
public static class UnityUIBindings
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user