227 lines
5.1 KiB
C#
227 lines
5.1 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-12-14
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "GuideWindow.View" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G.UI
|
|
{
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
partial class GuideWindow
|
|
{
|
|
#region Auto Generate
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
GameObject _goTarget;
|
|
[KUIFlag]
|
|
KHighLightMask _goMask;
|
|
[KUIFlag]
|
|
Button _goMask2;
|
|
[KUIFlag]
|
|
RectTransform _goTalking;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpTalking;
|
|
[KUIFlag]
|
|
Animator _hand;
|
|
[KUIFlag]
|
|
RectTransform _handRoot;
|
|
[KUIFlag]
|
|
RectTransform _handSquare;
|
|
[KUIFlag]
|
|
RectTransform _handCircle;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpHandTips;
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
#endregion
|
|
|
|
#region Field
|
|
|
|
private Vector2 _defaultTalkingPos;
|
|
private float _clickDelay;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void InitView()
|
|
{
|
|
SetViewData();
|
|
_goMask.maskClicked.AddListener(this.OnMaskClick);
|
|
_goMask2.onClick.AddListener(this.OnMask2Click);
|
|
|
|
_goMask.gameObject.SetActive(false);
|
|
_goMask2.gameObject.SetActive(false);
|
|
_handSquare.gameObject.SetActive(false);
|
|
_handCircle.gameObject.SetActive(false);
|
|
|
|
_defaultTalkingPos = _goTalking.GetComponent<RectTransform>().position;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void RefreshView()
|
|
{
|
|
if (this.data is GuideInfo guideInfo)
|
|
{
|
|
_clickDelay = Time.unscaledTime + guideInfo.delay;
|
|
|
|
ShowGuide(guideInfo);
|
|
|
|
ShowHand(guideInfo);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void UpdateView()
|
|
{
|
|
if (this.data is GuideInfo guideInfo)
|
|
{
|
|
ShowGuide(guideInfo);
|
|
//ShowHand(guideInfo);
|
|
}
|
|
}
|
|
|
|
private bool ClickValid()
|
|
{
|
|
return _clickDelay < Time.unscaledTime;
|
|
}
|
|
|
|
private void ShowGuide(GuideInfo guide)
|
|
{
|
|
if (!string.IsNullOrEmpty(guide.targetPath))
|
|
{
|
|
if (guide.target)
|
|
{
|
|
ShowTarget(guide.target.transform as RectTransform);
|
|
}
|
|
else
|
|
{
|
|
_goMask.gameObject.SetActive(true);
|
|
_goMask2.gameObject.SetActive(false);
|
|
|
|
guide.target = GameObject.Find(guide.targetPath);
|
|
if (guide.target)
|
|
{
|
|
ShowTarget(guide.target.transform as RectTransform);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShowTarget(null);
|
|
_goMask.gameObject.SetActive(false);
|
|
_goMask2.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void ShowTarget(RectTransform targetRT)
|
|
{
|
|
var rectT = _goTarget.GetComponent<RectTransform>();
|
|
if (!targetRT)
|
|
{
|
|
_handSquare.gameObject.SetActive(false);
|
|
rectT.pivot = Vector2.one * 0.5f;
|
|
rectT.position = Vector3.zero;
|
|
return;
|
|
}
|
|
|
|
_goMask.targetRectTransform1 = targetRT;
|
|
|
|
rectT.pivot = targetRT.pivot;
|
|
rectT.position = targetRT.position;
|
|
//rect.localScale = tR.lossyScale;
|
|
//rect.rotation = tR.rotation;
|
|
//rect.sizeDelta = tR.sizeDelta;
|
|
//return;
|
|
var screenPoint = RectTransformUtility.WorldToScreenPoint(KUIRoot.RootCamera, targetRT.position);
|
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)this.transform, screenPoint, KUIRoot.RootCamera, out var localPoint))
|
|
{
|
|
_handSquare.gameObject.SetActive(true);
|
|
_handSquare.anchorMax = targetRT.anchorMax;
|
|
_handSquare.anchorMin = targetRT.anchorMin;
|
|
_handSquare.anchoredPosition = targetRT.anchoredPosition;
|
|
_handSquare.anchoredPosition3D = targetRT.anchoredPosition3D;
|
|
_handSquare.offsetMax = targetRT.offsetMax;
|
|
_handSquare.offsetMin = targetRT.offsetMin;
|
|
_handSquare.pivot = targetRT.pivot;
|
|
_handSquare.sizeDelta = targetRT.sizeDelta;
|
|
_handSquare.localPosition = localPoint;
|
|
}
|
|
}
|
|
|
|
private void ShowHand(GuideInfo guide)
|
|
{
|
|
// hand
|
|
if (guide.handPoint != Vector2.zero)
|
|
{
|
|
_goTarget.SetActive(true);
|
|
if (guide.handAnimId != 0)
|
|
{
|
|
_hand.Play(guide.handAnimId);
|
|
}
|
|
_handRoot.anchoredPosition = guide.handPoint;
|
|
|
|
_tmpHandTips.text = guide.handTips;
|
|
}
|
|
else
|
|
{
|
|
_goTarget.SetActive(false);
|
|
}
|
|
|
|
// talking
|
|
if (!string.IsNullOrEmpty(guide.talking))
|
|
{
|
|
_goTalking.gameObject.SetActive(true);
|
|
_goTalking.anchoredPosition = guide.talkingPoint;
|
|
_goTalking.anchorMin = guide.talkingAnchor;
|
|
_goTalking.anchorMax = guide.talkingAnchor;
|
|
_tmpTalking.text = guide.talking;
|
|
}
|
|
else
|
|
{
|
|
_goTalking.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void OnMaskClick()
|
|
{
|
|
if (!ClickValid())
|
|
return;
|
|
|
|
_goMask.targetRectTransform1 = null;
|
|
CloseWindow(this);
|
|
TutorialProxy.Instance.CompleteStage();
|
|
}
|
|
|
|
private void OnMask2Click()
|
|
{
|
|
if (!ClickValid())
|
|
return;
|
|
|
|
CloseWindow(this);
|
|
TutorialProxy.Instance.CompleteStage();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|