weixudong
2020-11-02 987087eb401e39656fcfd9b5108eee93c3383396
修复购买金币按钮,位置不对的BUG
1 files modified
97 ■■■■■ changed files
Assets/Scripts/TowerDefense/Towers/Placement/TowerPlacementGridEndless.cs 97 ●●●●● patch | view | raw | blame | history
Assets/Scripts/TowerDefense/Towers/Placement/TowerPlacementGridEndless.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Core.Utilities;
using KTGMGemClient;
using TowerDefense.Level;
@@ -6,8 +7,25 @@
using UnityEngine;
using UnityEngine.UI;
namespace TowerDefense.Towers.Placement
namespace TowerDefense.Towers.Placement {
    public class BuyButtonGroup
{
        public BuyButtonGroup(Transform t,int x,int y)
        {
            this.button = t;
            this.x = x;
            this.y = y;
        }
        public Transform button;
        public int x;
        public int y;
    };
    /// <summary>
    /// A tower placement location made from a grid.
    /// Its origin is centered in the middle of the lower-right cell. It can be oriented in any direction
@@ -15,6 +33,10 @@
    [RequireComponent(typeof(BoxCollider))]
    public class TowerPlacementGridEndless : MonoBehaviour, IPlacementArea
    {
        [Range(0,100)]
        public float buyButtonScaler=1.9f;
        private List<BuyButtonGroup> mBuyButtons = new List<BuyButtonGroup>();
        public static float GRID_OPENCASH = 100;
        /// <summary>
@@ -319,9 +341,15 @@
                }
            }
        }
        void FixedUpdate()
        {
            this.resizeBuyButtonSize(this.buyButtonScaler);
        }
        void Update()
        {
            if (m_arrCoinGenTime == null || !EndlessUIStart.instance.IsGameRunning) return;
            float delta = Time.deltaTime;
@@ -529,6 +557,8 @@
            m_AvailableCells = new bool[dimensions.x, dimensions.y];
            opponent = false;
        }
        /// <summary>
@@ -548,6 +578,49 @@
            preCalculateGridUIPos();
        }
        void resizeBuyButtonSize(float defaultVal=1.9f)
        {
            foreach(BuyButtonGroup bbg in this.mBuyButtons)
            {
                Vector3 pos = bbg.button.position;
                pos.x = arrGridCentPos[bbg.x, bbg.y].x;
                pos.z = arrGridCentPos[bbg.x, bbg.y].y + (bbg.y - AttackRowNumbers) * defaultVal;
                pos.y = 30;
                bbg.button.position = pos;
                bbg.button.localRotation = Quaternion.identity;
                bbg.button.localScale = Vector3.one;
            }
            //for (int x = 0; x < dimensions.x; ++x)
            //{
            //    for (int y = dimensions.y - AttackRowNumbers; y < dimensions.y; ++y)
            //    {
            //        if (m_arrGridType[x, y] != PlacementGridType.EGridWaitBuy) continue;
            //        GameObject container = GameObject.Find("BuyButtonContainer");
            //        Button buyButton = Instantiate(waitBuyBtnPrefab);
            //        buyButton.transform.SetParent(container.transform);
            //        mBuyButtons.Add(new BuyButtonGroup(buyButton.transform, x, y));
            //        //Camera.main.WorldToViewportPoint()
            //        Vector3 pos = buyButton.transform.position;
            //        pos.x = arrGridCentPos[x, y].x;
            //        pos.z = arrGridCentPos[x, y].y + (y - AttackRowNumbers) * 1.9f;
            //        pos.y = 30;
            //        buyButton.transform.position = pos;
            //        buyButton.transform.localRotation = Quaternion.identity;
            //        buyButton.transform.localScale = Vector3.one;
            //    }
            //}
        }
        /// <summary>
        /// 预计算塔位格子对应的屏幕坐标以及塔位格子的屏幕尺寸
        /// WORK START: 计算屏幕坐标,然后开搞屏幕相关的内容。下午要把塔位上显示界面搞出来。
@@ -555,6 +628,7 @@
        /// </summary>
        void preCalculateGridUIPos()
        {
            arrGridCentPos = new Vector2[dimensions.x, dimensions.y];
            Vector3 targetPos = GridToWorld(new IntVector2(0, 0), new IntVector2(1, 1));
@@ -573,6 +647,7 @@
                }
            }
            // 血条位置的设定
            PreCalculateTowerBloodUi();
@@ -588,13 +663,17 @@
                    Button buyButton = Instantiate(waitBuyBtnPrefab);
                    buyButton.transform.SetParent(container.transform);
                    Vector3 pos = buyButton.transform.position;
                    pos.x = arrGridCentPos[x, y].x;
                    pos.z = arrGridCentPos[x, y].y + (y - AttackRowNumbers) * 1.9f;
                    pos.y = 30;
                    buyButton.transform.position = pos;
                    buyButton.transform.localRotation = Quaternion.identity;
                    buyButton.transform.localScale = Vector3.one;
                    mBuyButtons.Add(new BuyButtonGroup(buyButton.transform, x, y));
                    //Camera.main.WorldToViewportPoint()
                    //Vector3 pos = buyButton.transform.position;
                    //pos.x = arrGridCentPos[x, y].x;
                    //pos.z = arrGridCentPos[x, y].y + (y - AttackRowNumbers) * 1.9f;
                    //pos.y = 30;
                    //buyButton.transform.position = pos;
                    //buyButton.transform.localRotation = Quaternion.identity;
                    //buyButton.transform.localScale = Vector3.one;
                    // 设置按钮对应的点击功能
                    EndlessTowerGridOpen tgo = buyButton.GetComponent<EndlessTowerGridOpen>();
@@ -606,6 +685,8 @@
                    }
                }
            }
            this.resizeBuyButtonSize();
        }
        /// <summary>