Esempio n. 1
0
    private void OnGUI()
    {
        GUILayout.Box("内存占用:" + MemoryManager.totalAllocatedMemory.ToString("F") + "MB");
        EditorDrawGUIUtil.DrawScrollView(this, () =>
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            Dictionary <string, int> loadedAssets = AssetsPoolManager.GetLoadedAssets();
            GUILayout.Box("加载记录:");
            foreach (var item in loadedAssets)
            {
                GUILayout.Label("  =>" + item.Key + " : " + item.Value);
            }
            GUILayout.EndVertical();
            // GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();

            List <string> reCover = AssetsPoolManager.GetRecycleAssets();
            GUILayout.Box("回收池记录(" + reCover.Count + "):");
            foreach (var item in reCover)
            {
                GUILayout.Label("  ==>>" + item);
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        });
    }
 private void OnDestroy()
 {
     if (!string.IsNullOrEmpty(iconName))
     {
         AssetsPoolManager.DestroyByPool(iconName);
     }
 }
    public static Dictionary <string, SingleField> GetData(string ConfigName)
    {
        if (s_configCache.ContainsKey(ConfigName))
        {
            return(s_configCache[ConfigName]);
        }

        string dataJson = "";

        if (!Application.isPlaying)
        {
            dataJson = ResourceIOTool.ReadStringByResource(
                PathTool.GetRelativelyPath(c_directoryName,
                                           ConfigName,
                                           c_expandName));
        }
        else
        {
            dataJson = AssetsPoolManager.ReadTextFile(ConfigName);
        }


        if (dataJson == "")
        {
            throw new Exception("ConfigManager GetData not find " + ConfigName);
        }
        else
        {
            Dictionary <string, SingleField> config = JsonTool.Json2Dictionary <SingleField>(dataJson);

            s_configCache.Add(ConfigName, config);
            return(config);
        }
    }
    public static LanguageSettingConfig LoadEditorConfig()
    {
        if (ResourceManager.GetResourceIsExist(LanguageManager.c_configFileName))
        {
            LanguageSettingConfig config;

            string json = AssetsPoolManager.ReadTextFile(LanguageManager.c_configFileName);

            if (!string.IsNullOrEmpty(json))
            {
                config = JsonUtils.FromJson <LanguageSettingConfig>(json);
            }
            else
            {
                config = null;

                //config.defaultLanguage = SystemLanguage.ChineseSimplified;
                //config.gameExistLanguages.Add(SystemLanguage.ChineseSimplified);
            }
            return(config);
        }
        else
        {
            return(null);
        }
    }
    private void AssetsPoolGUI()
    {
        AssetsPoolManager.triggerUnloadNumber = (int)EditorDrawGUIUtil.DrawBaseValue("回收触发数量", AssetsPoolManager.triggerUnloadNumber);
        AssetsPoolManager.unloadDelayTime     = (float)EditorDrawGUIUtil.DrawBaseValue("回收时间间隔", AssetsPoolManager.unloadDelayTime);
        if (AssetsPoolManager.unloadDelayTime <= 0)
        {
            AssetsPoolManager.unloadDelayTime = 0.05f;
        }
        EditorDrawGUIUtil.DrawScrollView(this, () =>
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();

            DataDetail();
            Dictionary <string, AssetLoadInfo> loadedAssets = AssetsPoolManager.GetLoadedAssets();
            GUILayout.Box("加载记录(" + loadedAssets.Count + "):");
            foreach (var item in assetsInfos)
            {
                DrawTypeAssets(item.Key, item.Value);
            }
            GUILayout.EndVertical();
            // GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();

            List <AssetLoadInfo> reCover = AssetsPoolManager.GetRecycleAssets();
            GUILayout.Box("回收池记录(" + reCover.Count + "):");
            foreach (var item in recycleAssetsInfos)
            {
                DrawTypeAssets(item.Key, item.Value);
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        });
    }
