From 7f71e2c1cfb5a5bd329c87249c4da4f7f8cde330 Mon Sep 17 00:00:00 2001
From: wangguan <wangguan@kt007.com>
Date: Sat, 14 Nov 2020 17:38:12 +0800
Subject: [PATCH] 调整UI到BottomCanvas下,但是MainUI还需要保留,用来显示受击伤害文字

---
 Assets/Scripts/UI/ClickEffect.cs |   59 +++++++++++++++--------------------------------------------
 1 files changed, 15 insertions(+), 44 deletions(-)

diff --git a/Assets/Scripts/UI/ClickEffect.cs b/Assets/Scripts/UI/ClickEffect.cs
index 079ab31..b1a7353 100644
--- a/Assets/Scripts/UI/ClickEffect.cs
+++ b/Assets/Scripts/UI/ClickEffect.cs
@@ -22,10 +22,9 @@
     /// <summary>
     /// 屏幕特效渲染使用的相机
     /// </summary>
-    public Camera fxRenderCamera;
+    private Camera fxRenderCamera;
 
-    private Queue<GameObject> pool = new Queue<GameObject>(20);
-    private List<GameObject> activatedFXList = new List<GameObject>();
+    private Queue<RecycleEffectc> pool = new Queue<RecycleEffectc>(20);
 
     private void Awake()
     {
@@ -38,21 +37,12 @@
         {
             fxSample.SetActive(false);
         }
+
+        fxRenderCamera = GameObject.Find("UICamera").GetComponent<Camera>();
     }
 
     private void Update()
     {
-        for (int i = activatedFXList.Count - 1; i >= 0; --i)
-        {
-            GameObject fx = activatedFXList[i];
-            float fxTime = float.Parse(fx.name);
-            if (Time.time - fxTime > fxLifeTime)
-            {
-                RecycleFX(fx);
-                activatedFXList.RemoveAt(i);
-            }
-        }
-
         if (Application.isMobilePlatform)
         {
             for (int i = 0; i < Input.touchCount; ++i)
@@ -76,57 +66,38 @@
 
     private void PlayFX(Vector2 tapPos)
     {
-        GameObject fx = CreateFX();
-        fx.name = Time.time.ToString();
-        activatedFXList.Add(fx);
+        RecycleEffectc fx = CreateFX();
 
-        RectTransform fxRectTrans = fx.GetComponent<RectTransform>();
+        RectTransform fxRectTrans = fx.gameObject.GetComponent<RectTransform>();
         Vector2 fxLocalPos;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(fxContainer, tapPos, fxRenderCamera, out fxLocalPos);
         fxRectTrans.SetParent(fxContainer);
         fxRectTrans.anchoredPosition3D = fxLocalPos;
-        fx.SetActive(true);
+        //fxRectTrans.localScale = Vector3.one;
+        fx.gameObject.SetActive(true);
+        fx.StartPlay(fxLifeTime,RecycleFX);
     }
 
 
-    private GameObject CreateFX()
+    private RecycleEffectc CreateFX()
     {
-        GameObject newFX = null;
+        RecycleEffectc newFX = null;
         if (pool.Count > 0)
         {
             newFX = pool.Dequeue();
         }
         else
         {
-            newFX = Instantiate(fxSample);
+            GameObject go = Instantiate(fxSample);
+            newFX = go.AddComponent<RecycleEffectc>();
         }
         return newFX;
     }
 
-    private void RecycleFX(GameObject fx)
+    private void RecycleFX(RecycleEffectc fx)
     {
-        fx.SetActive(false);
+        fx.gameObject.SetActive(false);
         pool.Enqueue(fx);
     }
 
-    //简单,无法显示在最上层
-    // Vector3 point;
-    // GameObject effectGo;
-
-    // void Start()
-    // {
-    //     effectGo = Resources.Load<GameObject>("Prefabs/EffectClick");
-    // }
-
-    // void Update()
-    // {
-    //     if (Input.GetMouseButtonDown(0))
-    //     {
-    //         point = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 4f);//获得鼠标点击点
-    //         point = Camera.main.ScreenToWorldPoint(point);//从屏幕空间转换到世界空间
-    //         GameObject go = Instantiate(effectGo);//生成特效
-    //         go.transform.position = point;
-    //         Destroy(go, 0.5f);
-    //     }
-    // }
 }

--
Gitblit v1.9.1