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-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
|
|
|
|
|
|
|
|
|
|
public string tiptextAudio;
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
Debug.Log(TipOffect + "??????????");
|
|
|
|
|
|
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());
|
|
|
|
|
|
if (target==null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><ECB3A3>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
}
|
|
|
|
|
|
tipItemObj.GetComponentInChildren<Text>().text = ShowTexts[i];
|
|
|
|
|
|
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-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
|
|
|
|
//private void OnCloseSelf(string[] obj)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// CloseSelf();
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log("LateUpdate");
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
Debug.Log("UpdatePos");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnShow()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnHide()
|
|
|
|
|
|
{
|
|
|
|
|
|
isUpdate = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnClose()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-22 18:04:02 +08:00
|
|
|
|
}
|