Esempio n. 6
0
 private static DataTable LoadDataTable(SystemLanguage language, string fullFileName)
 {
     if (Application.isPlaying)
     {
         string    name = GetLanguageDataName(language, fullFileName);
         TextAsset text = AssetsPoolManager.Load <TextAsset>(name);
         if (text == null)
         {
             Debug.LogError("Error: no Language file :" + name);
             return(null);
         }
         if (loadTextFileTimesDic.ContainsKey(name))
         {
             loadTextFileTimesDic[name]++;
         }
         else
         {
             loadTextFileTimesDic.Add(name, 1);
         }
         DataTable data = DataTable.Analysis(text.text);
         return(data);
     }
     else
     {
         return(LanguageDataUtils.LoadFileData(language, fullFileName));
     }
 }
Esempio n. 7
0
    static public void SetImageSprite(Image img, string name, bool is_nativesize = false)
    {
        if (name == null)
        {
            Debug.LogError("set_icon Image name 不能为 null !");
            return;
        }

        if (img == null)
        {
            Debug.LogError("set_icon Image 不能为 null !");
            return;
        }

        Sprite sp = AssetsPoolManager.Load <Sprite>(name);// LoadSprite(name);

        if (sp != null)
        {
            img.overrideSprite = sp;// Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector3.zero);
            img.sprite         = img.overrideSprite;

            if (is_nativesize)
            {
                img.SetNativeSize();
            }
        }
        else
        {
            Debug.LogError("SetImageSprite 加载失败,查看资源是否存在,图片格式是否正确:" + name);
        }
    }
Esempio n. 8
0
    public static void SetText(Text text, string name, SystemLanguage language)
    {
        if (ContainsData(name, language))
        {
            TextStyleData data = GetTextStyleData(name, language);

            if (!ResourcesConfigManager.GetIsExitRes(data.fontName))
            {
                Debug.LogError("dont find font :" + data.fontName);
            }
            else
            {
                text.font = AssetsPoolManager.Load <Font>(data.fontName);
            }
            text.fontSize             = data.fontSize;
            text.fontStyle            = data.fontStyle;
            text.resizeTextForBestFit = data.bestFit;
            text.resizeTextMinSize    = data.minSize;
            text.resizeTextMaxSize    = data.maxSize;
            text.alignment            = data.alignment;
            text.supportRichText      = data.richText;
            text.horizontalOverflow   = data.horizontalOverflow;
            text.verticalOverflow     = data.verticalOverflow;
            text.lineSpacing          = data.lineSpacing;
        }
    }
Esempio n. 9
0
    private void LoadQueue()
    {
        if (currentNum >= count)
        {
            RunCallBack();
            Destroy();
            return;
        }
        PreloadResourcesDataGenerate da = queueRes[currentNum];

        currentNum++;
        //Debug.Log("da.m_key " + da.m_key);
        try
        {
            Type resType = ReflectionUtils.GetTypeByTypeFullName(da.m_ResType);

            //  object loadRes = AssetsPoolManager.Load(da.m_key);
            AssetsPoolManager.LoadAsync(da.m_key, resType, (LoadState loadState, object loadRes) =>
            {
                if (loadState.isDone)
                {
                    if (loadRes != null)
                    {
                        if (loadRes is GameObject)
                        {
                            GameObject prefab         = (GameObject)loadRes;
                            List <GameObject> resList = new List <GameObject>();
                            for (int i = 0; i < da.m_instantiateNum; i++)
                            {
                                GameObject obj = GameObjectManager.CreateGameObjectByPool(prefab);
                                resList.Add(obj);
                            }
                            foreach (var obj in resList)
                            {
                                GameObjectManager.DestroyGameObjectByPool(obj, !da.m_createInstanceActive);
                            }
                        }
                        else
                        {
                            AssetsPoolManager.DestroyByPool(da.m_key);
                        }
                    }
                    else
                    {
                        if (loadRes == null)
                        {
                            Debug.LogError("Error: 预加载失败  key:" + da.m_key);
                        }
                    }
                    RunCallBack();
                    LoadQueue();
                }
            });
        }
        catch (Exception e)
        {
            Debug.LogError(e);
            LoadQueue();
        }
    }
