wangguan
2020-12-29 452c75675679c44cc39b04bdb7d330d7c5c14d5c
Assets/Scripts/TowerDefense/UI/EndlessBuffSelect.cs
@@ -16,13 +16,6 @@
    {
        public List<SelectBuffIcon> IconList;
        private string iconPath = "UI/Endless/BuffIcon/BuffIcon_";
        /// <summary>
        /// buff是否选中完成
        /// </summary>
        private bool isCompleted;
        public event Action<int> BuffSelectCompleted;
        /// <summary>
@@ -31,6 +24,12 @@
        private int SelectedIndex = -1;
        public Button SelectBtn;
        public GameObject EffectPrefabObject;
        private GameObject effectObj;
        private Vector3[] effectPosArr = { new Vector3(-21.6f, 0, 6.6f), new Vector3(0, 0, 6.6f), new Vector3(21.6f, 0, 6.6f) };
        // Start is called before the first frame update
        private void Start()
@@ -43,20 +42,21 @@
            SelectBtn.onClick.AddListener(OnClickSelectBtn);
        }
        private void OnDisable()
        private void OnEnable()
        {
            Reset();
        }
        private void Reset()
        {
            isCompleted = false;
            SelectedIndex = -1;
            for (int i = 0; i < IconList.Count; ++i)
            {
                IconList[i].Reset();
            }
        }
        private void OnDisable()
        {
            if (effectObj != null)
                Destroy(effectObj);
        }
        public void OnClick(int index)
@@ -70,6 +70,33 @@
            SelectedIndex = index;
            IconList[index].SetState(true);
            //PlayEffect();
        }
        private void PlayEffect()
        {
            if (effectObj == null)
            {
                effectObj = Instantiate(EffectPrefabObject);
                GameObject particleSystemObject = GameObject.Find("ParticleSystemObject");
                effectObj.transform.SetParent(particleSystemObject.transform, false);
                effectObj.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
            }
            effectObj.transform.localPosition = effectPosArr[SelectedIndex];
            ParticleSystem ps = effectObj.transform.GetChild(0).GetComponent<ParticleSystem>();
            ps.Play();
        }
        private void StopEffect()
        {
            if (effectObj != null)
            {
                ParticleSystem ps = effectObj.transform.GetChild(0).GetComponent<ParticleSystem>();
                ps.Stop();
                ps.Clear();
            }
        }
        /// <summary>
@@ -81,7 +108,12 @@
            int index = SelectedIndex;
            AudioSourceManager.Ins.Play(AudioEnum.UI);
            HideBuffUI();
            IconList[index].Fly();
            EndlessRandomTower.instance.SetCountDown(true,true);
            if (BuffSelectCompleted != null)
                BuffSelectCompleted(index);
@@ -89,11 +121,15 @@
        public void ShowBuffUI()
        {
            EndlessMaskUI.instance.Show();
            gameObject.SetActive(true);
            AudioSourceManager.Ins?.Play(AudioEnum.ChooseBuff);
        }
        public void HideBuffUI()
        {
            EndlessMaskUI.instance.Hide();
            StopEffect();
            gameObject.SetActive(false);
        }
@@ -106,6 +142,7 @@
                IconList[i].SetName(list[i].Config.name);
                IconList[i].SetEffect(list[i].Config.brief);
                IconList[i].SetRare(list[i].Config.rare);
                IconList[i].SetIsGold(list[i].EffectType == EndlessBuffEffectType.GoldAdd);
            }
        }
    }