新增UIBackPack

This commit is contained in:
shenjianxing 2025-03-08 13:15:13 +08:00
parent 5e0af963c2
commit 3cfa13795e
13 changed files with 1607 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 310f51a2e0ce8db40b698f99e78ae145
PrefabImporter:
externalObjects: {}
userData:
assetBundleName: uibackpack_prefab
assetBundleVariant:

View File

@ -118,6 +118,11 @@ public class ActionHelper
var strAction = (XMLTool.DictionaryAction)act;
return UIToolsAction.Allocate(strAction.args);
}
case "UIBackPack":
{
var strAction = (XMLTool.DictionaryAction)act;
return UIBackPackAction.Allocate(strAction.args);
}
case "PointQuestion":
return PointQuestionAction.Allocate(act.Value);
case "Point3DQuestion":

View File

@ -0,0 +1,74 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QFramework;
using System;
using QFramework.Example;
using System.Linq;
public class UIBackPackAction : IAction
{
public ulong ActionID { get; set; }
public bool Deinited { get; set; }
public bool Paused { get; set; }
public ActionStatus Status { get; set; }
private static readonly SimpleObjectPool<UIBackPackAction> mPool =
new SimpleObjectPool<UIBackPackAction>(() => new UIBackPackAction(), null, 10);
string devices;
string random;
string scrollSpeed;
string position;
public static UIBackPackAction Allocate(Dictionary<string, string> datas, System.Action onDelayFinish = null)
{
var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++;
retNode.Deinited = false;
retNode.Reset();
retNode.devices = datas.ContainsKey("devices") ? datas["devices"] : "";
retNode.random = datas.ContainsKey("random") ? datas["random"] : "";
retNode.scrollSpeed = datas.ContainsKey("scrollSpeed") ? datas["scrollSpeed"] : "";
retNode.position = datas.ContainsKey("position") ? datas["position"] : "";
return retNode;
}
public void Deinit()
{
if (!Deinited)
{
Deinited = true;
mPool.Recycle(this);
}
}
public void OnExecute(float dt)
{
}
public void OnFinish()
{
}
public void OnStart()
{
UIBackPackData data = new UIBackPackData();
data.devices = devices.Split(',').ToList();
if (bool.TryParse(random, out data.random) == false)
{
data.random = false;
}
if (float.TryParse(scrollSpeed, out data.scrollSpeed) == false)
{
data.scrollSpeed = 25;
}
data.position = position;
UIKit.OpenPanelAsync<UIBackPack>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish());
}
public void Reset()
{
Status = ActionStatus.NotStart;
Paused = false;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e766ada0be55001488d4a5368bb7e63d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

55
Assets/Scripts/UI/UIBackPack.Designer.cs generated Normal file
View File

@ -0,0 +1,55 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using QFramework;
namespace QFramework.Example
{
// Generate Id:df731f7c-b33b-4edd-ac53-d859f4d06272
public partial class UIBackPack
{
public const string Name = "UIBackPack";
[SerializeField]
public UnityEngine.UI.Image bg;
[SerializeField]
public UnityEngine.UI.ScrollRect Scroll;
[SerializeField]
public RectTransform Content;
[SerializeField]
public UnityEngine.UI.Button ItemPrefab;
private UIBackPackData mPrivateData = null;
protected override void ClearUIComponents()
{
bg = null;
Scroll = null;
Content = null;
ItemPrefab = null;
mData = null;
}
public UIBackPackData Data
{
get
{
return mData;
}
}
UIBackPackData mData
{
get
{
return mPrivateData ?? (mPrivateData = new UIBackPackData());
}
set
{
mUIData = value;
mPrivateData = value;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7c10e0cf42fc507478eb8da812616766
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,110 @@
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();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10936952f7d03a849933486ae2d33b90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -69,6 +69,7 @@ namespace QFramework.Example
});
loader.LoadAsync();
}
transform.SetAsLastSibling();
}
protected override void OnShow()

View File

@ -34,6 +34,7 @@ namespace QFramework.Example
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UIToolsData ?? new UIToolsData();
mResLoader = ResLoader.Allocate();
// please add init code here
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuit).UnRegisterWhenGameObjectDestroyed(gameObject);
}
@ -51,7 +52,6 @@ namespace QFramework.Example
{
ScoreController.Instance.Add(mData.scoreStepName, mData.totalScore);
}
mResLoader = ResLoader.Allocate();
mData = uiData as UIToolsData ?? new UIToolsData();
if (string.IsNullOrEmpty(mData.answer) == false)
{

View File

@ -588,6 +588,28 @@ namespace XMLTool
newAction = act;
}
break;
case "UIBackPack":
{
var act = new DictionaryAction();
act.args.Add("devices", action.Attribute("devices").Value);
var random = action.Attribute("random");
if (random != null)
{
act.args.Add("random", random.Value);
}
var scrollSpeed = action.Attribute("scrollSpeed");
if (scrollSpeed != null)
{
act.args.Add("scrollSpeed", scrollSpeed.Value);
}
var position = action.Attribute("position");
if (position != null)
{
act.args.Add("position", position.Value);
}
newAction = act;
}
break;
case "TextQuestion":
{
var act = new DictionaryAction();

View File

@ -48,6 +48,12 @@
scrollSpeed="25"
position="right"></Action>
<!--道具背包,用于配合状态机进行道具的使用 目前是初步版本仅支持配合UIClick点击暂无道具数量等功能 详细参数可参考UITools-->
<Action type="UIBackPack" devices="道具名字1"
random="true"
scrollSpeed="25"
position="right"></Action>
<!--物体点位选择 物体的中心点-->
<Action type="PointQuestion" value="路径1,路径2"></Action>
<!--物体点位选择 3D版