Esempio n. 10
0
    /// <summary>
    /// 清除掉某一个对象的所有对象池缓存
    /// </summary>
    public static void CleanPoolByName(string name)
    {
        Debug.Log("CleanPool :" + name);
        if (recyclePools.ContainsKey(name))
        {
            List <GameObject> l_objList = recyclePools[name];

            for (int i = 0; i < l_objList.Count; i++)
            {
                GameObject go = l_objList[i];

                PoolObject po = go.GetComponent <PoolObject>();
                if (po)
                {
                    po.OnObjectDestroy();
                }

                GameObject.Destroy(go);
            }
            l_objList.Clear();
            recyclePools.Remove(name);
        }

        if (createPools[name].Count == 0)
        {
            createPools.Remove(name);
            AssetsPoolManager.DestroyByPool(name);
        }
    }
Esempio n. 11
0
    /// <summary>
    /// 清空对象池
    /// </summary>
    public static void CleanPool()
    {
        //Debug.LogWarning("清空对象池");
        removeObjList.Clear();

        foreach (string name in createPools.Keys)
        {
            //if (recyclePools.ContainsKey(name))
            //{
            //    List<GameObject> l_objList = recyclePools[name];

            //    for (int i = 0; i < l_objList.Count; i++)
            //    {
            //        GameObject go = l_objList[i];

            //        PoolObject po = go.GetComponent<PoolObject>();
            //        if (po)
            //        {
            //            po.OnObjectDestroy();
            //        }

            //        GameObject.Destroy(go);
            //    }
            //    l_objList.Clear();
            //    recyclePools.Remove(name);
            //}

            if (createPools[name].Count == 0)
            {
                removeObjList.Add(name);
                AssetsPoolManager.DestroyByPool(name);
            }
        }

        foreach (var item in removeObjList)
        {
            createPools.Remove(item);
        }

        foreach (var name in recyclePools.Keys)
        {
            List <GameObject> l_objList = recyclePools[name];

            for (int i = 0; i < l_objList.Count; i++)
            {
                GameObject go = l_objList[i];

                PoolObject po = go.GetComponent <PoolObject>();
                if (po)
                {
                    po.OnObjectDestroy();
                }

                GameObject.Destroy(go);
            }
            l_objList.Clear();
        }
        recyclePools.Clear();
    }
Esempio n. 12
0
 public void UnloadClip(AudioAsset asset)
 {
     if (asset.audioSource.clip != null)
     {
         string name = asset.assetName;
         asset.audioSource.clip = null;
         AssetsPoolManager.DestroyByPool(name);
     }
 }
Esempio n. 13
0
 private void ClearLoadSprite()
 {
     foreach (var item in loadSpriteNames)
     {
         int num = item.Value;
         //Debug.Log("UIBase 回收图片:" + item.Key + ":" + num);
         AssetsPoolManager.DestroyByPool(item.Key, num);
     }
     loadSpriteNames.Clear();
 }
Esempio n. 14
0
    public static void Release()
    {
        s_languageDataDict.Clear();
        isInit = false;

        foreach (var item in loadTextFileTimesDic)
        {
            AssetsPoolManager.DestroyByPool(item.Key, item.Value);
        }
        loadTextFileTimesDic.Clear();
    }
Esempio n. 15
0
    public AudioClip GetAudioClip(string name)
    {
        AudioClip red = AssetsPoolManager.Load <AudioClip>(name);

        if (red != null)
        {
            return(red);
        }
        Debug.LogError("Can not find AudioClip:" + name);
        return(null);
    }
