修复无子步骤时bug

This commit is contained in:
shenjianxing 2025-02-07 14:25:12 +08:00
parent fe5169e55a
commit bf6b7c057a

View File

@ -7,6 +7,7 @@ using TMPro;
using System.Collections.Generic; using System.Collections.Generic;
using static OperationController; using static OperationController;
using System; using System;
using UnityEditor.Hardware;
namespace QFramework.Example namespace QFramework.Example
{ {
public class UIOperationListData : UIPanelData public class UIOperationListData : UIPanelData
@ -87,6 +88,9 @@ namespace QFramework.Example
op = OperationController.Instance.operation; op = OperationController.Instance.operation;
StepContent.RemoveAllChildren(); StepContent.RemoveAllChildren();
foreach (var item in op.Steps) foreach (var item in op.Steps)
{
if (item.SubSteps != null && item.SubSteps.Count > 0)
{ {
GameObject obj = GameObject.Instantiate(Step.gameObject, StepContent); GameObject obj = GameObject.Instantiate(Step.gameObject, StepContent);
Transform title = obj.transform.Find("Title"); Transform title = obj.transform.Find("Title");
@ -102,11 +106,8 @@ namespace QFramework.Example
btns.Add(btn); btns.Add(btn);
arrow.gameObject.SetActive(subContent.transform.childCount > 0); arrow.gameObject.SetActive(subContent.transform.childCount > 0);
btn.onClick.AddListener(() => btn.onClick.AddListener(() =>
{
if (subContent.transform.childCount > 0)
{ {
subContent.SetActive(!subContent.activeSelf); subContent.SetActive(!subContent.activeSelf);
}
if (op.freeStep) if (op.freeStep)
{ {
if (highIcon.color != highColor) if (highIcon.color != highColor)
@ -115,13 +116,23 @@ namespace QFramework.Example
} }
} }
}); });
if (item.SubSteps != null)
{
foreach (var sub in item.SubSteps) foreach (var sub in item.SubSteps)
{ {
GameObject subObj = GameObject.Instantiate(SubStep.gameObject, subContent.transform); StepItemFactory(subContent.transform, sub.Name);
}
}
else
{
StepItemFactory(StepContent, item.Name);
}
}
}
public void StepItemFactory(Transform content, string txt)
{
GameObject subObj = GameObject.Instantiate(SubStep.gameObject, content.transform);
var stepLabel = subObj.transform.Find("StepLabel").GetComponent<TextMeshProUGUI>(); var stepLabel = subObj.transform.Find("StepLabel").GetComponent<TextMeshProUGUI>();
stepLabel.text = sub.Name; stepLabel.text = txt;
Button subBtn = subObj.GetComponent<Button>(); Button subBtn = subObj.GetComponent<Button>();
subBtn.name = btns.Count.ToString(); subBtn.name = btns.Count.ToString();
btns.Add(subBtn); btns.Add(subBtn);
@ -134,11 +145,6 @@ namespace QFramework.Example
} }
}); });
} }
}
}
}
protected override void OnShow() protected override void OnShow()
{ {