2025-05-22 18:04:02 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using QFramework;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
2025-05-23 17:41:26 +08:00
|
|
|
|
using DG.Tweening;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2025-05-26 19:19:40 +08:00
|
|
|
|
using static UnityEngine.GraphicsBuffer;
|
|
|
|
|
|
using UnityEngine.Assertions;
|
2025-05-27 11:56:08 +08:00
|
|
|
|
using static System.Net.Mime.MediaTypeNames;
|
2025-05-22 18:04:02 +08:00
|
|
|
|
|
|
|
|
|
|
namespace QFramework.Example
|
|
|
|
|
|
{
|
2025-05-26 19:19:40 +08:00
|
|
|
|
public class UIGuideTipData : UIPanelData
|
|
|
|
|
|
{
|
|
|
|
|
|
public string targets;
|
2025-05-22 18:04:02 +08:00
|
|
|
|
|
2025-05-23 17:41:26 +08:00
|
|
|
|
public string showName;
|
2025-05-22 18:04:02 +08:00
|
|
|
|
|
2025-05-26 19:19:40 +08:00
|
|
|
|
public string offestPos;
|
2025-05-22 18:04:02 +08:00
|
|
|
|
|
2025-05-26 20:22:21 +08:00
|
|
|
|
|
2025-05-27 11:56:08 +08:00
|
|
|
|
public string tiptext;
|
|
|
|
|
|
public string tipaudio;
|
2025-05-27 14:15:36 +08:00
|
|
|
|
public string tiptitle;
|
2025-05-26 20:22:21 +08:00
|
|
|
|
|
2025-05-22 18:04:02 +08:00
|
|
|
|
}
|
2025-05-26 19:19:40 +08:00
|
|
|
|
public partial class UIGuideTip : UIPanel
|
2025-05-23 17:41:26 +08:00
|
|
|
|
{
|
2025-05-26 19:19:40 +08:00
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
public Camera gameCamera;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
public List<Vector3> TipOffectList;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
|
|
|
|
|
|
public List<GameObject> TipItemList;
|
|
|
|
|
|
|
|
|
|
|
|
//UIGuideTipData uIGuideTipData;
|
|
|
|
|
|
public Camera Camera
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return this.gameCamera;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
this.gameCamera = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-23 17:41:26 +08:00
|
|
|
|
ResLoader loader;
|
|
|
|
|
|
protected override void OnInit(IUIData uiData = null)
|
2025-05-26 19:19:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
mData = uiData as UIGuideTipData ?? new UIGuideTipData();
|
|
|
|
|
|
//uIGuideTipData = mData;
|
2025-05-22 18:04:02 +08:00
|
|
|
|
// please add init code here
|
2025-05-23 17:41:26 +08:00
|
|
|
|
loader = ResLoader.Allocate();
|
2025-05-22 18:04:02 +08:00
|
|
|
|
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
2025-05-26 19:19:40 +08:00
|
|
|
|
|
2025-05-22 18:04:02 +08:00
|
|
|
|
}
|
2025-05-26 19:19:40 +08:00
|
|
|
|
|
|
|
|
|
|
protected override void OnOpen(IUIData uiData = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Connet.RemoveAllChildren();
|
|
|
|
|
|
TipOffectList.Clear();
|
|
|
|
|
|
TipItemList.Clear();
|
|
|
|
|
|
mData = uiData as UIGuideTipData ?? new UIGuideTipData();
|
|
|
|
|
|
//uIGuideTipData = mData;
|
2025-05-22 18:04:02 +08:00
|
|
|
|
if (uiData != null)
|
|
|
|
|
|
{
|
2025-05-26 19:19:40 +08:00
|
|
|
|
Connet.RemoveAllChildren();
|
|
|
|
|
|
gameCamera = GameObject.Find("ZhanShiCamera").GetComponent<Camera>();
|
2025-05-22 18:04:02 +08:00
|
|
|
|
mData = uiData as UIGuideTipData ?? new UIGuideTipData();
|
2025-05-26 19:19:40 +08:00
|
|
|
|
Debug.Log(mData);
|
|
|
|
|
|
List<String> Objs = mData.targets.Split(',')?.ToList();
|
|
|
|
|
|
List<String> ShowTexts = mData.showName.Split(',')?.ToList();
|
2025-05-27 14:15:36 +08:00
|
|
|
|
List<String> Tip = mData.tiptext.Split('|')?.ToList();
|
|
|
|
|
|
List<String> audio = mData.tipaudio.Split('|')?.ToList();
|
|
|
|
|
|
List< String > tiptitle = mData.tiptitle.Split('|')?.ToList();
|
2025-05-26 19:19:40 +08:00
|
|
|
|
if (String.IsNullOrEmpty(mData.offestPos) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> TipOffects = mData.offestPos.Split('|')?.ToList();
|
|
|
|
|
|
for (int i = 0; i < TipOffects.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector3 TipOffect = Utility.GetVector3FromStrArray(TipOffects[i]);
|
2025-05-27 11:56:08 +08:00
|
|
|
|
// Debug.Log(TipOffect + "??????????");
|
2025-05-26 19:19:40 +08:00
|
|
|
|
TipOffectList.Add(TipOffect);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("û<><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Tipƫ<70><C6AB>");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-26 20:22:21 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
|
2025-05-26 19:19:40 +08:00
|
|
|
|
for (int i = 0; i < Objs.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject tipItemObj = GameObject.Instantiate(TipItem.gameObject, Connet);
|
|
|
|
|
|
|
|
|
|
|
|
TipItemList.Add(tipItemObj);
|
|
|
|
|
|
tipItemObj.name = Objs[i];
|
|
|
|
|
|
GameObject target = GameObject.Find(Objs[i].ToString());
|
2025-05-27 11:56:08 +08:00
|
|
|
|
if (target == null)
|
2025-05-26 19:19:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><ECB3A3>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
}
|
2025-05-27 11:56:08 +08:00
|
|
|
|
//Tip<69><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
tipItemObj.GetComponentInChildren<UnityEngine.UI.Text>().text = ShowTexts[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-26 19:19:40 +08:00
|
|
|
|
UpdatePos(
|
|
|
|
|
|
target,
|
|
|
|
|
|
GetComponentInParent<Canvas>(),
|
|
|
|
|
|
tipItemObj.GetComponent<RectTransform>(),
|
|
|
|
|
|
tipItemObj.transform.Find("tip").GetComponent<RectTransform>(),
|
|
|
|
|
|
TipOffectList[i],
|
|
|
|
|
|
tipItemObj.transform.Find("Circle").GetComponent<RectTransform>(),
|
|
|
|
|
|
tipItemObj.transform.Find("Line").GetComponent<RectTransform>()
|
|
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-05-27 14:15:36 +08:00
|
|
|
|
if (Tip.Count != 0 || audio.Count != 0|| tiptitle.Count != 0)
|
2025-05-27 11:56:08 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD>ȣ<EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ
|
|
|
|
|
|
int minListCount = Math.Min(Tip.Count, audio.Count);
|
|
|
|
|
|
int buttonCount = TipItemList.Count;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < buttonCount; i++)
|
|
|
|
|
|
{
|
2025-05-27 14:15:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-05-27 11:56:08 +08:00
|
|
|
|
var tipButton = TipItemList[i].transform.Find("tip").GetComponent<Button>();
|
|
|
|
|
|
tipButton.onClick.RemoveAllListeners();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ľֲ<C4BE><D6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>հ<EFBFBD><D5B0><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
int currentIndex = i;
|
|
|
|
|
|
|
|
|
|
|
|
tipButton.onClick.AddListener(() => {
|
2025-05-27 14:15:36 +08:00
|
|
|
|
|
|
|
|
|
|
UIKit.ClosePanel<UITextWindow>();
|
|
|
|
|
|
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>Χ<EFBFBD><CEA7>
|
|
|
|
|
|
int safeIndex = Math.Min(currentIndex, minListCount - 1);
|
2025-05-27 11:56:08 +08:00
|
|
|
|
|
|
|
|
|
|
if (safeIndex >= 0 && safeIndex < Tip.Count && safeIndex < audio.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log(Tip[safeIndex] + "Tip");
|
|
|
|
|
|
Debug.Log(audio[safeIndex] + "audio");
|
|
|
|
|
|
|
2025-05-27 14:15:36 +08:00
|
|
|
|
|
2025-05-27 11:56:08 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ո<EFBFBD><D5B8><EFBFBD><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
Tip[safeIndex] = Utility.RemoveSpacesAndEmptyLines(Tip[safeIndex]);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>ƣ<EFBFBD><C6A3>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>пո<D0BF>
|
|
|
|
|
|
audio[safeIndex] = Utility.RemoveSpacesAndEmptyLines(audio[safeIndex], true);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><>ֵ<EFBFBD><D6B5>ť
|
|
|
|
|
|
var data = new UITextWindowData
|
|
|
|
|
|
{
|
|
|
|
|
|
text = Tip[safeIndex],
|
2025-05-27 14:15:36 +08:00
|
|
|
|
audio = audio[safeIndex],
|
|
|
|
|
|
title= tiptitle[safeIndex]
|
2025-05-27 11:56:08 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UIKit.OpenPanelAsync<UITextWindow>(uiData: data, canvasLevel: UILevel.PopUI)
|
|
|
|
|
|
.ToAction()
|
|
|
|
|
|
.Start(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning($"<22><><EFBFBD><EFBFBD> {currentIndex} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD>Χ<EFBFBD><CEA7>Tip.Count={Tip.Count}, audio.Count={audio.Count}");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-23 17:41:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-05-22 18:04:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-26 19:19:40 +08:00
|
|
|
|
|
|
|
|
|
|
isUpdate = true;
|
|
|
|
|
|
|
2025-05-22 18:04:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-26 19:19:40 +08:00
|
|
|
|
|
2025-05-27 11:56:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-26 19:19:40 +08:00
|
|
|
|
|
|
|
|
|
|
bool isUpdate = false;
|
|
|
|
|
|
private void LateUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (isUpdate)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < TipItemList.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject tipItemObj = TipItemList[i];
|
|
|
|
|
|
|
|
|
|
|
|
GameObject target = GameObject.Find(TipItemList[i].name);
|
|
|
|
|
|
|
2025-05-27 11:56:08 +08:00
|
|
|
|
//Debug.Log("LateUpdate");
|
2025-05-26 19:19:40 +08:00
|
|
|
|
|
|
|
|
|
|
UpdatePos(
|
|
|
|
|
|
target,
|
|
|
|
|
|
GetComponentInParent<Canvas>(),
|
|
|
|
|
|
tipItemObj.GetComponent<RectTransform>(),
|
|
|
|
|
|
tipItemObj.transform.Find("tip").GetComponent<RectTransform>(),
|
|
|
|
|
|
TipOffectList[i],
|
|
|
|
|
|
tipItemObj.transform.Find("Circle").GetComponent<RectTransform>(),
|
|
|
|
|
|
tipItemObj.transform.Find("Line").GetComponent<RectTransform>()
|
|
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB>λ<EFBFBD><CEBB>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
public static Vector3 CalculateScreenPosition(Vector3 position/* Ŀ<><C4BF><EFBFBD><EFBFBD>*/, Camera camera, Canvas canvas,
|
|
|
|
|
|
RectTransform transform)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull<Camera>(camera);
|
|
|
|
|
|
Assert.IsNotNull<Canvas>(canvas);
|
|
|
|
|
|
Assert.IsNotNull<RectTransform>(transform);
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>
|
|
|
|
|
|
Vector3 vector = camera.WorldToScreenPoint(position);
|
|
|
|
|
|
Vector3 zero = Vector3.zero;
|
|
|
|
|
|
//<2F>ж<EFBFBD>canvas <20><>Ⱦģʽ
|
|
|
|
|
|
switch (canvas.renderMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F><>Ļ<EFBFBD>ռ<EFBFBD>
|
|
|
|
|
|
case RenderMode.ScreenSpaceOverlay:
|
|
|
|
|
|
RectTransformUtility.ScreenPointToWorldPointInRectangle(transform, vector, null, out zero);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case RenderMode.ScreenSpaceCamera:
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>
|
|
|
|
|
|
case RenderMode.WorldSpace:
|
|
|
|
|
|
RectTransformUtility.ScreenPointToWorldPointInRectangle(transform, vector, canvas.worldCamera,
|
|
|
|
|
|
out zero);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
return zero;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// <20><>ֵTipItem<65><6D><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void UpdatePos(GameObject target, Canvas canvas, RectTransform TipItem, RectTransform tip, Vector3 tipOffset, RectTransform YuanDian, RectTransform zhiyinxian)
|
|
|
|
|
|
{
|
|
|
|
|
|
//if (this.target == null || this.canvas == null || this.gameCamera == null || this.rectTransform == null)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 position = CalculateScreenPosition(target.transform.position, gameCamera,
|
|
|
|
|
|
canvas, tip.GetComponent<RectTransform>());
|
|
|
|
|
|
tip.transform.position = position + tipOffset;
|
|
|
|
|
|
|
|
|
|
|
|
YuanDian.transform.position = Camera.WorldToScreenPoint(target.transform.position) /*+ YuanDianOffset*/;
|
|
|
|
|
|
zhiyinxian.transform.position = (YuanDian.transform.position + tip.transform.position) / 2;
|
|
|
|
|
|
zhiyinxian.transform.localEulerAngles = new Vector3(0, 0, Vector2.SignedAngle(Vector2.right, YuanDian.transform.position - tip.transform.position));
|
|
|
|
|
|
float length = (YuanDian.transform.position - tip.transform.position).magnitude;
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ߵĿ<DFB5><C4BF><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
zhiyinxian.GetComponent<RectTransform>().sizeDelta = new Vector2(length, 3f);
|
2025-05-27 11:56:08 +08:00
|
|
|
|
//Debug.Log("UpdatePos");
|
2025-05-26 19:19:40 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnShow()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnHide()
|
|
|
|
|
|
{
|
|
|
|
|
|
isUpdate = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnClose()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-22 18:04:02 +08:00
|
|
|
|
}
|