Esempio n. 16
0
    /// <summary>
    /// 加载一个对象并把它实例化
    /// </summary>
    /// <param name="gameObjectName">对象名</param>
    /// <param name="parent">对象的父节点,可空</param>
    /// <returns></returns>
    private static GameObject NewGameObject(string gameObjectName, GameObject parent = null)
    {
        GameObject goTmp = AssetsPoolManager.Load <GameObject>(gameObjectName);

        if (goTmp == null)
        {
            throw new Exception("CreateGameObject error dont find :" + gameObjectName);
        }

        return(ObjectInstantiate(goTmp, parent));
    }
Esempio n. 17
0
 private void ClearLoadSprite()
 {
     foreach (var item in loadSpriteNames)
     {
         int num = item.Value;
         for (int i = 0; i < num; i++)
         {
             AssetsPoolManager.DestroyByPool(item.Key);
         }
     }
     loadSpriteNames.Clear();
 }
Esempio n. 18
0
    public static AudioClip GetAudioClip(string soundName)
    {
        AudioClip clipTmp = null;

        clipTmp = AssetsPoolManager.Load <AudioClip>(soundName);

        if (clipTmp == null)
        {
            Debug.LogError("AudioManager GetAudioClip error: " + soundName + "is not AudioClip ! ");
        }

        return(clipTmp);
    }
Esempio n. 19
0
    public static Sprite LoadSprite(string resName)
    {
        Texture2D texture = AssetsPoolManager.Load <Texture2D>(resName);

        if (texture)
        {
            return(Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)));
        }
        else
        {
            Debug.LogError("加载图片失败:" + resName);
            return(null);
        }
    }
    public override void Init()
    {
        m_protocolInfo = ReadProtocolInfo(AssetsPoolManager.ReadTextFile(c_ProtocolFileName));
        ReadMethodNameInfo(
            out m_methodNameInfo,
            out m_methodIndexInfo,
            AssetsPoolManager.ReadTextFile(c_methodNameInfoFileName));

        m_messageBuffer = new byte[1024 * 1024 * 8];

        m_head  = 0;
        m_total = 0;

        base.Init();
    }
Esempio n. 21
0
    /// <summary>
    /// 释放内存
    /// </summary>
    public static void FreeMemory()
    {
        GlobalEvent.DispatchEvent(MemoryEvent.FreeMemory);
        //清空缓存的UI
        UIManager.DestroyAllHideUI();
        //清空对象池
        GameObjectManager.CleanPool(true);

        //GameObjectManager.CleanPool_New();

        AssetsPoolManager.Dispose();

        FreeHeapMemory();
        Resources.UnloadUnusedAssets();
        //GC
        //GC.Collect();
    }
    private void InitData()
    {
        if (subStringList == null)
        {
            return;
        }
        subStringsData = new Dictionary <string, string[]>();
        for (int i = 0; i < subStringList.Count; i++)
        {
            if (subStringList[i] == null)
            {
                continue;
            }
            string[] subString = AssetsPoolManager.ReadTextFile(subStringList[i]).Split(splitChar);

            subStringsData.Add(subStringList[i], subString);
        }
    }
