VirtualFramework/Assets/Scripts/UI/UIPointQuestion.cs

65 lines
1.8 KiB
C#
Raw Normal View History

2024-12-14 18:27:59 +08:00
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System.Collections.Generic;
using Unity.VisualScripting;
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
}
protected override void OnOpen(IUIData uiData = null)
{
mData = uiData as UIPointQuestionData ?? new UIPointQuestionData();
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);
}
}
}
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()
{
}
protected override void OnClose()
{
pointMap.Clear();
}
}
}