111 lines
3.9 KiB
C#
111 lines
3.9 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using QFramework;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using static OperationController;
|
||
|
||
namespace QFramework.Example
|
||
{
|
||
public class UIBackPackData : UIPanelData
|
||
{
|
||
public List<string> devices;
|
||
public bool random = false;
|
||
public float scrollSpeed = 25;
|
||
public string position;
|
||
}
|
||
public partial class UIBackPack : UIPanel
|
||
{
|
||
ResLoader mResLoader;
|
||
protected override void OnInit(IUIData uiData = null)
|
||
{
|
||
mData = uiData as UIBackPackData ?? new UIBackPackData();
|
||
mResLoader = ResLoader.Allocate();
|
||
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuit).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||
// please add init code here
|
||
}
|
||
|
||
protected override void OnOpen(IUIData uiData = null)
|
||
{
|
||
Content.RemoveAllChildren();
|
||
|
||
foreach (var device in mData.devices)
|
||
{
|
||
var item = DeviceController.Instance.GetDevice(device);
|
||
if (item == null)
|
||
{
|
||
Debug.LogError(device + ":ûÓÐÕÒµ½¶ÔÓ¦µÄDeviceÅäÖÃ");
|
||
return;
|
||
}
|
||
GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content);
|
||
obj.name = item.Name;
|
||
obj.transform.Find("Name").GetComponent<TextMeshProUGUI>().text = item.Name;
|
||
Image icon = obj.transform.Find("IconBg/Icon").GetComponent<Image>();
|
||
var localImageUrl = Global.deviceIconsPath + item.Icon;
|
||
GameObject right = icon.transform.Find("Right").gameObject;
|
||
GameObject wrong = icon.transform.Find("Wrong").gameObject;
|
||
GameObject Selected = icon.transform.Find("Selected").gameObject;
|
||
mResLoader.Add2Load(localImageUrl.ToNetImageResName(),
|
||
(bool success, IRes res) =>
|
||
{
|
||
if (success)
|
||
{
|
||
icon.sprite = Utility.GetSprite(res.Asset as Texture2D);
|
||
}
|
||
});
|
||
Button btn = obj.GetComponent<Button>();
|
||
btn.onClick.AddListener(() =>
|
||
{
|
||
|
||
});
|
||
}
|
||
mResLoader.LoadAsync();
|
||
Scroll.verticalNormalizedPosition = 1;
|
||
|
||
|
||
switch (mData.position)
|
||
{
|
||
case "left":
|
||
// ½«ÃªµãÉèΪ¸¸ÈÝÆ÷µÄÓÒ²àÖм䣨Middle-Right£©
|
||
bg.rectTransform.anchorMin = new Vector2(0, 0.5f); // ×óÏÂêµã£¨ÓҲࣩ
|
||
bg.rectTransform.anchorMax = new Vector2(0, 0.5f); // ÓÒÉÏêµã£¨ÓҲࣩ
|
||
|
||
// ½«Î»ÖÃÆ«ÒƹéÁ㣨Ïà¶ÔÓÚêµã£©
|
||
bg.rectTransform.anchoredPosition = Vector2.zero;
|
||
|
||
// ¿ÉÑ¡£ºÉèÖÃÖáÐĵãΪÓÒ²àÖе㣨ӰÏìËõ·Å/ÐýתÖÐÐÄ£©
|
||
bg.rectTransform.pivot = new Vector2(0, 0.5f);
|
||
break;
|
||
case "right":
|
||
default:
|
||
// ½«ÃªµãÉèΪ¸¸ÈÝÆ÷µÄÓÒ²àÖм䣨Middle-Right£©
|
||
bg.rectTransform.anchorMin = new Vector2(1, 0.5f); // ×óÏÂêµã£¨ÓҲࣩ
|
||
bg.rectTransform.anchorMax = new Vector2(1, 0.5f); // ÓÒÉÏêµã£¨ÓҲࣩ
|
||
|
||
// ½«Î»ÖÃÆ«ÒƹéÁ㣨Ïà¶ÔÓÚêµã£©
|
||
bg.rectTransform.anchoredPosition = Vector2.zero;
|
||
|
||
// ¿ÉÑ¡£ºÉèÖÃÖáÐĵãΪÓÒ²àÖе㣨ӰÏìËõ·Å/ÐýתÖÐÐÄ£©
|
||
bg.rectTransform.pivot = new Vector2(1, 0.5f);
|
||
break;
|
||
}
|
||
}
|
||
|
||
protected override void OnShow()
|
||
{
|
||
}
|
||
|
||
protected override void OnHide()
|
||
{
|
||
}
|
||
|
||
protected override void OnClose()
|
||
{
|
||
}
|
||
public void OnModuleQuit(OnModuleQuit arg)
|
||
{
|
||
Hide();
|
||
}
|
||
}
|
||
}
|