public AssetConfig LoadConfig(Type configType, string location)
        {
            string configName = Path.GetFileName(location);

            // 防止重复加载
            if (_configs.ContainsKey(configName))
            {
                MotionLog.Error($"Config {configName} is already existed.");
                return(null);
            }

            AssetConfig config = Activator.CreateInstance(configType) as AssetConfig;

            if (config != null)
            {
                config.Load(location);
                _configs.Add(configName, config);
            }
            else
            {
                MotionLog.Error($"Config {configType.FullName} create instance  failed.");
            }

            return(config);
        }
Exemple #2
0
 /// <summary>
 /// 按照表格顺序异步加载所有表格
 /// </summary>
 public IEnumerator LoadConfigs(List <string> locations)
 {
     for (int i = 0; i < locations.Count; i++)
     {
         string      location = locations[i];
         AssetConfig config   = LoadConfig(location);
         yield return(config);
     }
 }
Exemple #3
0
 /// <summary>
 /// 按照列表顺序批量加载配表
 /// </summary>
 public IEnumerator LoadConfigs(List <LoadPair> loadPairs)
 {
     for (int i = 0; i < loadPairs.Count; i++)
     {
         Type        type     = loadPairs[i].ClassType;
         string      location = loadPairs[i].Location;
         AssetConfig config   = LoadConfig(type, location);
         yield return(config);
     }
 }
Exemple #4
0
        public static AssetConfig Handle(string configName)
        {
            AssetConfig config = null;

            Type type;

            if (_cfgTypes.TryGetValue(configName, out type))
            {
                config = (AssetConfig)Activator.CreateInstance(type);
            }

            if (config == null)
            {
                throw new KeyNotFoundException($"AssetConfig {configName} is not define.");
            }

            return(config);
        }
        /// <summary>
        /// 加载配表
        /// </summary>
        /// <param name="configName">配表文件名称</param>
        public AssetConfig LoadConfig(string configName)
        {
            // 防止重复加载
            if (_configs.ContainsKey(configName))
            {
                MotionLog.Log(ELogLevel.Error, $"Config {configName} is already existed.");
                return(null);
            }

            AssetConfig config = ConfigCreater.CreateInstance(configName);

            if (config != null)
            {
                string location = $"{_baseDirectory}/{configName}";
                config.Load(location);
                _configs.Add(configName, config);
            }
            else
            {
                MotionLog.Log(ELogLevel.Error, $"Config type {configName} is invalid.");
            }
            return(config);
        }
Exemple #6
0
        /// <summary>
        /// 加载配表
        /// </summary>
        /// <param name="cfgName">配表文件名称</param>
        public void Load(string cfgName, System.Action <AssetConfig> callback)
        {
            // 防止重复加载
            if (_cfgs.ContainsKey(cfgName))
            {
                LogSystem.Log(ELogType.Error, $"Config {cfgName} is already exist.");
                return;
            }

            AssetConfig config = ConfigHandler.Handle(cfgName);

            if (config != null)
            {
                string location = BaseFolderPath + cfgName;
                _cfgs.Add(cfgName, config);
                config.Init(location);
                config.Load(callback);
            }
            else
            {
                LogSystem.Log(ELogType.Error, $"Config {cfgName} calss is invalid.");
            }
        }