From 69e0fea6c92fd4e153d45e5f26ef89baecf0405a Mon Sep 17 00:00:00 2001 From: weixudong <weixudong4700@ktgame.com> Date: Thu, 19 Nov 2020 08:51:09 +0800 Subject: [PATCH] Merge branch 'master' of ssh://172.16.1.52:8091/GemBattle into master --- Assets/Scripts/Guide/GuidePanel.cs | 197 ++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 160 insertions(+), 37 deletions(-) diff --git a/Assets/Scripts/Guide/GuidePanel.cs b/Assets/Scripts/Guide/GuidePanel.cs index d5b1744..81be6d7 100644 --- a/Assets/Scripts/Guide/GuidePanel.cs +++ b/Assets/Scripts/Guide/GuidePanel.cs @@ -3,7 +3,8 @@ using UnityEngine; using UnityEngine.UI; using System; - +using KTGMGemClient; +using DG.Tweening; /// <summary> /// 新手引导UI脚本 /// </summary> @@ -20,6 +21,7 @@ private RectGuidance maskObj; private RectTransform image_Rim_Rect;//边框 + private GameObject particle_1, particle_2;//使用粒子特效 private RectTransform image_Tip_Rect;//可以移动的提示框 private Text text_Tip;//可以移动的提示框文字 @@ -27,7 +29,7 @@ Vector2 rimOffset = new Vector2(30, 30);//边框要比按钮大一些 Image tmpMask;//自身的遮罩 - + GameObject offectBackground;//适配需要的黑色背景 ImageFire1 fire1; ImageFire2 fire2;//两个用来合成的火元素 @@ -39,9 +41,10 @@ ImageTowerPos2 towerPos2;//塔位标识 GameObject towerBuyBtn;//购买宝石按钮 - + Vector2 towerBuyBtnPos; Image backgroundImg;//用来接受空白点击事件的图片 + RectTransform dragHandImg;//拖动标识手指 /// <summary> /// 关闭所有UI /// </summary> @@ -57,9 +60,19 @@ void Awake() { tmpMask = GetComponent<Image>(); + tmpMask.enabled = false; + offectBackground = transform.Find("OffectImage").gameObject; + offectBackground.SetActive(false); + backgroundImg = transform.Find("Button").GetComponent<Image>(); - backgroundImg.color = new Color(1.0f, 1.0f, 1.0f, 0); - towerBuyBtn = GameObject.Find("MainUI/TowerBuyBtn"); + + towerBuyBtn = GameObject.Find("UICamera/BottomCanvas/Panel/TowerBuyBtn"); + RectTransform tmpTs = towerBuyBtn.GetComponent<RectTransform>(); + + RectTransform canvasUI = transform.parent.parent.GetComponent<RectTransform>(); + float tmpOffect = tmpTs.anchoredPosition.y - (canvasUI.sizeDelta.y * 0.5f); + towerBuyBtnPos = new Vector2(tmpTs.anchoredPosition.x, tmpOffect); + tipsUI = transform.Find("Tips").gameObject; tipsUI.transform.SetAsLastSibling();//把tips放在最下面 @@ -79,30 +92,51 @@ } image_Rim_Rect = transform.Find("Image_Rim").GetComponent<RectTransform>(); + particle_1 = image_Rim_Rect.transform.Find("Particle System Small").gameObject; + particle_2 = image_Rim_Rect.transform.Find("Particle System Big").gameObject; + + float a = 0.06666667f; + float b = canvasUI.localScale.x; + float tmpScale = a / b; + //Debug.Log($"记录的比值:{a} 当前Canvas的Scale:{b} 计算得到的比值:{tmpScale}"); + 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_SkillRim.GetComponent<RectTransform>().anchoredPosition *= tmpScale; SetRimActive(false); image_SkillRim.gameObject.SetActive(false); fire1 = transform.Find("Image_Fire1").GetComponent<ImageFire1>(); + fire1.GetComponent<RectTransform>().anchoredPosition *= tmpScale; fire2 = transform.Find("Image_Fire2").GetComponent<ImageFire2>(); + fire2.GetComponent<RectTransform>().anchoredPosition *= tmpScale; fire1.gameObject.SetActive(false); fire2.gameObject.SetActive(false); towerPos = transform.Find("Image_TowerPos").GetComponent<ImageTowerPos>(); + towerPos.GetComponent<RectTransform>().anchoredPosition *= tmpScale; + towerPos.enabled = false; towerPos2 = transform.Find("Image_TowerPos2").GetComponent<ImageTowerPos2>(); + towerPos2.GetComponent<RectTransform>().anchoredPosition *= tmpScale; + towerPos2.enabled = false; water1 = transform.Find("Image_Water").GetComponent<ImageWater>(); + water1.GetComponent<RectTransform>().anchoredPosition *= tmpScale; water1.gameObject.SetActive(false); skill = transform.Find("Image_Skill").GetComponent<ImageSkill>(); + skill.GetComponent<RectTransform>().anchoredPosition *= tmpScale; + skill.gameObject.SetActive(false); + + dragHandImg = transform.Find("ImageHand").GetComponent<RectTransform>(); + dragHandImg.gameObject.SetActive(false); } /// <summary> @@ -111,8 +145,10 @@ /// <param name="active"></param> public void SetGuideUI(bool active) { - if (backgroundImg.raycastTarget != active) backgroundImg.raycastTarget = active; - tipsUI.SetActive(active); + if (backgroundImg.enabled != active) + backgroundImg.enabled = active; + if (tipsUI.activeSelf != active) + tipsUI.SetActive(active); } //开始打印文字 @@ -143,9 +179,9 @@ SetRimActive(true); AddButtonListener(towerBuyBtn, ac); Image btnImg = towerBuyBtn.GetComponent<Image>(); - InitRectGuidance(btnImg); + InitRectGuidance(btnImg, 159, 73.5f); SetRimPos(towerBuyBtn); - maskObj.ShowImmediately(); + //maskObj.ShowImmediately(); } else if (currentIndex == 1) @@ -165,12 +201,20 @@ fire1.gameObject.SetActive(true); fire1.transform.Find("Image_2").gameObject.SetActive(false); fire1.enabled = false; + + EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.PlayAppearEffect, fire1.transform.position); } } public void Step1_2() { fire2.gameObject.SetActive(true); fire2.enabled = false; + DestoryButtonListener(towerBuyBtn); + SetRimActive(false); + CloseMask(); + EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.PlayAppearEffect, fire2.transform.position); + + //RemoveButtonListener(towerBuyBtn); } /// <summary> @@ -180,11 +224,7 @@ public void Step2(int currentIndex) { backgroundImg.raycastTarget = true; - - RemoveButtonListener(towerBuyBtn); - - SetRimActive(false); - CloseMask(); + //RemoveButtonListener(towerBuyBtn); } /// <summary> @@ -194,13 +234,17 @@ { if (currentIndex == 0) { - backgroundImg.raycastTarget = false; - backgroundImg.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); + + tmpMask.enabled = true; + offectBackground.SetActive(true); + SetGuideUI(false); SetRimPos(fire2.gameObject); fire1.enabled = true; fire2.enabled = true; + image_Tip_Rect.gameObject.SetActive(false); + ShowDragPath(fire2.GetStartP, fire1.GetRect); StartCoroutine(ShowRimTip(str)); } } @@ -209,7 +253,7 @@ public void Step3_2(string str) { SetRimPos(fire1.gameObject); - StartCoroutine(ShowRimTip(str)); + //StartCoroutine(ShowRimTip(str)); } /// <summary> @@ -219,18 +263,23 @@ { if (currentIndex == 0) { + tmpMask.enabled = false; + offectBackground.SetActive(false); + SetRimActive(true); Image btnImg = transform.Find("Image_TowerPos").GetComponent<Image>(); towerPos.enabled = true; - InitRectGuidance(btnImg); + InitRectGuidance(btnImg, 75, 80); SetRimPos(btnImg.gameObject); - maskObj.ShowImmediately(); + //maskObj.ShowImmediately(); + ShowDragPath(fire1.GetStartP, btnImg.rectTransform); StartCoroutine(ShowRimTip(str)); + } } /// <summary> - /// 第六步,拖动造塔 + /// 第六步 /// </summary> public void Step5(int currentIndex, string str) { @@ -238,7 +287,7 @@ { CloseMask(); SetRimActive(false); - backgroundImg.color = new Color(1.0f, 1.0f, 1.0f, 0); + } } @@ -254,9 +303,10 @@ GameObject go = transform.Find("Image_TowerPos2").gameObject; Image btnImg = go.GetComponent<Image>(); - InitRectGuidance(btnImg); + btnImg.raycastTarget = false; + InitRectGuidance(btnImg, 75, 80); SetRimPos(go); - maskObj.ShowImmediately(); + //maskObj.ShowImmediately(); StartCoroutine(ShowRimTip(str)); } } @@ -264,7 +314,6 @@ //介绍水元素 public void Step8() { - backgroundImg.color = new Color(1.0f, 1.0f, 1.0f, 0); SetGuideUI(true); SetRimActive(false); CloseMask(); @@ -280,32 +329,37 @@ { if (currentIndex == 0) { + SetRimActive(true); + + image_Tip_Rect.gameObject.SetActive(false); //设置位置 AddButtonListener(towerBuyBtn, ac); Image btnImg = towerBuyBtn.GetComponent<Image>(); - InitRectGuidance(btnImg); + InitRectGuidance(btnImg, 159, 73.5f); SetRimPos(towerBuyBtn); - maskObj.ShowImmediately(); + //maskObj.ShowImmediately(); } else if (currentIndex == 1) { GameObject go = transform.Find("Image_TowerPos2").gameObject; Image btnImg = go.GetComponent<Image>(); - InitRectGuidance(btnImg); + btnImg.raycastTarget = true; + InitRectGuidance(btnImg, 75, 80); SetRimPos(go); - maskObj.ShowImmediately(); + //maskObj.ShowImmediately(); + ShowDragPath(water1.GetStartP, btnImg.rectTransform); } - StartCoroutine(ShowRimTip(str)); + //StartCoroutine(ShowRimTip(str)); } public void Step9_1() { - RemoveButtonListener(towerBuyBtn); water1.gameObject.SetActive(true); towerPos2.enabled = true; + DestoryButtonListener(towerBuyBtn); } @@ -326,25 +380,41 @@ { if (currentIndex == 0) { + tmpMask.enabled = true; + tmpMask.color = new Color(1.0f, 1.0f, 1.0f, 0); SetGuideUI(false); SetRimActive(true); SetRimPos(skill.gameObject); - StartCoroutine(ShowRimTip(str)); + image_Tip_Rect.gameObject.SetActive(false); + //StartCoroutine(ShowRimTip(str)); + + ShowDragPath(skill.GetStartP, image_SkillRim.rectTransform); + + InitRectGuidance(image_SkillRim, 79, 265); + } else if (currentIndex == 1) { - SetRimPos(image_SkillRim.gameObject); - StartCoroutine(ShowRimTip(str)); + SetRimActive(false); + //SetRimPos(image_SkillRim.gameObject); + //StartCoroutine(ShowRimTip(str)); } } + public void SkillRelease() + { + StopShowDragPath(true); + CloseMask(); + image_SkillRim.gameObject.SetActive(false); + tmpMask.enabled = false; + SetRimActive(false); + } public void Step12() { - image_SkillRim.gameObject.SetActive(false); + SetGuideUI(true); - SetRimActive(false); } #region 按钮以及提示 @@ -367,7 +437,22 @@ SetRimActive(true); RectTransform rt = target.GetComponent<RectTransform>(); image_Rim_Rect.anchoredPosition = rt.anchoredPosition; + if (target.gameObject.name == "TowerBuyBtn") + { + image_Rim_Rect.anchoredPosition = towerBuyBtnPos; + } image_Rim_Rect.sizeDelta = (rt.sizeDelta * rt.localScale) + rimOffset; + if (image_Rim_Rect.sizeDelta.x > 200) + { + particle_1.SetActive(false); + particle_2.SetActive(true); + } + else + { + particle_1.SetActive(true); + particle_2.SetActive(false); + } + 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); @@ -399,13 +484,23 @@ /// 抠出来一个区域 /// </summary> /// <param name="target"></param> - void InitRectGuidance(Image target) + void InitRectGuidance(Image target, float x, float y) { if (!maskObj.gameObject.activeSelf) { maskObj.gameObject.SetActive(true); } - maskObj.Init(target); + //maskObj.Init(target); + //maskObj.ShowImmediately(); + if (target.gameObject.name == "TowerBuyBtn") + { + maskObj.InitForCamera(target, towerBuyBtnPos, x, y); + } + else + { + maskObj.InitForCamera(target, x, y); + } + } /// <summary> @@ -439,7 +534,35 @@ eventTriggerListener.RemoveListener(go); } + private void DestoryButtonListener(GameObject go) + { + EventTriggerListener eventTriggerListener = EventTriggerListener.GetListener(go); + + if (eventTriggerListener != null) + Destroy(eventTriggerListener); + } + #endregion + #region 拖动效果 + private void ShowDragPath(Vector2 startP, RectTransform endP) + { + if (!dragHandImg.gameObject.activeSelf) + { + dragHandImg.gameObject.SetActive(true); + dragHandImg.anchoredPosition = startP; + dragHandImg.DOMove(endP.position, 1).SetEase(Ease.InCubic).SetLoops(-1); + } + } + + public void StopShowDragPath(bool isClose) + { + dragHandImg.DOKill(); + if (isClose) + dragHandImg.gameObject.SetActive(false); + } + + + #endregion } -- Gitblit v1.9.1