using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using System;
|
|
/// <summary>
|
/// 新手引导UI脚本
|
/// </summary>
|
public class GuidePanel : MonoBehaviour
|
{
|
GameObject tipsUI;//显示文字的UI
|
CharForeach charForeach;//动态显示文字
|
|
GuideCtrl m_Ctrl;//控制类
|
|
/// <summary>
|
/// 遮罩对象
|
/// </summary>
|
private RectGuidance maskObj;
|
|
private RectTransform image_Rim_Rect;//边框
|
private RectTransform image_Tip_Rect;//可以移动的提示框
|
private Text text_Tip;//可以移动的提示框文字
|
|
private Image image_SkillRim;//技能释放区域
|
Vector2 rimOffset = new Vector2(30, 30);//边框要比按钮大一些
|
|
|
// Start is called before the first frame update
|
void Awake()
|
{
|
tipsUI = transform.Find("Tips").gameObject;
|
charForeach = tipsUI.GetComponent<CharForeach>();
|
m_Ctrl = transform.GetComponent<GuideCtrl>();
|
transform.Find("Button").GetComponent<Button>().onClick.AddListener(m_Ctrl.OnFinishOneStep);
|
GameObject go = Instantiate(Resources.Load<GameObject>("GuideFile/RectGuidance_Panel"), this.transform);
|
if (go != null)
|
{
|
go.transform.SetSiblingIndex(1);
|
maskObj = go.GetComponent<RectGuidance>();
|
maskObj.gameObject.SetActive(false);
|
}
|
else
|
{
|
Debug.LogError("遮罩生成失败了");
|
}
|
|
image_Rim_Rect = transform.Find("Image_Rim").GetComponent<RectTransform>();
|
image_Tip_Rect = transform.Find("Image_Tip").GetComponent<RectTransform>();
|
text_Tip = image_Tip_Rect.transform.Find("Text").GetComponent<Text>();
|
image_SkillRim = transform.Find("Image_SkillRim").GetComponent<Image>();
|
|
image_Rim_Rect.gameObject.SetActive(false);
|
image_Tip_Rect.gameObject.SetActive(false);
|
image_SkillRim.gameObject.SetActive(false);
|
|
}
|
|
/// <summary>
|
/// 设置引导框
|
/// </summary>
|
/// <param name="active"></param>
|
public void SetGuideUI(bool active)
|
{
|
tipsUI.SetActive(active);
|
}
|
|
//开始打印文字
|
public void StartShowWord(string str, Action cb)
|
{
|
charForeach.StartShowWord(str, cb);
|
}
|
|
/// <summary>
|
/// 立刻完成打印
|
/// </summary>
|
public void ShowWordImmediately()
|
{
|
charForeach.ShowWordImmediately();
|
}
|
|
/// <summary>
|
/// 第二步,购买宝石
|
/// </summary>
|
/// <param name="str"></param>
|
/// <param name="currentIndex">当前第几步</param>
|
public void Step1(string str, int currentIndex, Action ac)
|
{
|
if (currentIndex == 0)
|
{
|
image_Rim_Rect.gameObject.SetActive(true);
|
image_Tip_Rect.gameObject.SetActive(true);
|
//设置位置
|
GameObject go = GameObject.Find("MainUI/TowerBuyBtn");
|
AddButtonListener(go, ac);
|
|
Image btnImg = go.GetComponent<Image>();
|
InitRectGuidance(btnImg);
|
SetRimPos(btnImg);
|
maskObj.ShowImmediately();
|
|
}
|
else if (currentIndex == 1)
|
{
|
|
}
|
text_Tip.text = str;//动态改变长度
|
StartCoroutine(ShowRimTip(str));
|
|
}
|
|
|
public void Step2(int currentIndex)
|
{
|
image_Rim_Rect.gameObject.SetActive(false);
|
image_Tip_Rect.gameObject.SetActive(false);
|
|
CloseMask();
|
}
|
|
#region 按钮以及提示
|
|
/// <summary>
|
/// 设置边框的大小和位置
|
/// </summary>
|
/// <param name="target"></param>
|
private void SetRimPos(Image target)
|
{
|
RectTransform rt = target.GetComponent<RectTransform>();
|
image_Rim_Rect.anchoredPosition = rt.anchoredPosition;
|
image_Rim_Rect.sizeDelta = (rt.sizeDelta * rt.localScale) + rimOffset;
|
image_Tip_Rect.anchoredPosition = new Vector2(image_Rim_Rect.anchoredPosition.x, image_Rim_Rect.anchoredPosition.y + 74 / 2 + image_Rim_Rect.sizeDelta.y / 2);
|
|
}
|
|
IEnumerator ShowRimTip(string str)
|
{
|
yield return 10;
|
SetTipRect(str);//动态修改text长度需要等待计算完成
|
}
|
/// <summary>
|
/// 设置显示文字的长度
|
/// </summary>
|
/// <param name="str"></param>
|
private void SetTipRect(string str)
|
{
|
RectTransform textRect = text_Tip.GetComponent<RectTransform>();
|
image_Tip_Rect.sizeDelta = new Vector2(textRect.sizeDelta.x + 64, image_Tip_Rect.sizeDelta.y);
|
}
|
|
#endregion
|
|
#region 遮罩,以及按钮添加删除事件
|
|
/// <summary>
|
/// 抠出来一个区域
|
/// </summary>
|
/// <param name="target"></param>
|
void InitRectGuidance(Image target)
|
{
|
if (!maskObj.gameObject.activeSelf)
|
{
|
maskObj.gameObject.SetActive(true);
|
}
|
maskObj.Init(target);
|
}
|
|
/// <summary>
|
/// 关闭遮罩
|
/// </summary>
|
public void CloseMask()
|
{
|
maskObj.gameObject.SetActive(false);
|
}
|
|
/// <summary>
|
/// 给按钮添加事件
|
/// </summary>
|
private void AddButtonListener(GameObject go, Action ac)
|
{
|
EventTriggerListener.GetListener(go).onClick += (go1) =>
|
{
|
ac();
|
};
|
}
|
|
/// <summary>
|
/// 移除事件
|
/// </summary>
|
/// <param name="go"></param>
|
private void RemoveButtonListener(GameObject go)
|
{
|
EventTriggerListener.GetListener(go).onClick -= null;
|
|
}
|
|
#endregion
|
|
#region
|
|
#endregion
|
|
#region
|
|
#endregion
|
|
#region
|
|
#endregion
|
|
|
}
|