public ResName GetResName(string assetName, string abName)
        {
            if (string.IsNullOrEmpty(assetName) && string.IsNullOrEmpty(abName))
            {
                return(null);
            }

            //file name should keep letter case
            if (!string.IsNullOrEmpty(assetName) && ResName.NotABAsset(assetName))
            {
                int index = assetName.LastIndexOf('.');
                if (index < 0)
                {
                    return(new ResName(null, assetName, null));
                }
                return(new ResName(null, assetName.Substring(0, index), assetName.Substring(index)));
            }

            if (!string.IsNullOrEmpty(assetName))
            {
                assetName = assetName.ToLower();
            }
            if (!string.IsNullOrEmpty(abName))
            {
                abName = abName.ToLower();
            }

            ResName resName = null;
            SearchResNameFailInfo failInfo = null;

            for (int i = 0; i < mResGroups.Count; i++)
            {
                resName = mResGroups[i].GetResName(assetName, abName, out failInfo);
                if (resName != null)
                {
                    return(resName);
                }

                if (failInfo.FailType == SearchResNameFailInfo.NAME_AMBIGUOUS)
                {
                    throw new Exception(string.Format(failInfo.ToString(), assetName));
                }
            }
            if (failInfo.FailType == SearchResNameFailInfo.NOTFOUND_AB)
            {
                throw new Exception(string.Format(failInfo.ToString(), abName));
            }
            if (failInfo.FailType == SearchResNameFailInfo.NOTFOUND_ASSET)
            {
                throw new Exception(string.Format(failInfo.ToString(), assetName));
            }
            return(null);
        }
Beispiel #2
0
        public ResName GetResName(string assetName, string abName, out SearchResNameFailInfo failInfo)
        {
            failInfo = null;

            if (string.IsNullOrEmpty(assetName))
            {
                ResName resName;
                if (mABDict.TryGetValue(abName, out resName))
                {
                    return(resName);
                }

                failInfo = new SearchResNameFailInfo(SearchResNameFailInfo.NOTFOUND_AB);
                return(null);
            }

            string nameWithoutExt = assetName;
            string ext            = null;
            int    index          = assetName.LastIndexOf('.');

            if (index > 0)
            {
                nameWithoutExt = assetName.Substring(0, index);
                ext            = assetName.Substring(index);
            }

            List <ResName> resList;

            if (!mAssetDict.TryGetValue(nameWithoutExt, out resList))
            {
                failInfo = new SearchResNameFailInfo(SearchResNameFailInfo.NOTFOUND_ASSET);
                return(null);
            }

            ResName result = null;

            foreach (ResName resName in resList)
            {
                if (!string.IsNullOrEmpty(abName) && !abName.Equals(resName.ABName, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(ext) && !ext.Equals(resName.Extension, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (result != null)
                {
                    failInfo = new SearchResNameFailInfo(SearchResNameFailInfo.NAME_AMBIGUOUS);
                    return(null);
                }

                result = resName;
            }
            if (result == null)
            {
                failInfo = new SearchResNameFailInfo(SearchResNameFailInfo.NOTFOUND_ASSET);
            }

            return(result);
        }