예제 #1
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));
        }