111
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Threading;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
public class GameStart : MonoBehaviour
|
public class GameStart : MonoBehaviour
|
||||||
@@ -9,15 +15,15 @@ public class GameStart : MonoBehaviour
|
|||||||
{
|
{
|
||||||
Debug.Log("GameStart");
|
Debug.Log("GameStart");
|
||||||
GamePreload.Inst.Test("call by 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);
|
for (int i = 0; i < 100; i++)
|
||||||
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test2", MainUICanvas.Inst.Medium);
|
{
|
||||||
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test2");
|
Debug.Log(i);
|
||||||
await UIManager.Inst.ShowUIAsync<SimpleR3Test>("test3");
|
await UniTask.DelayFrame(delayFrame);
|
||||||
await UIManager.Inst.TestShowUIAsync("FullTest", "test4", MainUICanvas.Inst.Medium,true);
|
}
|
||||||
UIManager.Inst.TestShowUI("FullTest","test5", MainUICanvas.Inst.Medium);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,6 @@ public class SimpleR3Test : UIBase
|
|||||||
|
|
||||||
public override void OnCreate()
|
public override void OnCreate()
|
||||||
{
|
{
|
||||||
base.OnCreate();
|
|
||||||
value.BindToScrollbar(scrollbar).AddTo(this);
|
value.BindToScrollbar(scrollbar).AddTo(this);
|
||||||
value.BindToInputField(inputField).AddTo(this);
|
value.BindToInputField(inputField).AddTo(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,18 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class UIBase : MonoBehaviour
|
public class UIBase : MonoBehaviour
|
||||||
{
|
{
|
||||||
public RectTransform rectTransform;
|
public RectTransform rectTransform
|
||||||
public UIBase parent;
|
|
||||||
public virtual void OnCreate()
|
|
||||||
{
|
{
|
||||||
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 OnShow() { }
|
||||||
public virtual void OnHide() { }
|
public virtual void OnHide() { }
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ using YooAsset;
|
|||||||
|
|
||||||
public class UIManager : Singleton<UIManager>
|
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>();
|
Stack<UIBase> uiStack = new Stack<UIBase>();
|
||||||
|
|
||||||
public T ShowUI<T>(string uiName, RectTransform parent = null, bool isFull = false) where T : UIBase
|
public T ShowUI<T>(string uiName, RectTransform parent = null, bool isFull = false) where T : UIBase
|
||||||
@@ -58,19 +59,37 @@ public class UIManager : Singleton<UIManager>
|
|||||||
return ui;
|
return ui;
|
||||||
}
|
}
|
||||||
GameObject LoadUI(string uiType)
|
GameObject LoadUI(string uiType)
|
||||||
|
{
|
||||||
|
if (!assetHandles.ContainsKey(uiType))
|
||||||
{
|
{
|
||||||
AssetHandle uiHandle = YooAssets.LoadAssetSync<GameObject>(uiType);
|
AssetHandle uiHandle = YooAssets.LoadAssetSync<GameObject>(uiType);
|
||||||
|
assetHandles.Add(uiType, uiHandle);
|
||||||
return (GameObject)uiHandle.AssetObject;
|
return (GameObject)uiHandle.AssetObject;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AssetHandle uiHandle = assetHandles[uiType];
|
||||||
|
return (GameObject)uiHandle.AssetObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
async UniTask<GameObject> LoadUIAsync(string uiType)
|
async UniTask<GameObject> LoadUIAsync(string uiType)
|
||||||
|
{
|
||||||
|
if (!assetHandles.ContainsKey(uiType))
|
||||||
{
|
{
|
||||||
AssetHandle uiHandle = YooAssets.LoadAssetAsync<GameObject>(uiType);
|
AssetHandle uiHandle = YooAssets.LoadAssetAsync<GameObject>(uiType);
|
||||||
await uiHandle.ToUniTask();
|
await uiHandle.ToUniTask();
|
||||||
|
assetHandles.Add(uiType, uiHandle);
|
||||||
return (GameObject)uiHandle.AssetObject;
|
return (GameObject)uiHandle.AssetObject;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AssetHandle uiHandle = assetHandles[uiType];
|
||||||
|
return (GameObject)uiHandle.AssetObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region 用于测试没挂载UIBase的
|
#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>();
|
Stack<GameObject> testUIStack = new Stack<GameObject>();
|
||||||
public GameObject TestShowUI(string path, string uiName, RectTransform parent = null, bool isFull = false)
|
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);
|
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());
|
return source.Subscribe(inputField, static (x, t) => t.text = x.ToString());
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ namespace R3
|
|||||||
var disposable = new CompositeDisposable();
|
var disposable = new CompositeDisposable();
|
||||||
|
|
||||||
// 值 → InputField
|
// 值 → InputField
|
||||||
source.SubscribeToText(inputField).AddTo(disposable);
|
source.SubscribeToInputField(inputField).AddTo(disposable);
|
||||||
|
|
||||||
// InputField → 值
|
// InputField → 值
|
||||||
inputField.OnValueChangedAsObservable().Subscribe(_value =>
|
inputField.OnValueChangedAsObservable().Subscribe(_value =>
|
||||||
|
|||||||
Reference in New Issue
Block a user