VirtualFramework/Assets/Scripts/UI/UIPointQuestion.cs
2024-12-31 17:27:27 +08:00

77 lines
2.1 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System.Collections.Generic;
using static OperationController;
namespace QFramework.Example
{
public class UIPointQuestionData : UIPanelData
{
public string paths;
}
public partial class UIPointQuestion : UIPanel
{
public Dictionary<GameObject, GameObject> pointMap = new Dictionary<GameObject, GameObject>();
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UIPointQuestionData ?? new UIPointQuestionData();
// please add init code here
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged);
}
private void OnStepChanged(StepStatusOnChange change)
{
Hide();
}
protected override void OnOpen(IUIData uiData = null)
{
mData = uiData as UIPointQuestionData ?? new UIPointQuestionData();
Content.RemoveAllChildren();
var paths = mData.paths.Split(',');
for (int i = 0; i < paths.Length; i++)
{
string path = paths[i];
GameObject obj = Utility.FindObj(path);
if (obj != null)
{
GameObject point = GameObject.Instantiate(PointPrefab.gameObject, Content);
point.name = (i + 1).ToString();
pointMap.Add(obj, point);
}
else
{
Debug.LogError($"ûÓÐÕÒµ½Â·¾¶{path}");
}
}
}
private void Update()
{
if (gameObject.activeSelf)
{
foreach (var item in pointMap)
{
Vector3 screenPosition = Camera.main.WorldToScreenPoint(item.Key.Position());
item.Value.transform.position = screenPosition;
}
}
}
protected override void OnShow()
{
}
protected override void OnHide()
{
pointMap.Clear();
}
protected override void OnClose()
{
}
}
}