190 lines
5.5 KiB
C#
190 lines
5.5 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using GCGame.Table;
|
|||
|
|
|||
|
public class GuideStepBase : MonoBehaviour
|
|||
|
{
|
|||
|
#region attr
|
|||
|
|
|||
|
public enum GUIDE_OPT_TYPE
|
|||
|
{
|
|||
|
ForceOpt,
|
|||
|
FreeOpt,
|
|||
|
ClickClose,
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region params
|
|||
|
|
|||
|
public string GuideUIPath;
|
|||
|
public int GuideTipStr;
|
|||
|
|
|||
|
public GuideItem BelongGuideItem
|
|||
|
{
|
|||
|
get; set;
|
|||
|
}
|
|||
|
|
|||
|
public GUIDE_OPT_TYPE GuideType;
|
|||
|
public Vector3 GuideInfoPosOffset;
|
|||
|
public bool IsShowEffect = false;
|
|||
|
public bool IsClickBehind = true;
|
|||
|
|
|||
|
protected GameObject _GuideUIGO;
|
|||
|
protected GameObject _CopyGuideGO;
|
|||
|
protected List<string> _GuideUIImagePath;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
public virtual void StartGuideStep()
|
|||
|
{
|
|||
|
gameObject.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
public virtual void FinishGuideStep()
|
|||
|
{
|
|||
|
if (!gameObject.activeSelf)
|
|||
|
return;
|
|||
|
|
|||
|
StopGuideStep();
|
|||
|
BelongGuideItem.NextStep();
|
|||
|
}
|
|||
|
|
|||
|
public virtual void StopGuideStep()
|
|||
|
{
|
|||
|
gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
protected virtual void ShowGuide()
|
|||
|
{
|
|||
|
if (_GuideUIGO == null)
|
|||
|
{
|
|||
|
FinishGuideStep();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (GuideType == GUIDE_OPT_TYPE.ForceOpt)
|
|||
|
{
|
|||
|
GuideLogic.Instance().SetForceBackActive(true);
|
|||
|
}
|
|||
|
else if (GuideType == GUIDE_OPT_TYPE.ClickClose)
|
|||
|
{
|
|||
|
GuideLogic.Instance().SetClickBack();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
GuideLogic.Instance().SetForceBackActive(false);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
GuideLogic.Instance().ShowGuideInfo();
|
|||
|
GuideLogic.Instance()._GuideTips.text = StrDictionary.GetClientDictionaryString("#{" + GuideTipStr.ToString() + "}");
|
|||
|
//GuideLogic.Instance()._GuideInfo.position = _GuideUIGO.transform.position + GuideInfoPosOffset;
|
|||
|
GuideLogic.Instance()._GuidePos.position = _GuideUIGO.transform.position;
|
|||
|
GuideLogic.Instance()._GuidePos.anchoredPosition += new Vector2(GuideInfoPosOffset.x, GuideInfoPosOffset.y);
|
|||
|
iTween.MoveTo(GuideLogic.Instance()._GuideInfo.gameObject, GuideLogic.Instance()._GuidePos.position, 0.5f);
|
|||
|
if (GuideInfoPosOffset.x > 0)
|
|||
|
{
|
|||
|
GuideLogic.Instance().ShowGuideLeft();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
GuideLogic.Instance().ShowGuideRight();
|
|||
|
}
|
|||
|
|
|||
|
if (IsShowEffect)
|
|||
|
{
|
|||
|
GuideLogic.Instance().ShowEffect(_GuideUIGO.transform.position);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
GuideLogic.Instance().HideEffect();
|
|||
|
}
|
|||
|
|
|||
|
if (_CopyGuideGO != null)
|
|||
|
{
|
|||
|
_CopyGuideGO.SetActive(false);
|
|||
|
GameObject.Destroy(_CopyGuideGO, 0.1f);
|
|||
|
GuideLogic.Instance().HideEffect();
|
|||
|
}
|
|||
|
|
|||
|
_CopyGuideGO = GameObject.Instantiate(_GuideUIGO);
|
|||
|
var scripts = _CopyGuideGO.GetComponentsInChildren<UnityEngine.UI.Button>(true);
|
|||
|
foreach (var script in scripts)
|
|||
|
{
|
|||
|
script.enabled = false;
|
|||
|
}
|
|||
|
_CopyGuideGO.transform.SetParent(GuideLogic.Instance().transform);
|
|||
|
_CopyGuideGO.transform.position = _GuideUIGO.transform.position;
|
|||
|
_CopyGuideGO.transform.localScale = Vector3.one;
|
|||
|
|
|||
|
var rectTrans = _CopyGuideGO.GetComponent<RectTransform>();
|
|||
|
|
|||
|
var clickItem = _CopyGuideGO.AddComponent<GuideStepClickItem>();
|
|||
|
clickItem._IsClickBehind = IsClickBehind;
|
|||
|
clickItem._ClickEvent = OnItemClick;
|
|||
|
if (_GuideUIImagePath.Count > 0)
|
|||
|
{
|
|||
|
for (int i = 0; i < _GuideUIImagePath.Count; ++i)
|
|||
|
{
|
|||
|
var imageGO = _GuideUIGO.transform.Find(_GuideUIImagePath[i]);
|
|||
|
var image = imageGO.GetComponent<Image>();
|
|||
|
if (image != null)
|
|||
|
{
|
|||
|
clickItem._OrgImage.Add(image);
|
|||
|
|
|||
|
var copyImageGO = _CopyGuideGO.transform.Find(_GuideUIImagePath[i]);
|
|||
|
clickItem._SelfImage.Add(copyImageGO.GetComponent<Image>());
|
|||
|
}
|
|||
|
|
|||
|
var text = imageGO.GetComponent<Text>();
|
|||
|
if (text != null)
|
|||
|
{
|
|||
|
clickItem._OrgText.Add(text);
|
|||
|
|
|||
|
var copyImageGO = _CopyGuideGO.transform.Find(_GuideUIImagePath[i]);
|
|||
|
clickItem._SelfText.Add(copyImageGO.GetComponent<Text>());
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if (rectTrans != null)
|
|||
|
{
|
|||
|
var orgRectTrans = _GuideUIGO.GetComponent<RectTransform>();
|
|||
|
rectTrans.sizeDelta = _GuideUIGO.GetComponent<RectTransform>().sizeDelta;
|
|||
|
clickItem._OrgGOTrans = orgRectTrans;
|
|||
|
clickItem._SelfGOTrans = rectTrans;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
protected void FitCopyPos()
|
|||
|
{
|
|||
|
if (_CopyGuideGO == null || _GuideUIGO == null)
|
|||
|
return;
|
|||
|
|
|||
|
if (_CopyGuideGO.transform.position != _GuideUIGO.transform.position)
|
|||
|
{
|
|||
|
_CopyGuideGO.transform.position = _GuideUIGO.transform.position;
|
|||
|
//GuideLogic.Instance()._GuideInfo.position = _GuideUIGO.transform.position + GuideInfoPosOffset;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
if (GuideLogic.Instance()._GuidePos.position != _CopyGuideGO.transform.position)
|
|||
|
{
|
|||
|
GuideLogic.Instance()._GuidePos.position = _CopyGuideGO.transform.position;
|
|||
|
GuideLogic.Instance()._GuidePos.anchoredPosition += new Vector2(GuideInfoPosOffset.x, GuideInfoPosOffset.y);
|
|||
|
|
|||
|
iTween.MoveTo(GuideLogic.Instance()._GuideInfo.gameObject, GuideLogic.Instance()._GuidePos.position, 0.5f);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protected void OnItemClick(object nullItem)
|
|||
|
{
|
|||
|
FinishGuideStep();
|
|||
|
}
|
|||
|
|
|||
|
}
|