Exemple #1
0
        private IEnumerator LoadResData()
        {
            string filePath = PathTool.DataFileRootFold + "/common/Res.csv";

            resCsvfile = new CSVFile();
            resCsvfile.ReadCsv(filePath);
            foreach (string[] arr in resCsvfile.valueLines)
            {
                if (arr.Length != 7)
                {
                    continue;
                }
                int      id           = int.Parse(arr[0]);
                string   alias        = arr[1];
                EResType type         = (EResType)int.Parse(arr[2]);
                bool     inInspector  = bool.Parse(arr[3]);
                string   respath      = arr[4]; // Resouce.load 时路径
                string   bundlepath   = arr[5];
                string   inbundlepath = arr[6];
                if (inInspector)
                {
                    continue;             //已经在Inspector,不需要加载
                }
            }
            hasInitAllData = true;
            yield return(null);
        }
Exemple #2
0
    static int PreloadResource(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Object), typeof(int)))
            {
                UnityEngine.Object arg0 = (UnityEngine.Object)ToLua.ToObject(L, 1);
                int arg1 = (int)LuaDLL.lua_tonumber(L, 2);
                ObjectPoolManager.PreloadResource(arg0, arg1);
                return(0);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(ObjectPoolManager), typeof(string), typeof(int), typeof(EResType)))
            {
                ObjectPoolManager obj  = (ObjectPoolManager)ToLua.ToObject(L, 1);
                string            arg0 = ToLua.ToString(L, 2);
                int      arg1          = (int)LuaDLL.lua_tonumber(L, 3);
                EResType arg2          = (EResType)ToLua.ToObject(L, 4);
                obj.PreloadResource(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: ObjectPoolManager.PreloadResource"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemple #3
0
 /// <summary>
 /// Load Texture 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="t"></param>
 /// <returns></returns>
 static public NoramlResOperation LoadNormalAssetAsync(string name, EResType t)
 {
     NoramlResOperation operation = new NoramlResOperation(name);
     m_InProgressOperations.Add(operation);
     LoadNormalRes(name, t);
     return operation;
 }
Exemple #4
0
    internal UnityEngine.Object GetSharedResource(string res, EResType ResGroup, Action <UnityEngine.Object[]> func = null)
    {
        UnityEngine.Object obj     = null;
        string             abName  = string.Empty;
        string             resName = string.Empty;

        UnityEngine.Object retObj = null;
        if (string.IsNullOrEmpty(res))
        {
            return(obj);
        }
        if (kLoadedPrefabs.ContainsKey(res))
        {
            retObj = kLoadedPrefabs[res];
        }
        else
        {
            string ResName       = ResDefine.GetResourceType(ResGroup);
            string ResFolderName = ResName + "/";
            string abPath        = string.Empty;
            if (AppConst.PublishMode)
            {
                abName = string.Empty;
                abPath = Path.GetDirectoryName(res);
                if (string.IsNullOrEmpty(abPath))
                {
                    abName = ResFolderName + ResName + ResDefine.ExtName;
                }
                else
                {
                    abPath = abPath.Replace("/", "_");
                    abName = ResFolderName + abPath + ResDefine.ExtName;
                }
                resName = Path.GetFileName(res);
                obj     = AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader).LoadAsset <UnityEngine.Object>(abName, resName);
            }
            if (obj == null)
            {
                abPath = ResFolderName + res;
                obj    = Resources.Load(abPath);
            }
            if (obj != null)
            {
                retObj = UnityEngine.Object.Instantiate(obj);

                kLoadedPrefabs.Add(res, retObj);
                AssetsLoaderManager assetLoader = AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader);
                if (assetLoader != null)
                {
                    assetLoader.UnloadSyncAssetBundle(abName);
                }
            }
            else
            {
                UnityEngine.Debug.LogWarning("LoadAsset failed abpath:" + abName);
                UnityEngine.Debug.LogWarning("LoadAsset failed abName:" + resName);
            }
        }
        return(retObj);
    }
    public static IResLoader GetLoader(EResType type)
    {
        if (!m_loaderPool.ContainsKey(type))
        {
            m_loaderPool[type] = new Queue <IResLoader>();
        }

        if (m_loaderPool[type].Count > 0)
        {
            return(m_loaderPool[type].Dequeue());
        }
        else
        {
            switch (type)
            {
            case EResType.MODEL:
            case EResType.UI:
                return(new ResourcesResLoader <GameObject>());

            case EResType.TEXTURE:
            case EResType.ICON:
                return(new ResourcesResLoader <Texture>());

            case EResType.SOUND:
                return(new ResourcesResLoader <AudioClip>());

            default:
                return(null);
            }
        }
    }
