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/TowerDefense/Level/EndlessDropManager.cs |  199 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 134 insertions(+), 65 deletions(-)

diff --git a/Assets/Scripts/TowerDefense/Level/EndlessDropManager.cs b/Assets/Scripts/TowerDefense/Level/EndlessDropManager.cs
index 1f096ba..7ea8bf3 100644
--- a/Assets/Scripts/TowerDefense/Level/EndlessDropManager.cs
+++ b/Assets/Scripts/TowerDefense/Level/EndlessDropManager.cs
@@ -16,11 +16,6 @@
     public class EndlessDropManager : Singleton<EndlessDropManager>
     {
         /// <summary>
-        /// 掉落道具预制体列表
-        /// </summary>
-        public List<GameObject> PropList;
-
-        /// <summary>
         /// 获得掉落事件
         /// </summary>
         public event Action<EndlessDrop> ObtainDropEvent;
@@ -40,16 +35,26 @@
         /// </summary>
         private Dictionary<int, GameObject> DropObjDic;
 
+        private string dropPath = "UI/Props/EndlessDropEffect";
+
+        /// <summary>
+        /// 自动拾取时间,先统一处理
+        /// </summary>
+        public float AutoPickupTime = 5f;
+
         /// <summary>
         /// 掉落半径
         /// </summary>
-        public float DropRadius { get; set; } = 50f;
+        public float DropRadius { get; set; } = 5f;
+
+        public Canvas canvas;
 
         // Start is called before the first frame update
         private void Start()
         {
             AllDropList = new List<EndlessDrop>();
             DropObjDic = new Dictionary<int, GameObject>();
+            allIconLis = new List<FlyImage>();
         }
 
         // Update is called once per frame
@@ -63,9 +68,12 @@
 
                 if (AllDropList[i].ElapsedTime >= AllDropList[i].AutoPickupTime)
                 {
-                    AllDropList[i].IsPickupCompleted = true;
-                    SafelyCallObtainDrop(AllDropList[i]);
-                    RemoveDrop(AllDropList[i].Id);
+                    EndlessDropReward dropReward = DropObjDic[AllDropList[i].Id].GetComponent<EndlessDropReward>();
+                    // dropReward?.OnClick();
+
+                    //AllDropList[i].IsPickupCompleted = true;
+                    //SafelyCallObtainDrop(AllDropList[i]);
+                    //RemoveDrop(AllDropList[i].Id);
                 }
             }
         }
@@ -90,50 +98,21 @@
         }
 
         /// <summary>
-        /// 根据reward获得预制体对象
-        /// </summary>
-        /// <param name="data"></param>
-        private GameObject GetPrefabByReward(reward data)
-        {
-            switch (data.type)
-            {
-                case CURRENCY.Money:
-                    return PropList[0];
-                case CURRENCY.Gold:
-                    return PropList[1];
-                case CURRENCY.Box:
-                    return PropList[1 + data.id];
-            }
-
-            return null;
-        }
-
-        /// <summary>
         /// 获得一些掉落
         /// </summary>
         /// <param name="list"></param>
         /// <param name="pos">小怪的世界坐标</param>
         public void AddDrop(List<reward> list, Vector3 pos)
         {
-            for (int i = 0; i < list.Count; ++i)
-            {
-                EndlessDrop drop = new EndlessDrop();
-                drop.Reward = list[i];
-                drop.Id = GetDropId();
-
-                GameObject prefabObj = GetPrefabByReward(list[i]);
-
-                if (prefabObj == null)
-                {
-                    Debug.LogError($"--------------------- type: {list[i].type} id:{list[i].id} 没有对应的预制体 ---------------------");
-                    continue;
-                }
-
-                EndlessDropReward dropReward = prefabObj.GetComponent<EndlessDropReward>();
-                drop.AutoPickupTime = dropReward.AutoPickupTime;
-                CreateDrop(drop, pos, list.Count > 0);
-                AllDropList.Add(drop);
-            }
+            // for (int i = 0; i < list.Count; ++i)
+            // {
+            //     EndlessDrop drop = new EndlessDrop();
+            //     drop.Reward = list[i];
+            //     drop.Id = GetDropId();
+            //     drop.AutoPickupTime = AutoPickupTime;
+            //     CreateDrop(drop, pos, list.Count > 0);
+            //     AllDropList.Add(drop);
+            // }
         }
 
         /// <summary>
@@ -153,33 +132,108 @@
         /// 在场景中创建掉落的icon
         /// </summary>
         /// <param name="drop"></param>
-        /// <param name="pos"></param>
+        /// <param name="worldPos">世界坐标</param>
         /// <param name="isRandom">是否需要随机位置</param>
