Ejemplo n.º 1
0
 private void Clear()
 {
     m_AirConfig    = null;
     m_PlayerConfig = null;
     m_CNSConfig    = null;
     m_CmdConfig    = null;
     if (m_LuaConfig != null)
     {
         m_LuaConfig.Dispose();
         m_LuaConfig = null;
     }
 }
Ejemplo n.º 2
0
    private bool Init(string playerName, out GlobalPlayerLoaderResult result, string cnsName = "")
    {
        Clear();
        result       = GlobalPlayerLoaderResult.None;
        m_PlayerName = playerName;
        if (string.IsNullOrEmpty(playerName))
        {
            result = GlobalPlayerLoaderResult.ParamError;
            return(false);
        }
        try
        {
            m_PlayerConfig = new PlayerConfig();
            m_PlayerConfig.LoadPlayer(playerName);
        } catch (Exception e) {
                        #if DEBUG
            Debug.LogError(e.ToString());
                        #endif
            Clear();
            result = GlobalPlayerLoaderResult.PlayerConfigError;
            return(false);
        }

        if (!m_PlayerConfig.IsVaild)
        {
            Clear();
            result = GlobalPlayerLoaderResult.PlayerConfigError;
            return(false);
        }
        try
        {
            string airName = string.Empty;
            if (m_PlayerConfig != null && m_PlayerConfig.Files != null)
            {
                airName = m_PlayerConfig.Files.anim;
                airName = GlobalConfigMgr.GetConfigFileNameNoExt(airName);
            }
            m_AirConfig = new AirConfig(playerName, airName);
            if (!m_AirConfig.IsVaild)
            {
                Clear();
                result = GlobalPlayerLoaderResult.AirConfigError;
                return(false);
            }
        } catch (Exception e) {
                        #if DEBUG
            Debug.LogError(e.ToString());
                        #endif
            Clear();
            result = GlobalPlayerLoaderResult.AirConfigError;
            return(false);
        }

        // 判断LUA
        bool isLua = false;
        try
        {
            if (m_PlayerConfig != null && m_PlayerConfig.Files != null && m_PlayerConfig.Files.HasLuaFile)
            {
                isLua       = true;
                m_LuaConfig = new LuaCnsConfig();
                if (!m_LuaConfig.LoadFromFile(m_PlayerConfig.Files.lua))
                {
                    result = (GlobalPlayerLoaderResult)((int)result | (int)GlobalPlayerLoaderResult.LUAConfigError);
                }
            }
        }
        catch (Exception e)
        {
#if DEBUG
            Debug.LogError(e.ToString());
#endif
            result = (GlobalPlayerLoaderResult)((int)result | (int)GlobalPlayerLoaderResult.LUAConfigError);
        }

        //---------------------------- 加载Cmd
        if (!isLua)
        {
            try
            {
                if (m_PlayerConfig != null && m_PlayerConfig.Files != null)
                {
                    string cmdName = m_PlayerConfig.Files.cmd;
                    if (string.IsNullOrEmpty(cmdName))
                    {
                        cmdName = playerName;
                    }
                    else
                    {
                        cmdName = GlobalConfigMgr.GetConfigFileNameNoExt(cmdName);
                    }
                    string fileName = string.Format("{0}@{1}/{2}.cmd.txt", AppConfig.GetInstance().PlayerRootDir, playerName, cmdName);
                    m_CmdConfig = new CmdConfig();
                    if (!m_CmdConfig.LoadFromFile(fileName))
                    {
                        result = GlobalPlayerLoaderResult.CmdConfigError;
                    }
                }
            }
            catch (Exception e)
            {
#if DEBUG
                Debug.LogError(e.ToString());
#endif
                result = GlobalPlayerLoaderResult.CmdConfigError;
            }
        }



        //--------------------------- 最后加载cns
        if (!isLua)
        {
            try
            {
                if (string.IsNullOrEmpty(cnsName))
                {
                    if (m_PlayerConfig == null || m_PlayerConfig.Files == null)
                    {
                        cnsName = playerName;
                    }
                    else
                    {
                        cnsName = m_PlayerConfig.Files.cns;
                        cnsName = GlobalConfigMgr.GetConfigFileNameNoExt(cnsName);
                    }
                }
                string fileName = string.Format("{0}@{1}/{2}.cns.txt", AppConfig.GetInstance().PlayerRootDir, playerName, cnsName);
                m_CNSConfig = new CNSConfig();
                if (!m_CNSConfig.LoadFromFile(fileName))
                {
                    //Clear();
                    result = (GlobalPlayerLoaderResult)((int)result | (int)GlobalPlayerLoaderResult.CNSConfigError);
                    //return false;
                }
            } catch (Exception e) {
                        #if DEBUG
                Debug.LogError(e.ToString());
                        #endif
                //Clear ();
                result = (GlobalPlayerLoaderResult)((int)result | (int)GlobalPlayerLoaderResult.CNSConfigError);
                //return false;
            }
        }

        if (result == GlobalPlayerLoaderResult.None)
        {
            result = GlobalPlayerLoaderResult.Ok;
        }
        return(true);
    }