You've already forked taptap2024_GJ_chidouren
init
This commit is contained in:
137
Assets/Scripts/System/Guide/CommonGuidePanel.cs
Normal file
137
Assets/Scripts/System/Guide/CommonGuidePanel.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Guide;
|
||||
using Framework.Timer;
|
||||
using Framework.UI;
|
||||
using Framework.Utils;
|
||||
using Framework.Utils.UITools;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using IcecreamView;
|
||||
using TMPro;
|
||||
using Utils;
|
||||
using CameraType = Framework.Utils.CameraType;
|
||||
|
||||
namespace Views
|
||||
{
|
||||
public class CommonGuidePanel : IcecreamView.IC_AbstractModule
|
||||
{
|
||||
[SerializeField] private RectTransform _mask;
|
||||
[SerializeField] private RectTransform _target;
|
||||
[SerializeField] private RectTransform _tipWindow;
|
||||
[SerializeField] private TMP_Text _tipText;
|
||||
|
||||
private Vector3 _basePosition;
|
||||
private Transform _baseParent;
|
||||
private GuideNode _node;
|
||||
private int _objectIndex;
|
||||
private AdjustBox _adjustBox;
|
||||
|
||||
public override void OnInitView ()
|
||||
{
|
||||
this._node = null;
|
||||
GameUpdateMgr.Instance.AddUpdater (DoUpdate);
|
||||
this._adjustBox = new AdjustBox (CameraGroup.Instance.GetCamera (CameraType.Ui) , (RectTransform)this.transform , _tipWindow ,
|
||||
new Vector2Int (1, 1));
|
||||
}
|
||||
|
||||
private void DoUpdate ()
|
||||
{
|
||||
if (ReferenceEquals (this._node , null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReferenceEquals (this._node , default))
|
||||
{
|
||||
this.ViewConnector.CloseView ();
|
||||
return;
|
||||
}
|
||||
if (!_node.IsMask)
|
||||
{
|
||||
var screenPoint = UIKit.WorldPointToScreenPoint (this._node.transform.position ,
|
||||
CameraGroup.Instance.GetCamera (this._node.fromCameraType) );
|
||||
this._target.anchoredPosition
|
||||
= UIKit.ScreenPointToUILocalPoint (CameraGroup.Instance.GetCamera (CameraType.Ui) , this._mask , screenPoint );
|
||||
this._target.sizeDelta = ((RectTransform)(this._node.transform)).rect.size;
|
||||
}
|
||||
this._adjustBox.ExpendDistance = this._node.guideWindowExpend;
|
||||
this._adjustBox.AutoController (this._target);
|
||||
}
|
||||
|
||||
public override void OnOpenView (IC_ViewData parameters)
|
||||
{
|
||||
ResetNode ();
|
||||
this._node = parameters.GetValue<GuideNode> ();
|
||||
Transform nodeTransform;
|
||||
this._objectIndex = (nodeTransform = this._node.transform).GetSiblingIndex ();
|
||||
this._baseParent = nodeTransform.parent;
|
||||
this._basePosition = nodeTransform.position;
|
||||
SetNode ();
|
||||
}
|
||||
|
||||
public override void OnCloseView ()
|
||||
{
|
||||
ResetNode ();
|
||||
}
|
||||
|
||||
private void OnDestroy ()
|
||||
{
|
||||
GameUpdateMgr.Instance.RemoveUpdater (DoUpdate);
|
||||
}
|
||||
|
||||
private void SetNode ()
|
||||
{
|
||||
this._mask.gameObject.SetActive (this._node.IsMask);
|
||||
|
||||
var screenPoint = UIKit.WorldPointToScreenPoint (this._node.transform.position ,
|
||||
CameraGroup.Instance.GetCamera (this._node.fromCameraType) );
|
||||
|
||||
if (this._node.IsMask)
|
||||
{
|
||||
this._node.transform.SetParent (this.transform , false);
|
||||
this._node.transform.SetAsLastSibling ();
|
||||
}
|
||||
this._target.anchoredPosition
|
||||
= UIKit.ScreenPointToUILocalPoint (CameraGroup.Instance.GetCamera (CameraType.Ui) , this._mask , screenPoint );
|
||||
|
||||
if (_node.IsMask)
|
||||
{
|
||||
this._node.transform.position = _target.position;
|
||||
}
|
||||
|
||||
this._target.sizeDelta = ((RectTransform)(this._node.transform)).rect.size;
|
||||
this._adjustBox.ExpendDistance = this._node.guideWindowExpend;
|
||||
this._adjustBox.AutoController (this._target);
|
||||
|
||||
this._tipWindow.transform.SetAsLastSibling ();
|
||||
this._tipText.text = this._node.Tip;
|
||||
this._tipWindow.gameObject.SetActive (!string.IsNullOrEmpty (this._node.Tip));
|
||||
}
|
||||
|
||||
private void ResetNode ()
|
||||
{
|
||||
if (this._node != null)
|
||||
{
|
||||
if (this._baseParent == null)
|
||||
{
|
||||
Destroy (this._node.gameObject);
|
||||
}
|
||||
else if (this._node.transform.parent != this._baseParent)
|
||||
{
|
||||
// var screenPoint = UIKit.WorldPointToScreenPoint (this._node.transform.position ,
|
||||
// CameraGroup.Instance.GetCamera (CameraType.Ui) );
|
||||
|
||||
this._node.transform.SetParent (this._baseParent, false);
|
||||
this._node.transform.SetSiblingIndex (this._objectIndex);
|
||||
if (_node.IsMask)
|
||||
{
|
||||
_node.transform.position = _basePosition;
|
||||
}
|
||||
}
|
||||
|
||||
this._node = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user