Exemplo n.º 1
0
        private TConfig[] LoadCfg()
        {
            string path  = ConfigMgr.CfgPath + "/" + GetName() + ".csv";
            Excel  excel = new Excel(2);

            if (!excel.Load(path))
            {
                return(null);
            }

            ICfgDecoder decoder = ConfigMgr.GetDecoder(GetName());

            if (decoder == null)
            {
                m_logger.LogError(GetName() + "的Decoder没有找到!", "BaseDao_UseXML.LoadCfg");
                return(null);
            }

            if (!decoder.Decode(excel))
            {
                return(null);
            }

            BaseCfgData <TConfig> data = decoder.Data as BaseCfgData <TConfig>;

            if (data == null)
            {
                m_logger.LogError("data == null, dao = " + this, "BaseDao_UseXML.LoadCfg");
                return(null);
            }

            return(data.Data);
        }
Exemplo n.º 2
0
    /// <summary>
    /// 给所列表中的配置文件编码
    /// </summary>
    /// <param name="decoders"></param>
    /// <returns></returns>
    public static void EncodeCfgs(Type[] decoders)
    {
        foreach (Type decoderType in decoders)
        {
            ICfgDecoder decoder = Activator.CreateInstance(decoderType) as ICfgDecoder;
            if (decoder == null)
            {
                Debug.LogError("decoder == null, type = " + decoderType);
                continue;
            }

            if (!decoder.Enable)
            {
                continue;
            }

            ICfgReader reader = ReadCfg(decoder.GetName());
            if (reader == null)
            {
                continue;
            }

            if (!decoder.Decode(reader))
            {
                continue;
            }

            Save(decoder);
        }
    }
Exemplo n.º 3
0
 private static void RegistAll()
 {
     Type[] cfgDecoderTypes = GetAllCfgDecoderTypes();
     foreach (Type decoderType in cfgDecoderTypes)
     {
         ICfgDecoder decoder = Activator.CreateInstance(decoderType) as ICfgDecoder;
         if (decoder == null)
         {
             Logger.LogError("decoder == null, type = " + decoderType, "ConfigData.RegistAll");
             continue;
         }
         g_cfgDecoderMap[decoder.GetName()] = decoder;
     }
 }
Exemplo n.º 4
0
    public bool Save(ICfgDecoder decoder)
    {
        string           path = "Assets/Resources/Config/" + decoder.GetSaveName();
        ScriptableObject data = decoder.Data as ScriptableObject;

        if (data == null)
        {
            Debug.LogError("Save error:" + path);
            return(false);
        }

        AssetDatabase.CreateAsset(data, path);
        Debug.Log("Save success: " + path);
        return(true);
    }