-        private void CreateDrop(EndlessDrop drop, Vector3 pos, bool isRandom = false)
+        private void CreateDrop(EndlessDrop drop, Vector3 worldPos, bool isRandom = false)
         {
-            GameObject dropLayer = GameObject.Find("DropLayer");
-            GameObject prefabObj = GetPrefabByReward(drop.Reward);
+            GameObject prefabObj = Resources.Load<GameObject>(dropPath);
             GameObject obj = Instantiate(prefabObj);
-            GameObject mainUI = GameObject.Find("MainUI");
+            EndlessDropReward dropReward = obj.GetComponent<EndlessDropReward>();
 
-            Transform mainUITransform = mainUI.GetComponent<Transform>();
+            dropReward.DropData = drop;
+            dropReward.SetIcon();
+
+            GameObject mainUI = GameObject.Find("BottomUI");
+
+            Transform mainUITransform = mainUI.transform;
+            obj.transform.SetParent(mainUITransform, false);
+
+            // Vector3 screenPos = Camera.main.WorldToScreenPoint(worldPos);
+            // Vector2 pos;
+            // RectTransformUtility.ScreenPointToLocalPointInRectangle(mainUITransform as RectTransform, screenPos, Camera.main, out pos);
+            // (obj.transform as RectTransform).anchoredPosition = pos;
+
             obj.GetComponent<Transform>().SetParent(mainUITransform, true);
-            Vector3 screenPos = Camera.main.WorldToScreenPoint(pos);
-            screenPos.z = 0;
-            obj.transform.position = screenPos;
 
-            if (isRandom)
+            obj.transform.position = worldPos;
+
+            Vector3 offect = obj.GetComponent<RectTransform>().anchoredPosition3D;
+            offect.z = 0;
+            obj.GetComponent<RectTransform>().anchoredPosition3D = offect;
+            // obj.transform.localRotation = Quaternion.identity;
+            // obj.transform.localScale = Vector3.one;
+
+            // if (isRandom)
+            // {
+            //     Vector2 p = UnityEngine.Random.insideUnitCircle * DropRadius;
+            //     Vector3 pos1 = p.normalized * p.magnitude;
+            //     Vector3 objPos = obj.transform.position;
+            //     objPos.x += pos1.x;
+            //     objPos.z += pos1.y;
+            //     obj.transform.position = objPos;
+            // }
+
+            dropReward.PlayParticle();
+            DropObjDic.Add(drop.Id, obj);
+        }
+
+
+        List<FlyImage> allIconLis;
+        public GameObject drapIcon;
+
+        public FlyImage CreateIcon(Transform ts)
+        {
+            for (int i = 0; i < allIconLis.Count; i++)
             {
-                Vector2 p = UnityEngine.Random.insideUnitCircle * DropRadius;
-                Vector3 pos1 = p.normalized * p.magnitude;
-                Vector3 objPos = obj.transform.position;
-                objPos.x += pos1.x;
-                objPos.y += pos1.y;
-                obj.transform.position = objPos;
+                if (!allIconLis[i].gameObject.activeSelf)
+                {
+                    allIconLis[i].gameObject.SetActive(true);
+                    return allIconLis[i];
+                }
             }
 
-            obj.GetComponent<EndlessDropReward>().DropData = drop;
-            DropObjDic.Add(drop.Id, obj);
+            GameObject obj = Instantiate(drapIcon, ts);
+            FlyImage fly = obj.GetComponent<FlyImage>();
+            allIconLis.Add(fly);
+            return fly;
+
+        }
+
+        public void FlyIcon(Transform ts, Sprite sp, Vector3 startP, Vector3 endP, bool useBezier, int count)
+        {
+            StartCoroutine(CreateIcon(ts, sp, startP, endP, useBezier, count));
+        }
+
+        IEnumerator CreateIcon(Transform ts, Sprite sp, Vector3 startP, Vector3 endP, bool useBezier, int count)
+        {
+            FlyImage fly;
+
+            // for (int i = 0; i < 5; i++)
+            // {
+            //     fly = CreateIcon(ts);
+            //     fly.SetDestination(sp, startP, endP, useBezier);
+            // }
+            // yield return new WaitForSeconds(0.2f);
+
+
+            for (int i = 0; i < 15; i++)
+            {
+                fly = CreateIcon(ts);
+                if (i == 0)
+                {
+                    fly.Init(true, count);
+                }
+                else
+                {
+                    fly.Init(false, 0);
+                }
+
+                fly.SetDestination(sp, startP, endP, useBezier);
+                yield return new WaitForSeconds(0.01f);
+
+            }
+
+            yield break;
         }
 
         /// <summary>
@@ -220,5 +274,20 @@
 
             return true;
         }
+
+        /// <summary>
+        /// 拾取所有还未拾取的掉落
+        /// </summary>
+        public void PickUpAllDrop()
+        {
+            for (int i = 0; i < AllDropList.Count; ++i)
+            {
+                if (AllDropList[i].IsPickupCompleted) continue;
+
+                AllDropList[i].IsPickupCompleted = true;
+                SafelyCallObtainDrop(AllDropList[i]);
+                RemoveDrop(AllDropList[i].Id);
+            }
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1