309 lines
10 KiB
C#
309 lines
10 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;
|
||
using static System.Net.Mime.MediaTypeNames;
|
||
|
||
namespace QFramework.Example
|
||
{
|
||
public class UIGuideTipData : UIPanelData
|
||
{
|
||
public string targets;
|
||
|
||
public string showName;
|
||
|
||
public string offestPos;
|
||
|
||
|
||
public string tiptext;
|
||
public string tipaudio;
|
||
public string tiptitle;
|
||
|
||
}
|
||
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> Tip = mData.tiptext.Split('|')?.ToList();
|
||
List<String> audio = mData.tipaudio.Split('|')?.ToList();
|
||
List< String > tiptitle = mData.tiptitle.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>");
|
||
}
|
||
//Tip<69><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
tipItemObj.GetComponentInChildren<UnityEngine.UI.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>()
|
||
|
||
);
|
||
}
|
||
if (Tip.Count != 0 || audio.Count != 0|| tiptitle.Count != 0)
|
||
{
|
||
// <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++)
|
||
{
|
||
|
||
|
||
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(() => {
|
||
|
||
UIKit.ClosePanel<UITextWindow>();
|
||
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>Χ<EFBFBD><CEA7>
|
||
int safeIndex = Math.Min(currentIndex, minListCount - 1);
|
||
|
||
if (safeIndex >= 0 && safeIndex < Tip.Count && safeIndex < audio.Count)
|
||
{
|
||
//Debug.Log(Tip[safeIndex] + "Tip");
|
||
//Debug.Log(audio[safeIndex] + "audio");
|
||
|
||
|
||
// <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],
|
||
audio = audio[safeIndex],
|
||
title= tiptitle[safeIndex]
|
||
};
|
||
|
||
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}");
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
isUpdate = true;
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
public 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()
|
||
{
|
||
}
|
||
}
|
||
}
|