Esempio n. 23
0
    /// <summary>
    /// 将一个对象放入对象池
    /// </summary>
    /// <param name="go"></param>
    /// <param name="isSetInactive">是否将放入的物体设为不激活状态(obj.SetActive(false))</param>
    public static void DestroyGameObjectByPool(GameObject go, bool isSetInactive = true)
    {
        string key = go.name.Replace("(Clone)", "");

        if (s_objectPool.ContainsKey(key) == false)
        {
            s_objectPool.Add(key, new List <GameObject>());
        }

        if (s_objectPool[key].Contains(go))
        {
            throw new Exception("DestroyGameObjectByPool:-> Repeat Destroy GameObject !" + go);
        }

        s_objectPool[key].Add(go);

        if (isSetInactive)
        {
            go.SetActive(false);
        }
        else
        {
            go.transform.position = s_OutOfRange;
        }

        go.name = key;
        go.transform.SetParent(PoolParent);
        PoolObject po = go.GetComponent <PoolObject>();

        if (po)
        {
            po.OnRecycle();
        }
        if (createPools.ContainsKey(key) && createPools[key].Contains(go))
        {
            createPools[key].Remove(go);
            //Debug.LogWarning(go.name + " ==>>" + createPools[key].Count);
            if (createPools[key].Count == 0)
            {
                createPools.Remove(key);
                AssetsPoolManager.DestroyByPool(key);
            }
        }
    }
    private void DataDetail()
    {
        foreach (var item in assetsInfos)
        {
            item.Value.Clear();
        }
        Dictionary <string, AssetLoadInfo> loadedAssets = AssetsPoolManager.GetLoadedAssets();

        foreach (var item in loadedAssets)
        {
            if (assetsInfos.ContainsKey(item.Value.assetType))
            {
                assetsInfos[item.Value.assetType].Add(item.Value);
            }
            else
            {
                assetsInfos.Add(item.Value.assetType, new List <AssetLoadInfo>()
                {
                    item.Value
                });
            }
        }

        foreach (var item in recycleAssetsInfos)
        {
            item.Value.Clear();
        }
        List <AssetLoadInfo> reCover = AssetsPoolManager.GetRecycleAssets();

        foreach (var item in reCover)
        {
            if (recycleAssetsInfos.ContainsKey(item.assetType))
            {
                recycleAssetsInfos[item.assetType].Add(item);
            }
            else
            {
                recycleAssetsInfos.Add(item.assetType, new List <AssetLoadInfo>()
                {
                    item
                });
            }
        }
    }
Esempio n. 25
0
    public static Dictionary <string, Dictionary <SystemLanguage, TextStyleData> > LoadData()
    {
        string text = "";

        if (Application.isPlaying)
        {
            text = AssetsPoolManager.ReadTextFile(FileName);
        }
        else
        {
            text = FileUtils.LoadTextFileByPath(FilePathDir + FileName + ".txt");
        }
        if (!string.IsNullOrEmpty(text))
        {
            return(JsonUtils.FromJson <Dictionary <string, Dictionary <SystemLanguage, TextStyleData> > >(text));
        }
        else
        {
            return(new Dictionary <string, Dictionary <SystemLanguage, TextStyleData> >());
        }
    }
    public static DataTable GetData(string DataName)
    {
        try
        {
            //编辑器下不处理缓存
            if (s_dataCache.ContainsKey(DataName))
            {
                return(s_dataCache[DataName]);
            }

            DataTable data     = null;
            string    dataJson = "";

            if (Application.isPlaying)
            {
                dataJson = AssetsPoolManager.ReadTextFile(DataName);
            }
            else
            {
                dataJson = ResourceIOTool.ReadStringByResource(
                    PathTool.GetRelativelyPath(c_directoryName,
                                               DataName,
                                               c_expandName));
            }

            if (dataJson == "")
            {
                throw new Exception("Dont Find ->" + DataName + "<-");
            }
            data             = DataTable.Analysis(dataJson);
            data.m_tableName = DataName;

            s_dataCache.Add(DataName, data);
            return(data);
        }
        catch (Exception e)
        {
            throw new Exception("GetData Exception ->" + DataName + "<- : " + e.ToString());
        }
    }
Esempio n. 27
0
    // Use this for initialization
    void Start()
    {
        transform.GetComponent <InputField>().onValueChanged.AddListener(OnValueChanged);

        if (String.IsNullOrEmpty(textName))
        {
            Debug.LogError("MaskWord textName error = " + textName);
            //无屏蔽字库
            return;
        }
        SentiWords = AssetsPoolManager.ReadTextFile(textName).Split(splitChar);
        for (int i = 0; i < SentiWords.Length; i++)
        {
            if (SentiWords[i].Contains("\n"))
            {
                SentiWords[i] = SentiWords[i].Replace("\r", "");

                SentiWords[i] = SentiWords[i].Replace("\n", "");
            }
        }
        inputField = transform.GetComponent <InputField>();
    }
