Ejemplo n.º 1
0
        private void OnNormalTxtLoaded(Object[] objs, string[] assetNames, string assetPath)
        {
            if (objs == null || objs.Length < 1 || assetNames == null || assetNames.Length != objs.Length)
            {
                UnityEngine.Debug.LogError("Load " + assetPath + " failed.");
                return;
            }

            for (int i = 0; i < objs.Length; i++)
            {
                Object obj       = objs[i];
                string assetName = CUtil.ConvertFileNameForAssetbundle(assetNames[i]);
                if (!string.IsNullOrEmpty(assetName))
                {
                    if (!m_preLoadedTxt.ContainsKey(assetName))
                    {
                        m_preLoadedTxt.Add(assetName, obj);
                    }
                    else
                    {
                        UnityEngine.Debug.LogError(string.Format("{0} duplicate in {1}", assetName, "preLoadedTxt"));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public stResourcePath GetResourcePath(string dir, string name, string extension, bool bLevel = false, string pathPrifix = IcConfig.PathAssetResources)
        {
            bool   bAssetbundle = false;
            string path         = null;
            Object asset        = null;
            int    ver          = 0;

            string assetbundlePath = pathPrifix + dir + name;

            if (!string.IsNullOrEmpty(extension))
            {
                assetbundlePath += "_" + extension;
            }

            assetbundlePath = assetbundlePath.ToLower();//打出去的assetbundle路径是小写
            if (dir.Contains("TableBinary"))
            {
                assetbundlePath = CUtil.ConvertFileNameForAssetbundle(assetbundlePath);
            }
            else
            {
                assetbundlePath = CUtil.ConvertFileNameForAssetbundleMd5(assetbundlePath);
            }

            if (m_mapResourceVer.TryGetValue(assetbundlePath, out ver))
            {
                bAssetbundle = true;
                path         = assetbundlePath;//assetbundle资源路径

                //specialVer的特殊处理
                if (ver < 0)
                {
                    if (ver == -2)
                    {
                        if (!m_preLoadedTxt.TryGetValue(assetbundlePath, out asset))
                        {
                            UnityEngine.Debug.LogError(assetbundlePath + " not found in preLoadedSceneTxt.");
                        }
                    }
                    //todo other ver process...
                    else
                    {
                        //others
                        //ver == -1
                        if (!m_preLoadedAssets.TryGetValue(assetbundlePath, out asset))
                        {
                            UnityEngine.Debug.LogError(assetbundlePath + " not found in preLoaded resource.");
                        }
                    }
                }
            }
            else
            {
                bAssetbundle = false;
                if (bLevel)
                {
                    path = name;//场景, 直接返回name就行了
                }
                else
                {
                    //The path is relative to any Resources folder inside the Assets folder of your project
                    //, extensions must be omitted
                    path = dir + name;//Resource里的路径
                }
            }

            return(new stResourcePath(path, bAssetbundle, ver, assetbundlePath, asset));
        }