Browse Source

添加EffectUI

guodong 2 năm trước cách đây
mục cha
commit
e6e4c680aa

+ 2 - 2
GameClient/Assets/Game/HotUpdate/DressUp/SceneController.cs

@@ -110,13 +110,13 @@ namespace GFGGame
             spr.sprite = sp;
         }
 
-        public static void AddObjectToView(GameObject _gameObject, GoWrapper _wrapper, GGraph holder, string res, out GameObject gameObject, out GoWrapper wrapper, float scale = 100)
+        public static void AddObjectToView(GameObject _gameObject, GoWrapper _wrapper, GGraph holder, string resPath, out GameObject gameObject, out GoWrapper wrapper, float scale = 100)
         {
             if (_gameObject != null)
             {
                 GameObject.DestroyImmediate(_gameObject);
             }
-            _gameObject = DressUpUtil.CreateAnimationObj(res);
+            _gameObject = DressUpUtil.CreateAnimationObj(resPath);
             _gameObject.transform.localScale = new Vector3(scale, scale, scale);
 
             if (_wrapper != null)

+ 40 - 0
GameClient/Assets/Game/HotUpdate/Effect/EffectUI.cs

@@ -0,0 +1,40 @@
+using FairyGUI;
+using UnityEngine;
+
+namespace GFGGame
+{
+    public class EffectUI
+    {
+        private GameObject _gameObject;
+        private GoWrapper _wrapper;
+        public bool isDisposed;
+
+
+        public void Reset(GGraph holder, string uiName, string resName, float scale = 100)
+        {
+            if (!isDisposed) Dispose();
+            isDisposed = false;
+            string resPath = ResPathUtil.GetViewEffectPath(uiName, resName);
+            _gameObject = DressUpUtil.CreateAnimationObj(resPath);
+            _gameObject.transform.localScale = new Vector3(scale, scale, scale);
+            _wrapper = new GoWrapper(_gameObject);
+            holder.SetNativeObject(_wrapper);
+
+        }
+
+
+        public void Dispose()
+        {
+            isDisposed = true;
+            if (_gameObject != null)
+            {
+                GameObject.DestroyImmediate(_gameObject);
+                _gameObject = null;
+            }
+            if (_wrapper != null)
+            {
+                _wrapper.Dispose();
+            }
+        }
+    }
+}

+ 11 - 0
GameClient/Assets/Game/HotUpdate/Effect/EffectUI.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 69937108f64b99a44b93a44031fadcd1
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 39 - 0
GameClient/Assets/Game/HotUpdate/Effect/EffectUIPool.cs

@@ -0,0 +1,39 @@
+using FairyGUI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace GFGGame
+{
+    public static class EffectUIPool
+    {
+        private static List<EffectUI> effectUIs = new List<EffectUI>();
+
+        public static EffectUI CreateEffectUI(GGraph holder, string uiName, string resName, float scale = 100)
+        {
+            EffectUI effectUI;
+            if (effectUIs.Count > 0)
+            {
+                int lastIndex = effectUIs.Count - 1;
+                effectUI = effectUIs[lastIndex];
+                effectUIs.RemoveAt(lastIndex);
+            }
+            else
+            {
+                effectUI = new EffectUI();
+            }
+            effectUI.Reset(holder, uiName, resName, scale);
+            return effectUI;
+        }
+
+        public static void Recycle(EffectUI effect)
+        {
+            if (effect == null) return;
+            effect.Dispose();
+            if (effectUIs.Contains(effect)) return;
+            effectUIs.Add(effect);
+        }
+    }
+}

+ 11 - 0
GameClient/Assets/Game/HotUpdate/Effect/EffectUIPool.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: bb6b98b28cf9ba54a8b1562e865ffb34
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 7 - 5
GameClient/Assets/Game/HotUpdate/Views/MainUI/MainUIView.cs

@@ -40,8 +40,9 @@ namespace GFGGame
         private GButton _btnActivityDay7;
 
 
-        private GameObject _effectObj4;
-        private GoWrapper _wrapper4;
+        //private GameObject _effectObj4;
+        //private GoWrapper _wrapper4;
+        private EffectUI _effectUI4;
 
         private GameObject _effectObj4_1;
         private GoWrapper _wrapper4_1;
@@ -73,7 +74,7 @@ namespace GFGGame
                 SceneController.DestroyObjectFromView(_effects[i], _wrappers[i]);
                 SceneController.DestroyObjectFromView(_effects1[i], _wrappers1[i]);
             }
-            SceneController.DestroyObjectFromView(_effectObj4, _wrapper4);
+            EffectUIPool.Recycle(_effectUI4);
             SceneController.DestroyObjectFromView(_effectObj4_1, _wrapper4_1);
             SceneController.DestroyObjectFromView(_effectObj5, _wrapper5);
 
@@ -269,9 +270,10 @@ namespace GFGGame
         private void AddEffect()
         {
 
-            string resPath1 = ResPathUtil.GetViewEffectPath("ui_zjm", "ui_zjm_zzl_d");
+            //string resPath1 = ResPathUtil.GetViewEffectPath("ui_zjm", "ui_zjm_zzl_d");
             string resPath3 = ResPathUtil.GetViewEffectPath("ui_zjm", "ui_zjm_zzl");
-            SceneController.AddObjectToView(_effectObj4, _wrapper4, _ui.m_btnMain.m_holder, resPath1, out _effectObj4, out _wrapper4);
+            //SceneController.AddObjectToView(_effectObj4, _wrapper4, _ui.m_btnMain.m_holder, resPath1, out _effectObj4, out _wrapper4);
+            _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_btnMain.m_holder, "ui_zjm", "ui_zjm_zzl_d");
             SceneController.AddObjectToView(_effectObj4_1, _wrapper4_1, _ui.m_btnMain.m_holder1, resPath3, out _effectObj4_1, out _wrapper4_1);
 
             string resPath4 = ResPathUtil.GetViewEffectPath("ui_zjm", "ui_zjm_jt");