247 lines
7.6 KiB
C#
247 lines
7.6 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using QFramework;
|
||
using System.Text.RegularExpressions;
|
||
using DG.Tweening;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using static UnityEngine.GraphicsBuffer;
|
||
using UnityEngine.Assertions;
|
||
|
||
namespace QFramework.Example
|
||
{
|
||
public class UIGuideTipData : UIPanelData
|
||
{
|
||
public string targets;
|
||
|
||
public string showName;
|
||
|
||
public string offestPos;
|
||
|
||
|
||
public string tiptextAudio;
|
||
|
||
|
||
}
|
||
public partial class UIGuideTip : UIPanel
|
||
{
|
||
|
||
[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;
|
||
}
|
||
}
|
||
|
||
|
||
ResLoader loader;
|
||
protected override void OnInit(IUIData uiData = null)
|
||
{
|
||
mData = uiData as UIGuideTipData ?? new UIGuideTipData();
|
||
//uIGuideTipData = mData;
|
||
// please add init code here
|
||
loader = ResLoader.Allocate();
|
||
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||
|
||
}
|
||
|
||
protected override void OnOpen(IUIData uiData = null)
|
||
{
|
||
Connet.RemoveAllChildren();
|
||
TipOffectList.Clear();
|
||
TipItemList.Clear();
|
||
mData = uiData as UIGuideTipData ?? new UIGuideTipData();
|
||
//uIGuideTipData = mData;
|
||
if (uiData != null)
|
||
{
|
||
Connet.RemoveAllChildren();
|
||
gameCamera = GameObject.Find("ZhanShiCamera").GetComponent<Camera>();
|
||
mData = uiData as UIGuideTipData ?? new UIGuideTipData();
|
||
Debug.Log(mData);
|
||
List<String> Objs = mData.targets.Split(',')?.ToList();
|
||
List<String> ShowTexts = mData.showName.Split(',')?.ToList();
|
||
List<String> textTip =mData.tiptextAudio.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>");
|
||
|
||
}
|
||
|
||
//<2F><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
|
||
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>()
|
||
|
||
);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
isUpdate = true;
|
||
|
||
}
|
||
|
||
//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()
|
||
{
|
||
}
|
||
}
|
||
}
|