From e70a047e1d3a3b476212d49714264cf6871cd9fc Mon Sep 17 00:00:00 2001
From: wangguan <wangguan@kt007.com>
Date: Mon, 23 Nov 2020 16:22:04 +0800
Subject: [PATCH] 修改表格

---
 Assets/Scripts/Guide/GuidePanel.cs |   88 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 76 insertions(+), 12 deletions(-)

diff --git a/Assets/Scripts/Guide/GuidePanel.cs b/Assets/Scripts/Guide/GuidePanel.cs
index b201c07..1a2f525 100644
--- a/Assets/Scripts/Guide/GuidePanel.cs
+++ b/Assets/Scripts/Guide/GuidePanel.cs
@@ -29,7 +29,7 @@
     Vector2 rimOffset = new Vector2(30, 30);//边框要比按钮大一些
 
     Image tmpMask;//自身的遮罩
-
+    GameObject offectBackground;//适配需要的黑色背景
     ImageFire1 fire1;
     ImageFire2 fire2;//两个用来合成的火元素
 
@@ -41,7 +41,7 @@
     ImageTowerPos2 towerPos2;//塔位标识
 
     GameObject towerBuyBtn;//购买宝石按钮
-
+    Vector2 towerBuyBtnPos;
     Image backgroundImg;//用来接受空白点击事件的图片
 
     RectTransform dragHandImg;//拖动标识手指
@@ -61,9 +61,18 @@
     {
         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");
+        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,35 +95,71 @@
         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);
     }
 
+
+    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>
+    void Start()
+    {
+        tmpOffect = GetComponent<RectTransform>().offsetMin;
+        tmpOffect = new Vector2(tmpOffect.x, tmpOffect.y * 0.5f);
+
+        image_SkillRim.GetComponent<RectTransform>().anchoredPosition -= tmpOffect;
+        fire1.GetComponent<RectTransform>().anchoredPosition -= tmpOffect;
+        fire2.GetComponent<RectTransform>().anchoredPosition -= tmpOffect;
+        towerPos.GetComponent<RectTransform>().anchoredPosition -= tmpOffect;
+        towerPos2.GetComponent<RectTransform>().anchoredPosition -= tmpOffect;
+        water1.GetComponent<RectTransform>().anchoredPosition -= tmpOffect;
+        skill.GetComponent<RectTransform>().anchoredPosition -= tmpOffect;
+
+    }
     /// <summary>
     /// 设置引导框
     /// </summary>
@@ -155,7 +200,7 @@
             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();
 
@@ -212,6 +257,7 @@
         {
 
             tmpMask.enabled = true;
+            offectBackground.SetActive(true);
 
             SetGuideUI(false);
 
@@ -239,11 +285,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 +325,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));
@@ -311,7 +358,7 @@
             AddButtonListener(towerBuyBtn, ac);
 
             Image btnImg = towerBuyBtn.GetComponent<Image>();
-            InitRectGuidance(btnImg, 189, 73.5f);
+            InitRectGuidance(btnImg, 159, 73.5f, Vector2.one);
             SetRimPos(towerBuyBtn);
             //maskObj.ShowImmediately();
         }
@@ -320,7 +367,7 @@
             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);
@@ -364,7 +411,7 @@
 
             ShowDragPath(skill.GetStartP, image_SkillRim.rectTransform);
 
-            InitRectGuidance(image_SkillRim, 79, 265);
+            InitRectGuidance(image_SkillRim, 79, 265, tmpOffect);
 
         }
         else if (currentIndex == 1)
@@ -410,7 +457,14 @@
     {
         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
+        {
+            image_Rim_Rect.anchoredPosition = rt.anchoredPosition;
+        }
         image_Rim_Rect.sizeDelta = (rt.sizeDelta * rt.localScale) + rimOffset;
         if (image_Rim_Rect.sizeDelta.x > 200)
         {
@@ -424,7 +478,10 @@
         }
 
         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);
+            //image_Tip_Rect.anchoredPosition -= tmpOffect;
+        }
 
     }
 
@@ -454,7 +511,7 @@
     /// 抠出来一个区域
     /// </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)
         {
@@ -462,7 +519,14 @@
         }
         //maskObj.Init(target);
         //maskObj.ShowImmediately();
-        maskObj.InitForCamera(target, x, y);
+        if (target.gameObject.name == "TowerBuyBtn")
+        {
+            maskObj.InitForCamera(target, towerBuyBtnPos, x, y);
+        }
+        else
+        {
+            maskObj.InitForCamera(target, x, y, offect);
+        }
 
     }
 

--
Gitblit v1.9.1