From 439510ca0d2da7fa0af0496d4a05096841f01f8f Mon Sep 17 00:00:00 2001 From: wangguan <wangguan@kt007.com> Date: Mon, 26 Oct 2020 14:20:42 +0800 Subject: [PATCH] 新手引导2.0 --- Assets/Scripts/Guide/GuidePanel.cs | 288 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 260 insertions(+), 28 deletions(-) diff --git a/Assets/Scripts/Guide/GuidePanel.cs b/Assets/Scripts/Guide/GuidePanel.cs index e63cda4..d5b1744 100644 --- a/Assets/Scripts/Guide/GuidePanel.cs +++ b/Assets/Scripts/Guide/GuidePanel.cs @@ -26,11 +26,43 @@ private Image image_SkillRim;//技能释放区域 Vector2 rimOffset = new Vector2(30, 30);//边框要比按钮大一些 + Image tmpMask;//自身的遮罩 + + ImageFire1 fire1; + ImageFire2 fire2;//两个用来合成的火元素 + + ImageWater water1; + + ImageSkill skill; + + ImageTowerPos towerPos;//塔位标识 + ImageTowerPos2 towerPos2;//塔位标识 + + GameObject towerBuyBtn;//购买宝石按钮 + + Image backgroundImg;//用来接受空白点击事件的图片 + + /// <summary> + /// 关闭所有UI + /// </summary> + public void CleanMask() + { + CloseMask(); + SetRimActive(false); + image_SkillRim.gameObject.SetActive(false); + + } // Start is called before the first frame update void Awake() { + tmpMask = GetComponent<Image>(); + backgroundImg = transform.Find("Button").GetComponent<Image>(); + backgroundImg.color = new Color(1.0f, 1.0f, 1.0f, 0); + towerBuyBtn = GameObject.Find("MainUI/TowerBuyBtn"); tipsUI = transform.Find("Tips").gameObject; + tipsUI.transform.SetAsLastSibling();//把tips放在最下面 + charForeach = tipsUI.GetComponent<CharForeach>(); m_Ctrl = transform.GetComponent<GuideCtrl>(); transform.Find("Button").GetComponent<Button>().onClick.AddListener(m_Ctrl.OnFinishOneStep); @@ -51,10 +83,26 @@ 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); + SetRimActive(false); image_SkillRim.gameObject.SetActive(false); + fire1 = transform.Find("Image_Fire1").GetComponent<ImageFire1>(); + fire2 = transform.Find("Image_Fire2").GetComponent<ImageFire2>(); + + fire1.gameObject.SetActive(false); + fire2.gameObject.SetActive(false); + + towerPos = transform.Find("Image_TowerPos").GetComponent<ImageTowerPos>(); + towerPos.enabled = false; + + towerPos2 = transform.Find("Image_TowerPos2").GetComponent<ImageTowerPos2>(); + towerPos2.enabled = false; + + water1 = transform.Find("Image_Water").GetComponent<ImageWater>(); + water1.gameObject.SetActive(false); + + skill = transform.Find("Image_Skill").GetComponent<ImageSkill>(); + skill.gameObject.SetActive(false); } /// <summary> @@ -63,6 +111,7 @@ /// <param name="active"></param> public void SetGuideUI(bool active) { + if (backgroundImg.raycastTarget != active) backgroundImg.raycastTarget = active; tipsUI.SetActive(active); } @@ -87,55 +136,246 @@ /// <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>(); + backgroundImg.raycastTarget = false; + SetRimActive(true); + AddButtonListener(towerBuyBtn, ac); + Image btnImg = towerBuyBtn.GetComponent<Image>(); InitRectGuidance(btnImg); - SetRimPos(btnImg); + SetRimPos(towerBuyBtn); maskObj.ShowImmediately(); } else if (currentIndex == 1) { - + RemoveButtonListener(towerBuyBtn); + AddButtonListener(towerBuyBtn, ac); } text_Tip.text = str;//动态改变长度 StartCoroutine(ShowRimTip(str)); } + public void Step1_1() + { + if (!fire1.gameObject.activeSelf) + { + fire1.gameObject.SetActive(true); + fire1.transform.Find("Image_2").gameObject.SetActive(false); + fire1.enabled = false; + } + } + public void Step1_2() + { + fire2.gameObject.SetActive(true); + fire2.enabled = false; + } + /// <summary> + /// 第三步,关闭其余遮罩,打开大Tips + /// </summary> + /// <param name="currentIndex"></param> public void Step2(int currentIndex) { - image_Rim_Rect.gameObject.SetActive(false); - image_Tip_Rect.gameObject.SetActive(false); + backgroundImg.raycastTarget = true; + RemoveButtonListener(towerBuyBtn); + + SetRimActive(false); CloseMask(); + } + + /// <summary> + /// 第四步,合成宝石 + /// </summary> + public void Step3(int currentIndex, string str) + { + if (currentIndex == 0) + { + backgroundImg.raycastTarget = false; + backgroundImg.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); + SetGuideUI(false); + + SetRimPos(fire2.gameObject); + fire1.enabled = true; + fire2.enabled = true; + StartCoroutine(ShowRimTip(str)); + } + } + + //移动方框,提示玩家进行合成 + public void Step3_2(string str) + { + SetRimPos(fire1.gameObject); + StartCoroutine(ShowRimTip(str)); + } + + /// <summary> + /// 第五步,拖动造塔 + /// </summary> + public void Step4(int currentIndex, string str) + { + if (currentIndex == 0) + { + SetRimActive(true); + Image btnImg = transform.Find("Image_TowerPos").GetComponent<Image>(); + towerPos.enabled = true; + InitRectGuidance(btnImg); + SetRimPos(btnImg.gameObject); + maskObj.ShowImmediately(); + StartCoroutine(ShowRimTip(str)); + } + } + + /// <summary> + /// 第六步,拖动造塔 + /// </summary> + public void Step5(int currentIndex, string str) + { + if (currentIndex == -1) + { + CloseMask(); + SetRimActive(false); + backgroundImg.color = new Color(1.0f, 1.0f, 1.0f, 0); + } + } + + /// <summary> + /// 第七步,解锁新塔位 + /// </summary> + public void Step7(int currentIndex, string str) + { + if (currentIndex == 0) + { + SetRimActive(true); + //设置位置 + GameObject go = transform.Find("Image_TowerPos2").gameObject; + + Image btnImg = go.GetComponent<Image>(); + InitRectGuidance(btnImg); + SetRimPos(go); + maskObj.ShowImmediately(); + StartCoroutine(ShowRimTip(str)); + } + } + + //介绍水元素 + public void Step8() + { + backgroundImg.color = new Color(1.0f, 1.0f, 1.0f, 0); + SetGuideUI(true); + SetRimActive(false); + CloseMask(); + } + + + /// <summary> + /// 第九步, + /// </summary> + /// <param name="str"></param> + /// <param name="currentIndex">当前第几步</param> + public void Step9(string str, int currentIndex, Action ac) + { + if (currentIndex == 0) + { + SetRimActive(true); + //设置位置 + AddButtonListener(towerBuyBtn, ac); + + Image btnImg = towerBuyBtn.GetComponent<Image>(); + InitRectGuidance(btnImg); + SetRimPos(towerBuyBtn); + maskObj.ShowImmediately(); + } + else if (currentIndex == 1) + { + GameObject go = transform.Find("Image_TowerPos2").gameObject; + Image btnImg = go.GetComponent<Image>(); + InitRectGuidance(btnImg); + SetRimPos(go); + maskObj.ShowImmediately(); + } + + StartCoroutine(ShowRimTip(str)); + } + + public void Step9_1() + { + RemoveButtonListener(towerBuyBtn); + water1.gameObject.SetActive(true); + towerPos2.enabled = true; + } + + + //生成一个技能宝石 + public void Step10() + { + //SetGuideUI(false); + + image_SkillRim.gameObject.SetActive(true); + + skill.gameObject.SetActive(true); + } + + /// <summary> + /// 第12步,引导释放技能 + /// </summary> + public void Step11(int currentIndex, string str) + { + if (currentIndex == 0) + { + SetGuideUI(false); + SetRimActive(true); + SetRimPos(skill.gameObject); + StartCoroutine(ShowRimTip(str)); + } + else if (currentIndex == 1) + { + SetRimPos(image_SkillRim.gameObject); + StartCoroutine(ShowRimTip(str)); + } + } + + + public void Step12() + { + image_SkillRim.gameObject.SetActive(false); + + SetGuideUI(true); + SetRimActive(false); } #region 按钮以及提示 + + public void SetRimActive(bool isOn) + { + if (image_Rim_Rect.gameObject.activeSelf != isOn) + { + image_Rim_Rect.gameObject.SetActive(isOn); + image_Tip_Rect.gameObject.SetActive(isOn); + } + } /// <summary> /// 设置边框的大小和位置 /// </summary> /// <param name="target"></param> - private void SetRimPos(Image target) + private void SetRimPos(GameObject target, bool changeTipPos = true) { + SetRimActive(true); 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); + if (changeTipPos) + 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) { + text_Tip.text = str;//动态改变长度 yield return 10; SetTipRect(str);//动态修改text长度需要等待计算完成 } @@ -152,6 +392,8 @@ #endregion #region 遮罩,以及按钮添加删除事件 + + /// <summary> /// 抠出来一个区域 @@ -183,6 +425,7 @@ { ac(); }; + } /// <summary> @@ -191,21 +434,10 @@ /// <param name="go"></param> private void RemoveButtonListener(GameObject go) { - EventTriggerListener.GetListener(go).onClick -= null; + EventTriggerListener eventTriggerListener = EventTriggerListener.GetListener(go); + eventTriggerListener.RemoveListener(go); } - - #endregion - - #region - - #endregion - - #region - - #endregion - - #region #endregion -- Gitblit v1.9.1