From aadfae81e6a511cd2c062ab0b05f3ee3419f1a7f Mon Sep 17 00:00:00 2001 From: wangguan <wangguan@kt007.com> Date: Wed, 23 Dec 2020 20:15:14 +0800 Subject: [PATCH] 选中BUFF塔播放相应的特效 --- Assets/Scripts/Guide/GuidePanel.cs | 367 +++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 274 insertions(+), 93 deletions(-) diff --git a/Assets/Scripts/Guide/GuidePanel.cs b/Assets/Scripts/Guide/GuidePanel.cs index b201c07..684560e 100644 --- a/Assets/Scripts/Guide/GuidePanel.cs +++ b/Assets/Scripts/Guide/GuidePanel.cs @@ -25,26 +25,34 @@ private RectTransform image_Tip_Rect;//可以移动的提示框 private Text text_Tip;//可以移动的提示框文字 - private Image image_SkillRim;//技能释放区域 Vector2 rimOffset = new Vector2(30, 30);//边框要比按钮大一些 Image tmpMask;//自身的遮罩 - + GameObject offectBackground;//适配需要的黑色背景 ImageFire1 fire1; + ParticleSystem fire1PS1, fire1PS2;//出现的特效 + ImageFire2 fire2;//两个用来合成的火元素 + ParticleSystem fire2PS1, fire2PS2; - ImageWater water1; + ImageWater wood1; - ImageSkill skill; + ParticleSystem woodPS1, woodPS2; + ImageTowerPos towerPos;//塔位标识 - ImageTowerPos2 towerPos2;//塔位标识 + ImageTowerPos towerPos2;//塔位标识 GameObject towerBuyBtn;//购买宝石按钮 - + Vector2 towerBuyBtnPos; Image backgroundImg;//用来接受空白点击事件的图片 RectTransform dragHandImg;//拖动标识手指 + + Button skillBtn;// + Vector2 skillBtnPos = new Vector2(459, 44.6f); + + private Image warningImg;//大波敌人来袭提示 /// <summary> /// 关闭所有UI /// </summary> @@ -52,18 +60,30 @@ { CloseMask(); SetRimActive(false); - image_SkillRim.gameObject.SetActive(false); } + + private GuideBox boxPanel;//宝箱面板 // Start is called before the first frame update void Awake() { tmpMask = GetComponent<Image>(); tmpMask.enabled = false; + offectBackground = transform.Find("OffectImage").gameObject; + offectBackground.SetActive(false); + backgroundImg = transform.Find("Button").GetComponent<Image>(); - towerBuyBtn = GameObject.Find("BottomCanvas/TowerBuyBtn"); + skillBtn = GameObject.Find("UICamera/BottomCanvas/Panel/Energy/FireSkillBg/SkillBtn").GetComponent<Button>(); + skillBtn.interactable = false; + 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放在最下面 @@ -86,60 +106,78 @@ 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>(); + SetRimActive(false); - image_SkillRim.gameObject.SetActive(false); + fire1 = transform.Find("Image_Fire1").GetComponent<ImageFire1>(); + fire1.GetComponent<RectTransform>().anchoredPosition *= tmpScale; + fire1PS1 = fire1.transform.Find("Huo/Particle System").GetComponent<ParticleSystem>(); + fire1PS2 = fire1.transform.Find("Huo_02/Particle System").GetComponent<ParticleSystem>(); + fire2 = transform.Find("Image_Fire2").GetComponent<ImageFire2>(); + fire2.GetComponent<RectTransform>().anchoredPosition *= tmpScale; + fire2PS1 = fire2.transform.Find("Huo/Particle System").GetComponent<ParticleSystem>(); + fire2PS2 = fire2.transform.Find("Huo_02/Particle System").GetComponent<ParticleSystem>(); 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 = transform.Find("Image_TowerPos2").GetComponent<ImageTowerPos>(); + towerPos2.GetComponent<RectTransform>().anchoredPosition *= tmpScale; + towerPos2.enabled = false; - water1 = transform.Find("Image_Water").GetComponent<ImageWater>(); - water1.gameObject.SetActive(false); + wood1 = transform.Find("Image_Wood").GetComponent<ImageWater>(); + wood1.GetComponent<RectTransform>().anchoredPosition *= tmpScale; + woodPS1 = wood1.transform.Find("Mu/Particle System").GetComponent<ParticleSystem>(); + woodPS2 = wood1.transform.Find("Mu_02/Particle System").GetComponent<ParticleSystem>(); - skill = transform.Find("Image_Skill").GetComponent<ImageSkill>(); - skill.gameObject.SetActive(false); + wood1.gameObject.SetActive(false); dragHandImg = transform.Find("ImageHand").GetComponent<RectTransform>(); dragHandImg.gameObject.SetActive(false); + + warningImg = transform.Find("Image_Warning").GetComponent<Image>(); + warningImg.gameObject.SetActive(false); + + boxPanel = transform.Find("BoxPanel").GetComponent<GuideBox>(); } + + + private Vector2 tmpOffect; /// <summary> - /// 设置引导框 + /// Start is called on the frame when a script is enabled just before + /// any of the Update methods is called the first time. /// </summary> - /// <param name="active"></param> - public void SetGuideUI(bool active) + void Start() { - if (backgroundImg.enabled != active) - backgroundImg.enabled = active; - if (tipsUI.activeSelf != active) - tipsUI.SetActive(active); + tmpOffect = GetComponent<RectTransform>().offsetMin; + tmpOffect = new Vector2(tmpOffect.x, tmpOffect.y * 0.5f); + + fire1.GetComponent<RectTransform>().anchoredPosition -= tmpOffect; + fire2.GetComponent<RectTransform>().anchoredPosition -= tmpOffect; + towerPos.GetComponent<RectTransform>().anchoredPosition -= tmpOffect; + towerPos2.GetComponent<RectTransform>().anchoredPosition -= tmpOffect; + wood1.GetComponent<RectTransform>().anchoredPosition -= tmpOffect; + } - //开始打印文字 - public void StartShowWord(string str, Action cb) - { - charForeach.StartShowWord(str, cb); - } - /// <summary> - /// 立刻完成打印 - /// </summary> - public void ShowWordImmediately() - { - charForeach.ShowWordImmediately(); - } /// <summary> /// 第二步,购买宝石 @@ -148,14 +186,13 @@ /// <param name="currentIndex">当前第几步</param> public void Step1(string str, int currentIndex, Action ac) { - if (currentIndex == 0) { backgroundImg.raycastTarget = false; SetRimActive(true); AddButtonListener(towerBuyBtn, ac); Image btnImg = towerBuyBtn.GetComponent<Image>(); - InitRectGuidance(btnImg, 189, 73.5f); + InitRectGuidance(btnImg, 159, 73.5f, Vector2.one); SetRimPos(towerBuyBtn); //maskObj.ShowImmediately(); @@ -167,7 +204,6 @@ } text_Tip.text = str;//动态改变长度 StartCoroutine(ShowRimTip(str)); - } public void Step1_1() @@ -177,18 +213,22 @@ fire1.gameObject.SetActive(true); fire1.transform.Find("Image_2").gameObject.SetActive(false); fire1.enabled = false; + fire1PS1.Play(); + fire1PS2.Play(); - EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.PlayAppearEffect, fire1.transform.position); + //EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.PlayAppearEffect, fire1.transform.position); } } public void Step1_2() { fire2.gameObject.SetActive(true); + fire2PS1.Play(); + fire2PS2.Play(); fire2.enabled = false; DestoryButtonListener(towerBuyBtn); SetRimActive(false); CloseMask(); - EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.PlayAppearEffect, fire2.transform.position); + //EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.PlayAppearEffect, fire2.transform.position); //RemoveButtonListener(towerBuyBtn); } @@ -212,6 +252,7 @@ { tmpMask.enabled = true; + offectBackground.SetActive(true); SetGuideUI(false); @@ -219,7 +260,7 @@ fire1.enabled = true; fire2.enabled = true; image_Tip_Rect.gameObject.SetActive(false); - ShowDragPath(fire2.GetStartP, fire1.GetRect); + //ShowDragPath(fire2.GetStartP, fire1.GetRect); StartCoroutine(ShowRimTip(str)); } } @@ -239,11 +280,12 @@ if (currentIndex == 0) { tmpMask.enabled = false; + offectBackground.SetActive(false); SetRimActive(true); Image btnImg = transform.Find("Image_TowerPos").GetComponent<Image>(); towerPos.enabled = true; - InitRectGuidance(btnImg, 75, 80); + InitRectGuidance(btnImg, 75, 80, tmpOffect); SetRimPos(btnImg.gameObject); //maskObj.ShowImmediately(); ShowDragPath(fire1.GetStartP, btnImg.rectTransform); @@ -278,7 +320,7 @@ Image btnImg = go.GetComponent<Image>(); btnImg.raycastTarget = false; - InitRectGuidance(btnImg, 75, 80); + InitRectGuidance(btnImg, 75, 80, tmpOffect); SetRimPos(go); //maskObj.ShowImmediately(); StartCoroutine(ShowRimTip(str)); @@ -295,7 +337,7 @@ /// <summary> - /// 第九步, + /// 第九步,购买水元素,第二步上阵 /// </summary> /// <param name="str"></param> /// <param name="currentIndex">当前第几步</param> @@ -303,93 +345,172 @@ { if (currentIndex == 0) { - SetRimActive(true); - image_Tip_Rect.gameObject.SetActive(false); //设置位置 AddButtonListener(towerBuyBtn, ac); - Image btnImg = towerBuyBtn.GetComponent<Image>(); - InitRectGuidance(btnImg, 189, 73.5f); + InitRectGuidance(btnImg, 159, 73.5f, Vector2.one); SetRimPos(towerBuyBtn); - //maskObj.ShowImmediately(); } else if (currentIndex == 1) { GameObject go = transform.Find("Image_TowerPos2").gameObject; Image btnImg = go.GetComponent<Image>(); btnImg.raycastTarget = true; - InitRectGuidance(btnImg, 75, 80); + InitRectGuidance(btnImg, 75, 80, tmpOffect); SetRimPos(go); - //maskObj.ShowImmediately(); - ShowDragPath(water1.GetStartP, btnImg.rectTransform); + ShowDragPath(wood1.GetStartP, btnImg.rectTransform); } - - //StartCoroutine(ShowRimTip(str)); } public void Step9_1() { - water1.gameObject.SetActive(true); + wood1.gameObject.SetActive(true); + woodPS1.Play(); + woodPS2.Play(); towerPos2.enabled = true; DestoryButtonListener(towerBuyBtn); + towerBuyBtn.gameObject.SetActive(false); } - - //生成一个技能宝石 - public void Step10() - { - //SetGuideUI(false); - - image_SkillRim.gameObject.SetActive(true); - - skill.gameObject.SetActive(true); - } /// <summary> - /// 第12步,引导释放技能 + /// 第12步,交换水火塔 /// </summary> - public void Step11(int currentIndex, string str) + public void Step11Drag(int currentIndex) { if (currentIndex == 0) { - tmpMask.enabled = true; - tmpMask.color = new Color(1.0f, 1.0f, 1.0f, 0); - SetGuideUI(false); + GameConfig.CanDragTower = true; + //标记水塔 引导拖动 + towerPos.GetComponent<Image>().raycastTarget = false; + towerPos2.GetComponent<Image>().raycastTarget = false; + backgroundImg.raycastTarget = false; SetRimActive(true); - SetRimPos(skill.gameObject); - image_Tip_Rect.gameObject.SetActive(false); - //StartCoroutine(ShowRimTip(str)); + SetGuideUI(false); + Image btnImg = towerPos2.GetComponent<Image>(); + btnImg.raycastTarget = false; - ShowDragPath(skill.GetStartP, image_SkillRim.rectTransform); - - InitRectGuidance(image_SkillRim, 79, 265); + InitRectGuidance(btnImg, 75, 80, tmpOffect); + //SetRimPos(towerPos2.gameObject); + SetRimPos(towerPos2.gameObject, new Vector2(0, 30)); + StartCoroutine(ShowRimTip("交换")); + ShowDragPath(towerPos2.GetComponent<RectTransform>().anchoredPosition, towerPos.GetComponent<RectTransform>()); } else if (currentIndex == 1) { + Image btnImg = towerPos.GetComponent<Image>(); + btnImg.raycastTarget = false; + + InitRectGuidance(btnImg, 75, 80, tmpOffect); + //SetRimPos(towerPos.gameObject); + SetRimPos(towerPos.gameObject, new Vector2(0, 10)); + + StartCoroutine(ShowRimTip("交换")); + + } + else if (currentIndex == 2) + { SetRimActive(false); - //SetRimPos(image_SkillRim.gameObject); - //StartCoroutine(ShowRimTip(str)); + StopShowDragPath(true); + CloseMask(); } } - public void SkillRelease() + /// <summary> + /// 一大波敌人 + /// </summary> + public void Step11_End() { - StopShowDragPath(true); - CloseMask(); - image_SkillRim.gameObject.SetActive(false); - tmpMask.enabled = false; - SetRimActive(false); + warningImg.color = new Color(1.0f, 1.0f, 1.0f, 0); + warningImg.gameObject.SetActive(true); + colorCount = 0; + SetWarningColor(); + } + + int colorCount = 0; + private void SetWarningColor() + { + if (colorCount < 4) + { + colorCount++; + warningImg.DOFade(colorCount % 2, 1.0f).OnComplete(SetWarningColor); + CommonDebugHelper.Debug($"执行了{colorCount}次"); + } + else + { + EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.CreateThirdWave); + warningImg.gameObject.SetActive(false); + } } public void Step12() { - - SetGuideUI(true); + backgroundImg.raycastTarget = true; } + + public void Step13(string str, Action ac) + { + skillBtn.interactable = true; + + EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.GuideEnergyUp, 100); + + SetGuideUI(false); + + backgroundImg.raycastTarget = false; + SetRimActive(true); + AddButtonListener(skillBtn.gameObject, ac); + Image btnImg = skillBtn.GetComponent<Image>(); + InitRectGuidance(btnImg, 79, 79f, Vector2.one); + //SetRimPos(skillBtn.gameObject); + SetRimPos(skillBtn.gameObject, new Vector2(-15, -241)); + + text_Tip.text = str;//动态改变长度 + StartCoroutine(ShowRimTip(str)); + } + + public void Step14() + { + SetGuideUI(true); + backgroundImg.raycastTarget = true; + RemoveButtonListener(skillBtn.gameObject); + } + + public void FinishGuide() + { + towerBuyBtn.gameObject.SetActive(true); + } + + #region 设置对话框 + /// <summary> + /// 设置引导框 + /// </summary> + /// <param name="active"></param> + public void SetGuideUI(bool active) + { + if (backgroundImg.enabled != active) + backgroundImg.enabled = active; + if (tipsUI.activeSelf != active) + tipsUI.SetActive(active); + } + + //开始打印文字 + public void StartShowWord(string str, Action cb) + { + charForeach.StartShowWord(str, cb); + } + + /// <summary> + /// 立刻完成打印 + /// </summary> + public void ShowWordImmediately() + { + charForeach.ShowWordImmediately(); + } + #endregion #region 按钮以及提示 @@ -410,7 +531,18 @@ { SetRimActive(true); RectTransform rt = target.GetComponent<RectTransform>(); - image_Rim_Rect.anchoredPosition = rt.anchoredPosition; + if (target.gameObject.name == "TowerBuyBtn") + { + image_Rim_Rect.anchoredPosition = towerBuyBtnPos - tmpOffect; + } + else if (target.gameObject.name == "SkillBtn") + { + image_Rim_Rect.anchoredPosition = skillBtnPos - tmpOffect; + } + else + { + image_Rim_Rect.anchoredPosition = rt.anchoredPosition; + } image_Rim_Rect.sizeDelta = (rt.sizeDelta * rt.localScale) + rimOffset; if (image_Rim_Rect.sizeDelta.x > 200) { @@ -424,8 +556,45 @@ } 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); + } + } + + /// <summary> + /// 设置边框的大小和位置 + /// </summary> + /// <param name="target"></param> + private void SetRimPos(GameObject target, Vector2 offect) + { + SetRimActive(true); + RectTransform rt = target.GetComponent<RectTransform>(); + if (target.gameObject.name == "TowerBuyBtn") + { + image_Rim_Rect.anchoredPosition = towerBuyBtnPos - tmpOffect; + } + else if (target.gameObject.name == "SkillBtn") + { + image_Rim_Rect.anchoredPosition = skillBtnPos - tmpOffect; + } + else + { + image_Rim_Rect.anchoredPosition = rt.anchoredPosition; + } + 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); + } + image_Tip_Rect.anchoredPosition = new Vector2(image_Rim_Rect.anchoredPosition.x, image_Rim_Rect.anchoredPosition.y + 74 / 2 + image_Rim_Rect.sizeDelta.y / 2); + image_Tip_Rect.anchoredPosition += offect; } IEnumerator ShowRimTip(string str) @@ -447,23 +616,29 @@ #endregion #region 遮罩,以及按钮添加删除事件 - - - /// <summary> /// 抠出来一个区域 /// </summary> /// <param name="target"></param> - void InitRectGuidance(Image target, float x, float y) + void InitRectGuidance(Image target, float x, float y, Vector2 offect) { if (!maskObj.gameObject.activeSelf) { maskObj.gameObject.SetActive(true); } - //maskObj.Init(target); - //maskObj.ShowImmediately(); - maskObj.InitForCamera(target, x, y); + if (target.gameObject.name == "TowerBuyBtn") + { + maskObj.InitForCamera(target, towerBuyBtnPos, x, y); + } + else if (target.gameObject.name == "SkillBtn") + { + maskObj.InitForCamera(target, skillBtnPos, x, y); + } + else + { + maskObj.InitForCamera(target, x, y, offect); + } } /// <summary> @@ -528,4 +703,10 @@ #endregion + + public void OpenDialogBox(){ + + } + + } -- Gitblit v1.9.1