Beispiel #1
0
        /// <summary>
        /// 从给出的路径中加载卡片和皮肤,支持通配符,比如“Cards/*.xls”
        /// </summary>
        /// <param name="excelPaths"></param>
        /// <returns></returns>
        public async Task load(string[] excelPaths, Assembly[] assemblies = default, ILogger logger = null, ILogger screenLogger = null)
        {
            //加载内置卡片
            screenLogger?.log("加载内置卡片");
            if (assemblies == default)
            {
                assemblies = AppDomain.CurrentDomain.GetAssemblies();
            }
            List <CardDefine> cardList = new List <CardDefine>(CardHelper.getCardDefines(assemblies, logger));

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

            foreach (var excelPath in excelPaths)
            {
                // 判断文件夹
                if (excelPath.Contains("*") || excelPath.Contains("?"))
                {
                    if (!PlatformCompability.Current.RequireWebRequest)
                    {
                        var pathes = ResourceManager.GetDirectoryFiles(excelPath);
                        // 去重
                        foreach (var item in pathes)
                        {
                            if (!pathList.Contains(item))
                            {
                                pathList.Add(item);
                            }
                        }
                    }
                }
                else
                {
                    if (!pathList.Contains(excelPath))
                    {
                        pathList.Add(excelPath);
                    }
                }
            }

            //加载外置卡片
            foreach (string path in pathList)
            {
                try
                {
                    screenLogger?.log("加载卡片集:" + Path.GetFileNameWithoutExtension(path));

                    CardDefine[] cards = await loadCards(path);

                    foreach (var card in cards)
                    {
                        CardDefine older = cardList.Find(c => c.id == card.id);
                        if (older != null)
                        {
                            older.merge(card);
                            UberDebug.LogDebugChannel("Load", "数据覆盖:" + card.ToJson());
                        }
                        else
                        {
                            cardList.Add(card);
                        }
                    }
                }
                catch (Exception e)
                {
                    UberDebug.LogError("读取外部卡牌文件" + path + "失败,发生异常:" + e);
                }
            }
            foreach (CardDefine card in cardList)
            {
                if (defineDic.ContainsKey(card.id))
                {
                    Debug.LogWarning("存在重复ID的卡片" + defineDic[card.id] + "和" + card);
                    continue;
                }
                defineDic.Add(card.id, card);
            }
            //加载内置皮肤
            skinDic.Clear();
            foreach (CardSkinData skin in _skins)
            {
                if (skin.image == null)
                {
                    skin.image = await getDefaultSprite();
                }
                skinDic.Add(skin.id, skin);
            }
            foreach (string path in pathList)
            {
                try
                {
                    CardSkinData[] skins = await loadSkins(path, logger : screenLogger);

                    foreach (var skin in skins)
                    {
                        if (skinDic.ContainsKey(skin.id))
                        {
                            Debug.LogWarning("存在重复ID的皮肤" + skinDic[skin.id] + "和" + skin);
                            continue;
                        }
                        skinDic.Add(skin.id, skin);
                    }
                }
                catch (Exception e)
                {
                    UberDebug.LogError("读取外部皮肤文件" + path + "失败,发生异常:" + e);
                }
            }
        }
        /// <summary>
        /// 从给出的路径中加载卡片和皮肤
        /// </summary>
        /// <param name="excelPaths"></param>
        /// <returns></returns>
        public async Task Load(string[] excelPaths)
        {
            //加载内置卡片
            Assembly[]        assemblies = AppDomain.CurrentDomain.GetAssemblies();
            List <CardDefine> cardList   = new List <CardDefine>(CardHelper.getCardDefines(assemblies));

            //加载外置卡片
            foreach (string path in excelPaths)
            {
                try
                {
                    CardDefine[] cards = await loadCards(path);

                    foreach (var card in cards)
                    {
                        CardDefine older = cardList.Find(c => c.id == card.id);
                        if (older != null)
                        {
                            older.merge(card);
                        }
                        else
                        {
                            cardList.Add(card);
                        }
                    }
                }
                catch (Exception e)
                {
                    UberDebug.LogError("读取外部卡牌文件" + path + "失败,发生异常:" + e);
                }
            }
            foreach (CardDefine card in cardList)
            {
                if (defineDic.ContainsKey(card.id))
                {
                    Debug.LogWarning("存在重复ID的卡片" + defineDic[card.id] + "和" + card);
                    continue;
                }
                defineDic.Add(card.id, card);
            }
            //加载内置皮肤
            skinDic.Clear();
            foreach (CardSkinData skin in _skins)
            {
                if (skin.image == null)
                {
                    skin.image = await getDefaultSprite();
                }
                skinDic.Add(skin.id, skin);
            }
            foreach (string path in excelPaths)
            {
                try
                {
                    CardSkinData[] skins = await loadSkins(path);

                    foreach (var skin in skins)
                    {
                        if (skinDic.ContainsKey(skin.id))
                        {
                            Debug.LogWarning("存在重复ID的皮肤" + skinDic[skin.id] + "和" + skin);
                            continue;
                        }
                        skinDic.Add(skin.id, skin);
                    }
                }
                catch (Exception e)
                {
                    UberDebug.LogError("读取外部皮肤文件" + path + "失败,发生异常:" + e);
                }
            }
        }