From 31efa47c430874f95f4ff5503372f0cf6ecb53ae Mon Sep 17 00:00:00 2001
From: client_Wu Xijin <364452445@qq.com>
Date: 星期二, 04 十二月 2018 18:28:30 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.0.87:10010/r/snxxz_scripts

---
 Core/ResModule/MaterialLoader.cs |   73 ++++++++++++++++++++++--------------
 1 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/Core/ResModule/MaterialLoader.cs b/Core/ResModule/MaterialLoader.cs
index 4d21bea..9d26d5d 100644
--- a/Core/ResModule/MaterialLoader.cs
+++ b/Core/ResModule/MaterialLoader.cs
@@ -1,30 +1,9 @@
-锘縰sing UnityEngine;
-using System.Collections;
+锘縰sing System.Collections.Generic;
+using UnityEngine;
 
 public class MaterialLoader
 {
-
-    public static Material Load(string modelName, string materialName)
-    {
-
-        string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME,
-                                                   ResourcesPath.MOB_SUFFIX,
-                                                   modelName);
-
-        string _assetName = materialName;
-
-        AssetInfo _assetInfo = new AssetInfo(_bundleName, _assetName);
-
-        Material _controller = AssetBundleUtility.Instance.Sync_LoadAsset(_assetInfo) as Material;
-
-        if (_controller == null)
-        {
-            DebugEx.LogErrorFormat("MaterialLoader.Load() => 鍔犺浇涓嶅埌璧勬簮: {0}.", _assetName);
-        }
-
-        return _controller;
-
-    }
+    readonly static Dictionary<string, ObjectPool<Material>> s_MatDict = new Dictionary<string, ObjectPool<Material>>();
 
     public static Material LoadClothesMaterial(int id, bool isUI, bool isSuit)
     {
@@ -65,6 +44,19 @@
             return null;
         }
 
+        //Debug.LogFormat("鎯宠鍔犺浇鐨勬潗璐ㄧ殑鍚嶇О: {0}", _assetName);
+
+        ObjectPool<Material> _pool = null;
+
+        if (s_MatDict.TryGetValue(_assetName, out _pool))
+        {
+            if (_pool.inactivedCount > 0)
+            {
+                //Debug.Log(" |-- 姹犻噷鏈�, 浠庢睜閲屽彇");
+                return _pool.Get();
+            }
+        }
+
         string _name = _modelResConfig.ResourcesName;
         int _index = _name.IndexOf('/');
         if (_index != -1)
@@ -72,13 +64,15 @@
             _name = _name.Substring(_index + 1);
         }
 
+        var _parentDirName = string.Empty;
+
         if (_name.Contains("A_Zs"))
         {
-            _name = "A_Zs";
+            _parentDirName = "A_Zs";
         }
         else if (_name.Contains("A_Fs"))
         {
-            _name = "A_Fs";
+            _parentDirName = "A_Fs";
         }
 
         Material _mat = null;
@@ -87,7 +81,7 @@
 #if UNITY_EDITOR
             string _resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
                                                     "Mob/",
-                                                    _name,
+                                                    _parentDirName,
                                                     "/Materials/",
                                                     _assetName,
                                                     ".mat");
@@ -96,16 +90,37 @@
         }
         else
         {
-            string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, _name.ToLower(), "_materials");
+            string _bundleName = StringUtility.Contact(ResourcesPath.MOB_FOLDER_NAME, InstanceResourcesLoader.raceSuffix, _name.ToLower());
             AssetInfo _assetInfo = new AssetInfo(_bundleName, _assetName);
             _mat = AssetBundleUtility.Instance.Sync_LoadAsset(_assetInfo) as Material;
         }
 
         if (_mat == null)
         {
-            DebugEx.LogErrorFormat("MaterialLoader.Load() => 鍔犺浇涓嶅埌璧勬簮: {0}.", _assetName);
+            DebugEx.LogErrorFormat("MaterialLoader.Load() => 鍔犺浇涓嶅埌璧勬簮: {0}", _assetName);
         }
 
         return _mat;
     }
+
+    public static void Release(Material mat)
+    {
+        if (!mat)
+        {
+            return;
+        }
+
+        var _name = mat.name.Replace(" (Instance)", "");
+        //Debug.LogFormat("瑕侀噴鏀剧殑鏉愯川鐨勫悕绉�: {0}, 淇敼鍚庣殑鍚嶇О: {1}", mat.name, _name);
+
+        ObjectPool<Material> _pool = null;
+
+        if (!s_MatDict.TryGetValue(_name, out _pool))
+        {
+            _pool = new ObjectPool<Material>(null, null);
+            s_MatDict.Add(_name, _pool);
+        }
+
+        _pool.Add(mat);
+    }
 }

--
Gitblit v1.8.0