Exemple #6
0
    static int GetSharedResource(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 3);
            string   arg0 = ToLua.CheckString(L, 1);
            EResType arg1 = (EResType)ToLua.CheckObject(L, 2, typeof(EResType));
            System.Action <UnityEngine.Object[]> arg2 = null;
            LuaTypes funcType3 = LuaDLL.lua_type(L, 3);

            if (funcType3 != LuaTypes.LUA_TFUNCTION)
            {
                arg2 = (System.Action <UnityEngine.Object[]>)ToLua.CheckObject(L, 3, typeof(System.Action <UnityEngine.Object[]>));
            }
            else
            {
                LuaFunction func = ToLua.ToLuaFunction(L, 3);
                arg2 = DelegateFactory.CreateDelegate(typeof(System.Action <UnityEngine.Object[]>), func) as System.Action <UnityEngine.Object[]>;
            }

            UnityEngine.Object o = ObjectPoolManager.GetSharedResource(arg0, arg1, arg2);
            ToLua.Push(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemple #7
0
 /// <summary>
 /// 设置资源类型
 /// </summary>
 /// <param name="type"></param>
 public void SetType(EResType type)
 {
     //资源一旦被设置过非空类型,则不可再设置回空,除非清除
     if (type != EResType.None)
     {
         m_type = type;
     }
 }
Exemple #8
0
    static public string GetResourceType(EResType eResourceGroup)
    {
        switch (eResourceGroup)
        {
        case EResType.eResAudio:
            return("Audio");

        case EResType.eResEffect:
            return("Effect");

        case EResType.eResUI:
            return("UI");

        case EResType.eResCharacter:
            return("Character");

        case EResType.eResModel:
            return("Model");

        case EResType.eResBoss:
            return("Boss");

        case EResType.eResPicture:
            return("Picture");

        case EResType.eResMonster:
            return("Monster");

        case EResType.eResPet:
            return("Pet");

        case EResType.eResUIEffect:
            return("UIEffect");

        case EResType.eResScene:
            return("scenes");

        case EResType.eResFont:
            return("Font");

        case EResType.eResShader:
            return("shader");

        case EResType.eResMaterial:
            return("Materials");

        case EResType.eResTexure:
            return("Texture");

        case EResType.eResDataTable:
            return("DataTable");

        case EResType.eResSceneElemt:
            return("SceneRes");
        }
        return("");
    }
Exemple #9
0
		// Where we actuall call WWW to download the assetBundle.
		static protected bool LoadResInternal (string assetBundleName, EResType t, bool isLoadingAssetBundleManifest)
		{
			// Already loaded.
			LoadedWWW bundle = null;
			m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
			if (bundle != null)
			{
				bundle.m_ReferencedCount++;
				return true;
			}
	
			// @TODO: Do we need to consider the referenced count of WWWs?
			// In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
			// But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
			if (m_DownloadingWWWs.ContainsKey(assetBundleName) )
				return true;
	
			WWW download = null;
            string url = null;
            switch (t)
            {
                case EResType.E_AssetBundle:
                  url =   m_BaseDownloadingURL + "/assetbundle/" +assetBundleName;
                    break;
                case EResType.E_TEXTURE:
                    url = m_BaseDownloadingURL + "/texture/" +assetBundleName;
                    break;
                case EResType.E_BYTE:
                    url = m_BaseDownloadingURL + "/config/" + assetBundleName;
                    break;
                case EResType.E_TXT:
                    url = m_BaseDownloadingURL + "/config/" + assetBundleName;
                    break;
                case EResType.E_AudioClip:
                    url = m_BaseDownloadingURL + "/sound/" + assetBundleName;
                    break;
                default:
                    break;
            }
          
            //Debug.Log(url);
            // For manifest assetbundle, always download it as we don't have hash for it.
            if (isLoadingAssetBundleManifest)
                download = new WWW(url);
            else
            {
                //yadoutodo
                //   download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0);
                download = new WWW(url);
            }
			m_DownloadingWWWs.Add(assetBundleName, new WWWLoadInfo(download,t));
	
			return false;
		}
Exemple #10
0
 internal void PreloadSharedResource(string res, EResType restype)
 {
     UnityEngine.Object prefab = GetSharedResource(res, restype);
     if (null != prefab)
     {
         if (!kPreloadResources.Contains(res))
         {
             kPreloadResources.Add(res);
         }
     }
 }
Exemple #11
0
 static public string GetResPath(EResType eResourceGroup)
 {
     if (kDictResPath.Count < 1)
     {
         Init();
     }
     if (kDictResPath.ContainsKey(eResourceGroup))
     {
         return(kDictResPath[eResourceGroup]);
     }
     return(null);
 }
Exemple #12
0
        protected virtual void OnGUI()
        {
            GUILayout.BeginHorizontal();
            resType = (EResType)EditorGUILayout.EnumPopup("资源目录", resType, GUILayout.MaxWidth(250));
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            EditorGUILayout.ObjectField("SelectedShader", m_SelectShader, typeof(Shader), true, GUILayout.MaxWidth(450));
            if (GUILayout.Button("Scan", GUILayout.MaxWidth(150)))
            {
                string resPath = resPaths[(int)resType];
                FindMat(resPath);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            shaderScrollPos = GUILayout.BeginScrollView(shaderScrollPos, false, false);

            Dictionary <Shader, List <Material> > .Enumerator it = m_Shaders.GetEnumerator();
            while (it.MoveNext())
            {
                GUILayout.BeginHorizontal();
                Shader shader = it.Current.Key;
                EditorGUILayout.ObjectField(it.Current.Value.Count.ToString(), shader, typeof(Shader), true, GUILayout.MaxWidth(450));
                if (GUILayout.Button("Select", GUILayout.MaxWidth(50)))
                {
                    m_SelectShader = shader;
                    m_Materials    = it.Current.Value;
                }
                GUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            materialScrollPos = GUILayout.BeginScrollView(materialScrollPos, false, false);
            if (m_Materials != null)
            {
                for (int i = 0; i < m_Materials.Count; ++i)
                {
                    GUILayout.BeginHorizontal();
                    Material mat = m_Materials[i];
                    EditorGUILayout.ObjectField("", mat, typeof(Material), true, GUILayout.MaxWidth(450));
                    GUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.EndScrollView();
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
Exemple #13
0
 static int PreloadSharedResource(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         string   arg0 = ToLua.CheckString(L, 1);
         EResType arg1 = (EResType)ToLua.CheckObject(L, 2, typeof(EResType));
         ObjectPoolManager.PreloadSharedResource(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemple #14
0
        /// <summary>
        /// 底层加载函数,异步加载unity压缩过的AssetBundle,或者同步加载Resources类型
        /// </summary>
        /// <param name="newPath">相对于Resources路径下的资源路径</param>
        /// <param name="callBack">回调函数的参数为ResourceItem对象,可以详细拿到AB中的所有Asset</param>
        /// <param name="type">分类标签</param>
        /// <param name="saveAssetBundle">是否保存AssetBundle对象不卸载,可以保留依赖关系</param>
        /// <param name="clearAfterLoaded">加载完成后清除自己的缓存</param>
        public static void LoadCore(string path, Action <ResourceItem> callBack, EResType type = EResType.None, bool saveAssetBundle = false, bool clearAfterLoaded = false, bool dependLoad = true, bool needCRC = false, int tag = 0, bool isImage = false)
        {
            //LoggerHelper.Error("LoadCore: " + path + saveAssetBundle + clearAfterLoaded);
            var isMainifest = IsManifest(path);

            if (!isMainifest && !IsInit)
            {
                Debug.LogError("has not init mainifest, can not load item: " + path);
                return;
            }
            string newPath  = path.ToLower();
            string savePath = "";

            # region isImage
            if (isImage)
Exemple #15
0
    protected IEnumerator LoadAssetResAsync(string name, EResType t, System.Action <NormalRes> completeCallback)
    {
        NoramlResOperation request = AssetManager.LoadNormalAssetAsync(name, t);

        if (request == null)
        {
            yield break;
        }
        yield return(StartCoroutine(request));

        if (null != request.m_loaded)
        {
            completeCallback(request.m_loaded.m_normalres);
        }
    }
Exemple #16
0
 /// <summary>
 /// 用来给预加载的资源方便用
 /// </summary>
 /// <param name="path"></param>
 /// <param name="type"></param>
 /// <param name="tag"></param>
 public ResourceItem(string path, EResType type, int tag = 0)
 {
     m_path            = path;
     m_saveAssetBundle = type == EResType.Atlas || type == EResType.Font || type == EResType.Shader;
     SetType(type);
     m_clearAfterLoaded = false;
     m_bNeedCRC         = type == EResType.BattlePrefab;
     if (m_saveAssetBundle)
     {
         AddTags(ResTag.AssetBundle);
     }
     if (tag != 0)
     {
         AddTags(tag);
     }
 }
Exemple #17
0
    private IResLoader GetLoader(string path, EResType type)
    {
        IResLoader loader;

        if (!m_activeLoader.ContainsKey(path))
        {
            loader = ResLoaderFactory.GetLoader(type);
            loader.SetResPath(path, type);
        }
        else
        {
            loader = m_activeLoader[path];
        }

        return(loader);
    }
Exemple #18
0
    public void GetRes(string name, EResType type, ResCallBack callback, object param)
    {
        string path = ResUtility.GetResRelativePath(type) + name;

        if (m_resPool.ContainsKey(path))
        {
            callback(m_resPool[path], param);
        }
        else
        {
            IResLoader loader = GetLoader(path, type);
            loader.AddCallBack(callback, param);

            m_activeLoader[path] = loader;

            loader.StartLoad();
        }
    }
Exemple #19
0
    /// <summary>
    /// 处理资源assetbundle
    /// </summary>
    static void HandleResourceBundle()
    {
        string resPath = AppDataPath + "/" + AppConst.AssetDir + "/";

        if (!Directory.Exists(resPath))
        {
            Directory.CreateDirectory(resPath);
        }

        for (int i = 0; i < (int)EResType.eResCount; i++)
        {
            EResType kResGroup = (EResType)i;
            if (kResGroup != EResType.eResScene && kResGroup != EResType.eSceneLoadRes)
            {
                HandleResourceBundle(kResGroup);
            }
        }
    }
Exemple #20
0
    protected IEnumerator LoadNormalResAsync(string name, EResType t, System.Action <NormalRes> onloaded, System.Action <string> errload)
    {
        NoramlResOperation request = AssetManager.LoadNormalAssetAsync(name, t);

        if (request == null)
        {
            yield break;
        }
        yield return(StartCoroutine(request));

        if (null != request.m_loaded)
        {
            onloaded(request.m_loaded.m_normalres);
        }
        else
        {
            if (null != errload)
            {
                errload(name);
            }
        }
    }
Exemple #21
0
 /// <summary>
 /// 清除数据
 /// </summary>
 public void Clear(bool unloadAllLoadedObjects = false)
 {
     m_mainAsset     = null;
     m_mainAssetName = null;
     m_assets        = null;
     m_assetsName    = null;
     if (m_assetBundle != null)
     {
         m_assetBundle.Unload(false);
     }
     m_assetBundle = null;
     m_path        = null;
     if (m_callBackFunc != null)
     {
         m_callBackFunc.Clear();
     }
     m_callBackFunc = null;
     m_type         = EResType.None;
     m_tags         = 0;
     m_bNeedCRC     = false;
     m_CRC          = 0;
 }
Exemple #22
0
    static void HandleResourceBundle(EResType eResType)
    {
        EResType kResGroup = eResType;
        string   path      = ResDefine.GetResPath(kResGroup);

        if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
        {
            return;
        }
        string ResName       = ResDefine.GetResourceType(kResGroup);
        string ResFolderName = ResName + "/";
        string Dirpath       = "";

        List <string> kExtList = new List <string>();

        ResDefine.GetResTypeFileExtList(kResGroup, ref kExtList);


        string[] dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories);
        for (int j = 0; j < dirs.Length; j++)
        {
            string fPath = path;
            if (target == BuildTarget.iOS)
            {
                fPath = path + "/";
            }
            string name = dirs[j].Replace(fPath, string.Empty).TrimStart(new char[] { '\\' });
            name = name.Replace('\\', '_').Replace('/', '_');
            name = name.ToLower() + ResDefine.ExtName;

            Dirpath = "Assets" + dirs[j].Replace(Application.dataPath, "");
            AddBuildMap(ResFolderName + name, kExtList, Dirpath);
        }
        if (kResGroup != EResType.eResScene)  //资源根目录打包
        {
            string DirName = Path.GetFileName(path);
            AddBuildMap(ResFolderName + DirName + ResDefine.ExtName, kExtList, "Assets" + path.Replace(Application.dataPath, ""));
        }
    }
Exemple #23
0
    private static string GetFolderPath(EResType type)
    {
        switch (type)
        {
        case EResType.ICON:
            return("Icon");

        case EResType.MODEL:
            return("Model");

        case EResType.SOUND:
            return("Sound");

        case EResType.TEXTURE:
            return("Texture");

        case EResType.UI:
            return("UI");

        default:
            return("");
        }
    }
Exemple #24
0
 public static UnityEngine.Object GetSharedResource(string res, EResType restype, Action <UnityEngine.Object[]> func = null)
 {
     return(ObjectPoolSystem.Instance.GetSharedResource(res, restype, func));
 }
Exemple #25
0
 public static void NewObject(string res, EResType resType, float timeToRecycle, float timeToDestroy, Action <UnityEngine.Object> func = null)
 {
     ObjectPoolSystem.Instance.NewObject(res, resType, timeToRecycle, timeToDestroy, func);
 }
Exemple #26
0
 public static void Clear(EResType resType, bool clearDepend = false)
 {
     LoadResources.Clear(resType, clearDepend);
 }
Exemple #27
0
 public static void PreloadSharedResource(string res, EResType restype)
 {
     ObjectPoolSystem.Instance.PreloadSharedResource(res, restype);
 }
Exemple #28
0
 public static void NewObject(string res, EResType resType, Action <UnityEngine.Object> func = null)
 {
     ObjectPoolSystem.Instance.NewObject(res, resType, func);
 }
Exemple #29
0
 internal void NewObject(string res, EResType resType, Action <UnityEngine.Object> func = null)
 {
     NewObject(res, resType, 0, 60, func);
 }
Exemple #30
0
    internal void NewObject(string res, EResType resType, float timeToRecycle, float timeToDestory, Action <UnityEngine.Object> func = null)
    {
        UnityEngine.Object obj     = null;
        UnityEngine.Object retObj  = null;
        string             abName  = string.Empty;
        string             resName = string.Empty;

        if (kLoadedPrefabs.ContainsKey(res) && kLoadedPrefabs[res] != null)
        {
            obj = kLoadedPrefabs[res];
            if (obj != null)
            {
                retObj = NewObject(res, obj, timeToRecycle, timeToDestory);
                if (func != null)
                {
                    func(retObj);
                }
            }
        }
        else
        {
            string ResName       = ResDefine.GetResourceType(resType);
            string ResFolderName = ResName + "/";
            string abPath        = string.Empty;
            if (AppConst.PublishMode && resType != EResType.eSceneLoadRes)
            {
                abName = string.Empty;
                abPath = Path.GetDirectoryName(res);
                if (string.IsNullOrEmpty(abPath))
                {
                    abName = ResFolderName + ResName + ResDefine.ExtName;
                }
                else
                {
                    abPath = abPath.Replace("/", "_");
                    abName = ResFolderName + abPath + ResDefine.ExtName;
                }
                resName = Path.GetFileName(res);
                AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader).LoadAsset(abName, resName, delegate(UnityEngine.Object[] uObj)
                {
                    if (uObj == null || uObj[0] == null)
                    {
                        UnityEngine.Debug.LogWarning("LoadAsset failed abpath:" + abName);
                        UnityEngine.Debug.LogWarning("LoadAsset failed abName:" + resName);
                    }
                    else
                    {
                        retObj = NewObject(res, uObj[0], timeToRecycle, timeToDestory);
                        if (func != null)
                        {
                            func(retObj);
                        }
                        if (!kLoadedPrefabs.ContainsKey(res))
                        {
                            kLoadedPrefabs.Add(res, retObj);
                        }
                    }
                }
                                                                                                        );
            }
            else
            {
                if (obj == null)
                {
                    abPath = ResFolderName + res;
                    // obj = Resources.Load(abPath);
                    AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader).LoadRes(abPath, delegate(UnityEngine.Object uObj)
                    {
                        if (uObj == null)
                        {
                            UnityEngine.Debug.LogWarning("LoadAsset failed abpath:" + abName);
                            UnityEngine.Debug.LogWarning("LoadAsset failed abName:" + resName);
                        }
                        retObj = NewObject(res, uObj, timeToRecycle, timeToDestory);
                        if (func != null)
                        {
                            func(retObj);
                        }
                        if (!kLoadedPrefabs.ContainsKey(res))
                        {
                            kLoadedPrefabs.Add(res, retObj);
                        }
                    });
                }
            }
        }
    }
Exemple #31
0
 public static void LoadTexture(string name, Action<Texture2D> callBack, EResType restype = EResType.Texture)
 {
     LoadResources.LoadCore(name, res => callBack(res.MainAsset as Texture2D), restype);
 }
Exemple #32
0
 public void PreloadResource(string res, int count, EResType resTpye)
 {
     ObjectPoolSystem.Instance.PreloadResource(res, count, resTpye);
 }
Exemple #33
0
 /// <summary>
 /// 清除指定类型的资源缓存
 /// </summary>
 /// <param name="resType"></param>
 /// <param name="clearDepend"></param>
 public static void Clear(EResType resType, bool clearDepend = false)
 {
     var delList = new List<string>();
     var list = new Queue<string>();
     foreach (var resourceItem in m_resourceItemDic)
     {
         if (resourceItem.Value.Type == resType)
         {
             var path = resourceItem.Value.Path;
             //Debug.LogError("before: " + path);
             if (resType == EResType.Texture)
             {
                 var assetName = getImagAssetName(resourceItem.Value.Path);
                 path = getImagePath(assetName);
             }
             //Debug.LogError("after: " + path);
             delList.Add(path);
             if (clearDepend)
             {
                 list.Clear();
                 GetAllDependResources(resourceItem.Value.Path, list);
                 delList.AddRange(list);
             }
         }
     }
     for (int i = 0; i < delList.Count; i++)
     {
         if (m_resourceItemDic.ContainsKey(delList[i]))
         {
             m_resourceItemDic[delList[i]].Clear();
             m_resourceItemDic.Remove(delList[i]);
             i--;
         }
     }
     delList.Clear();
 }
Exemple #34
0
        /// <summary>
        /// 底层加载函数,异步加载unity压缩过的AssetBundle,或者同步加载Resources类型
        /// </summary>
        /// <param name="newPath">相对于Resources路径下的资源路径</param>
        /// <param name="callBack">回调函数的参数为ResourceItem对象,可以详细拿到AB中的所有Asset</param>
        /// <param name="type">分类标签</param>
        /// <param name="saveAssetBundle">是否保存AssetBundle对象不卸载,可以保留依赖关系</param>
        /// <param name="clearAfterLoaded">加载完成后清除自己的缓存</param>
        public static void LoadCore(string path, Action<ResourceItem> callBack, EResType type = EResType.None, bool saveAssetBundle = false, bool clearAfterLoaded = false, bool dependLoad = true, bool needCRC = false, int tag = 0, bool isImage = false)
        {
            //LoggerHelper.Error("LoadCore: " + path + saveAssetBundle + clearAfterLoaded);
            var isMainifest = IsManifest(path);
            if (!isMainifest && !IsInit)
            {
                Debug.LogError("has not init mainifest, can not load item: " + path);
                return;
            }
            string newPath = path.ToLower();
            string savePath = "";
            # region isImage
            if (isImage)
            {
                string assetName = getImagAssetName(newPath);
                if (string.IsNullOrEmpty(assetName))
                {
                    Debug.LogError("LoadImageAssets, url error: " + newPath);
                    return;
                }

                savePath = getImagSavePath(newPath);

                if (!m_resourceItemDic.ContainsKey(assetName))
                {
                    //先从本地加载图片
                    //Debug.LogError("savePath: " + savePath);
                    if (string.IsNullOrEmpty(savePath))
                    {
                        Debug.LogError("LoadImageAssets, url error 2: " + newPath);
                        return;
                    }

            #if UNITY_WEBPLAYER
                ResourceItem itemNew = new ResourceItem(path, saveAssetBundle);
            #else
                    FileInfo fi = new FileInfo(savePath);
                    //创建缓存保存目录
                    if (!fi.Directory.Exists)
                        fi.Directory.Create();
                    ResourceItem itemNew;
                    if (!fi.Exists)
                    {
                        //如果本地文件不存在,说明是个网络地址
                        itemNew = new ResourceItem(newPath, saveAssetBundle);
                    }
                    else
                    {
                        itemNew = new ResourceItem("file:///" + savePath, saveAssetBundle);
                    }
            #endif
                    itemNew.NeedCRC = needCRC;
                    itemNew.AddTags(tag);
                    m_resourceItemDic.Add(assetName, itemNew);
                }

                newPath = assetName;
            }
            # endregion

            bool hasContains = false;

            if (!m_resourceItemDic.ContainsKey(newPath))
            {
                var itemNew = new ResourceItem(path, saveAssetBundle);
                itemNew.NeedCRC = needCRC;
                itemNew.AddTags(tag);
                m_resourceItemDic.Add(newPath, itemNew);
            }
            else
            {
                hasContains = !isImage;
                if (hasContains)
                {
                    Debug.Log("hascontains: " + newPath);
                }
            }

            var item = m_resourceItemDic[newPath];
            item.SetType(type);
            item.IsClearAfterLoaded = clearAfterLoaded;
            if (!hasContains && !item.IsLoaded)
            {
                if (dependLoad && IsInit)
                {
                    //Debug.LogError("bb: " + item.Path);
                    var dependList = AssetBundleManifestObject.GetAllDependencies(item.Path.ToLower());
                    List<string> distinctList = new List<string>();
                    for (int i = 0; i < dependList.Length; i++)
                    {
                        if (m_resourceItemDic.ContainsKey(dependList[i]))
                        {
                            Debug.Log("contains depend, path: " + item.Path + "------- file: " + dependList[i]);
                        }
                        else
                        {
                            Debug.Log("not contains depend, path: " + item.Path + "------- file: " + dependList[i]);
                            distinctList.Add(dependList[i]);
                        }
                    }
                    //LoadMulti(distinctList.ToArray(), null, () => GlobalDelegate.Instance.View.StartCoroutine(BeginAssetBundleLoadAsync(item)));
                    LoadMulti(distinctList.ToArray(), null, () => beginLoadItem(item));
                }
                else if (isImage)
                {
                    GlobalDelegate.Instance.View.StartCoroutine(BeginImageLoadAsync(item, savePath));
                }
                else
                {
                    //GlobalDelegate.Instance.View.StartCoroutine(BeginAssetBundleLoadAsync(item));
                    beginLoadItem(item);
                }
            }

            item.AddCallBackFunc(callBack);
            if (item.IsCompleted)
            {
                item.LaunchCallBack();
            }
        }
Exemple #35
0
 public static ResourceItem LoadCore(string path, EResType type = EResType.None)
 {
     if (m_resourceItemDic.ContainsKey(path))
     {
         var item = m_resourceItemDic[path];
         item.SetType(type);
         return item;
     }
     return null;
 }