162 lines
5.5 KiB
C#
162 lines
5.5 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using QFramework;
|
||
using TMPro;
|
||
using UnityEngine.SceneManagement;
|
||
using System;
|
||
using UnityEditor;
|
||
|
||
namespace QFramework.Example
|
||
{
|
||
public class UIModuleSelectData : UIPanelData
|
||
{
|
||
}
|
||
public partial class UIModuleSelect : UIPanel
|
||
{
|
||
ResLoader loader;
|
||
protected override void OnInit(IUIData uiData = null)
|
||
{
|
||
mData = uiData as UIModuleSelectData ?? new UIModuleSelectData();
|
||
backBtn.onClick.AddListener(() =>
|
||
{
|
||
Hide();
|
||
UIKit.OpenPanelAsync<UIModeSelect>().ToAction().StartGlobal();
|
||
});
|
||
setBtn.onClick.AddListener(() =>
|
||
{
|
||
UIKit.OpenPanelAsync<UISetting>(canvasLevel: UILevel.PopUI).ToAction().Start(this);
|
||
});
|
||
closeBtn.onClick.AddListener(() =>
|
||
{
|
||
Application.Quit();
|
||
});
|
||
loader = ResLoader.Allocate();
|
||
}
|
||
|
||
protected override void OnOpen(IUIData uiData = null)
|
||
{
|
||
Content.RemoveAllChildren();
|
||
int moduleCount = 0;
|
||
int lastIndex = 0;
|
||
for (int i = 0; i < Global.Instance.appData.Modules.Count; i++)
|
||
{
|
||
var item = Global.Instance.appData.Modules[i];
|
||
Global.AppType curType = Global.AppType.All;
|
||
Enum.TryParse(item.type, out curType);
|
||
|
||
if (curType == Global.appTpe || curType == Global.AppType.All)
|
||
{
|
||
moduleCount++;
|
||
int index = i;
|
||
GameObject obj = GameObject.Instantiate(BtnItem.gameObject, Content);
|
||
obj.gameObject.SetActive(true);
|
||
obj.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = item.ModuleName;
|
||
obj.GetComponent<Button>().onClick.AddListener(() =>
|
||
{
|
||
Global.Instance.curModule = Global.Instance.appData.Modules[index];
|
||
UIKit.OpenPanelAsync<UILoading>(canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() =>
|
||
{
|
||
SceneManager.LoadSceneAsync(Global.Instance.curModule.Scene, LoadSceneMode.Single);
|
||
SceneManager.sceneLoaded += OnLoadFinished;
|
||
});
|
||
});
|
||
if (string.IsNullOrEmpty(item.Icon)==false)
|
||
{
|
||
var icon = obj.transform.Find("Icon").GetComponent<Image>();
|
||
//obj.gameObject.GetComponent<Button>().transition= Selectable.Transition.SpriteSwap;
|
||
|
||
|
||
var localImageUrl = Global.imagePath + item.Icon;
|
||
loader.Add2Load(localImageUrl.ToNetImageResName(),
|
||
(bool success, IRes res) =>
|
||
{
|
||
if (success)
|
||
{
|
||
icon.sprite = Utility.GetSprite(res.Asset as Texture2D);
|
||
|
||
|
||
}
|
||
});
|
||
icon.gameObject.SetActive(true);
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ״̬
|
||
|
||
}
|
||
|
||
|
||
lastIndex = index;
|
||
}
|
||
}
|
||
|
||
if (moduleCount == 1)
|
||
{
|
||
Global.Instance.curModule = Global.Instance.appData.Modules[lastIndex];
|
||
UIKit.OpenPanelAsync<UILoading>(canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() =>
|
||
{
|
||
SceneManager.LoadSceneAsync(Global.Instance.curModule.Scene, LoadSceneMode.Single);
|
||
SceneManager.sceneLoaded += OnLoadFinished;
|
||
});
|
||
|
||
}
|
||
else
|
||
{
|
||
UIKit.OpenPanelAsync<UILoading>(canvasLevel: UILevel.PopUI).ToAction().StartGlobal();
|
||
loader.LoadAsync(() =>
|
||
{
|
||
TypeEventSystem.Global.Send<OnLoadingHide>(new OnLoadingHide());
|
||
});
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
private void OnLoadFinished(Scene arg0, LoadSceneMode arg1)
|
||
{
|
||
SceneManager.sceneLoaded -= OnLoadFinished;
|
||
|
||
if (Global.Instance.curModule.Devices != null && Global.Instance.curModule.Devices.Count > 0)
|
||
{
|
||
var dev = DeviceController.Instance;
|
||
}
|
||
if (Global.Instance.curModule.body3d != null)
|
||
{
|
||
var body3d = Body3DController.Instance;
|
||
}
|
||
if (Global.Instance.curModule.score != null)
|
||
{
|
||
ScoreController.Instance.Init();
|
||
}
|
||
if (Global.Instance.curModule.Operations != null && Global.Instance.curModule.Operations.Count > 0)
|
||
{
|
||
var op = OperationController.Instance;
|
||
}
|
||
if (Global.Instance.curModule.FSM.Count > 0)
|
||
{
|
||
var machin = StateMachineController.Instance;
|
||
}
|
||
UIKit.OpenPanelAsync<UIRightTop>().ToAction().StartGlobal(() =>
|
||
{
|
||
|
||
TypeEventSystem.Global.Send<OnModuleStart>();
|
||
TypeEventSystem.Global.Send<OnLoadingHide>();
|
||
Hide();
|
||
});
|
||
}
|
||
|
||
protected override void OnShow()
|
||
{
|
||
}
|
||
|
||
protected override void OnHide()
|
||
{
|
||
}
|
||
|
||
protected override void OnClose()
|
||
{
|
||
}
|
||
}
|
||
}
|