Esempio n. 28
0
    private static void Init()
    {
        if (isInit)
        {
            return;
        }
        isInit = true;

        GameObject obj = new GameObject("[AudioGroupSystem]");

        instance = obj.AddComponent <AudioGroupSystem>();

        TextAsset asset = AssetsPoolManager.Load <TextAsset>(ConfigName);

        List <AudioGroupData> datas = JsonUtils.FromJson <List <AudioGroupData> >(asset.text);

        audioGroupDataDic.Clear();
        foreach (var item in datas)
        {
            audioGroupDataDic.Add(item.keyName, item);
        }
    }
Esempio n. 29
0
    private static GameObject GetByPrefabe(string objName, GameObject prefab, GameObject parent = null, bool isSetActive = true)
    {
        GameObject go   = null;
        string     name = objName;

        if (string.IsNullOrEmpty(name))
        {
            name = prefab.name;
        }
        if (IsExist(name))
        {
            go = s_objectPool[name][0];

            s_objectPool[name].RemoveAt(0);
            PoolObject po = go.GetComponent <PoolObject>();
            if (po)
            {
                po.OnFetch();
            }
            AssetsPoolManager.MarkeFlag(name, true);
        }
        else
        {
            if (prefab == null && !string.IsNullOrEmpty(objName))
            {
                go = CreateGameObject(name, parent);
            }
            else if (prefab != null && string.IsNullOrEmpty(objName))
            {
                go = ObjectInstantiate(prefab, parent);
            }
            PoolObject po = go.GetComponent <PoolObject>();
            if (po)
            {
                po.OnCreate();
            }
            if (createPools.ContainsKey(name))
            {
                createPools[name].Add(go);
            }
            else
            {
                createPools.Add(name, new List <GameObject>()
                {
                    go
                });
            }
        }
        if (isSetActive)
        {
            go.SetActive(true);
        }

        if (parent == null)
        {
            go.transform.SetParent(null);
        }
        else
        {
            go.transform.SetParent(parent.transform);
        }

        //go.transform.localScale = Vector3.one;

        return(go);
    }
Esempio n. 30
0
    private static GameObject GetNewObject(bool isAlwaysNew, string objName, GameObject prefab, GameObject parent = null, bool isSetActive = true)
    {
        GameObject go   = null;
        string     name = objName;

        if (string.IsNullOrEmpty(name))
        {
            name = prefab.name;
        }

        if (!isAlwaysNew && IsExist(name))
        {
            go = recyclePools[name][0];
            recyclePools[name].RemoveAt(0);

            AssetsPoolManager.MarkeFlag(name, typeof(GameObject));
        }
        else
        {
            if (prefab == null && !string.IsNullOrEmpty(objName))
            {
                go = NewGameObject(name, parent);
                if (createPools.ContainsKey(name))
                {
                    createPools[name].Add(go);
                }
                else
                {
                    createPools.Add(name, new List <GameObject>()
                    {
                        go
                    });
                }
            }
            else if (prefab != null && string.IsNullOrEmpty(objName))
            {
                go = ObjectInstantiate(prefab, parent);
            }
        }

        PoolObject po = go.GetComponent <PoolObject>();

        if (po)
        {
            try
            {
                po.OnFetch();
            }
            catch (Exception e)
            {
                Debug.LogError("GetNewObject Error: " + e.ToString());
            }
        }

        if (isSetActive)
        {
            go.SetActive(true);
        }

        if (parent == null)
        {
            go.transform.SetParent(null);
        }
        else
        {
            go.transform.SetParent(parent.transform);
        }
        return(go);
    }