111
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
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;
|
||||
|
||||
public class GameStart : MonoBehaviour
|
||||
@@ -9,15 +15,15 @@ public class GameStart : MonoBehaviour
|
||||
{
|
||||
Debug.Log("GameStart");
|
||||
GamePreload.Inst.Test("call by GameStart");
|
||||
await LoadSimpleR3Test();
|
||||
_=FrameSplittingTest(1);
|
||||
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test1", MainUICanvas.Inst.Medium);
|
||||
}
|
||||
async UniTask LoadSimpleR3Test()
|
||||
async UniTask FrameSplittingTest(int delayFrame)
|
||||
{
|
||||
UIManager.Inst.ShowUI<SimpleR3Test>("test1", MainUICanvas.Inst.Medium);
|
||||
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test2", MainUICanvas.Inst.Medium);
|
||||
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test2");
|
||||
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test3");
|
||||
await UIManager.Inst.TestShowUIAsync("FullTest", "test4", MainUICanvas.Inst.Medium,true);
|
||||
UIManager.Inst.TestShowUI("FullTest","test5", MainUICanvas.Inst.Medium);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
Debug.Log(i);
|
||||
await UniTask.DelayFrame(delayFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ public class SimpleR3Test : UIBase
|
||||
|
||||
public override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
value.BindToScrollbar(scrollbar).AddTo(this);
|
||||
value.BindToInputField(inputField).AddTo(this);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,18 @@ using UnityEngine;
|
||||
|
||||
public class UIBase : MonoBehaviour
|
||||
{
|
||||
public RectTransform rectTransform;
|
||||
public UIBase parent;
|
||||
public virtual void OnCreate()
|
||||
public RectTransform rectTransform
|
||||
{
|
||||
rectTransform = GetComponent<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() { }
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ using YooAsset;
|
||||
|
||||
public class UIManager : Singleton<UIManager>
|
||||
{
|
||||
public Dictionary<string, UIBase> openedUIs = new Dictionary<string, UIBase>();
|
||||
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
|
||||
@@ -59,18 +60,36 @@ public class UIManager : Singleton<UIManager>
|
||||
}
|
||||
GameObject LoadUI(string uiType)
|
||||
{
|
||||
AssetHandle uiHandle = YooAssets.LoadAssetSync<GameObject>(uiType);
|
||||
return (GameObject)uiHandle.AssetObject;
|
||||
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;
|
||||
}
|
||||
}
|
||||
async UniTask<GameObject> LoadUIAsync(string uiType)
|
||||
{
|
||||
AssetHandle uiHandle = YooAssets.LoadAssetAsync<GameObject>(uiType);
|
||||
await uiHandle.ToUniTask();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#region 用于测试没挂载UIBase的
|
||||
public Dictionary<string, GameObject> testOpenedUIs = new Dictionary<string, GameObject>();
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace R3
|
||||
{
|
||||
return source.Subscribe(scrollbar, static (x, s) => s.value = x);
|
||||
}
|
||||
public static IDisposable SubscribeToText(this ReactiveProperty<float> source, InputField inputField)
|
||||
public static IDisposable SubscribeToInputField(this ReactiveProperty<float> source, InputField inputField)
|
||||
{
|
||||
return source.Subscribe(inputField, static (x, t) => t.text = x.ToString());
|
||||
}
|
||||
@@ -33,7 +33,7 @@ namespace R3
|
||||
var disposable = new CompositeDisposable();
|
||||
|
||||
// 值 → InputField
|
||||
source.SubscribeToText(inputField).AddTo(disposable);
|
||||
source.SubscribeToInputField(inputField).AddTo(disposable);
|
||||
|
||||
// InputField → 值
|
||||
inputField.OnValueChangedAsObservable().Subscribe(_value =>
|
||||
|
||||
Reference in New Issue
Block a user