Ejemplo n.º 1
0
    public GlobalPlayer LoadPlayer_(string playerName, out GlobalPlayerLoaderResult result)
    {
        if (string.IsNullOrEmpty(playerName))
        {
            result = GlobalPlayerLoaderResult.ParamError;
            return(null);
        }
        var trans = this.transform;
        DefaultLoaderPlayer finder = null;

        for (int i = 0; i < trans.childCount; ++i)
        {
            var child = trans.GetChild(i);
            DefaultLoaderPlayer loader = child.GetComponent <DefaultLoaderPlayer>();
            if (loader == null)
            {
                continue;
            }
            var plyName = loader.GetPlayerName();
            if (string.Compare(plyName, playerName) == 0)
            {
                finder = loader;
                break;
            }
        }
        if (finder == null)
        {
            GameObject obj = new GameObject(playerName, typeof(DefaultLoaderPlayer));
            obj.transform.SetParent(this.transform, false);
            finder = obj.GetComponent <DefaultLoaderPlayer>();
        }
        GlobalPlayer ret = LoadPlayer(finder, out result);

        return(ret);
    }
Ejemplo n.º 2
0
    public GlobalPlayer LoadPlayer(DefaultLoaderPlayer loaderPlayer, out GlobalPlayerLoaderResult result)
    {
        if (loaderPlayer == null)
        {
            result = GlobalPlayerLoaderResult.ParamError;
            return(null);
        }
        string       playerName = loaderPlayer.GetPlayerName();
        GlobalPlayer ret        = LoadPlayer(playerName, out result, loaderPlayer.CnsName);

        if (ret != null)
        {
        }
        return(ret);
    }
Ejemplo n.º 3
0
    private GlobalPlayer LoadPlayer(string playerName, out GlobalPlayerLoaderResult result, string cnsName = "")
    {
        result = GlobalPlayerLoaderResult.Ok;
        GlobalPlayer player;

        if (m_PlayerDict.TryGetValue(playerName, out player) && player != null)
        {
            return(player);
        }
        player = GlobalPlayer.CreatePlayer(playerName, out result, cnsName);
        if (player != null)
        {
            m_PlayerDict [playerName] = player;
        }
        return(player);
    }
Ejemplo n.º 4
0
    public static GlobalPlayer CreatePlayer(string playerName, out GlobalPlayerLoaderResult result, string cnsName = "")
    {
        if (string.IsNullOrEmpty(playerName))
        {
            result = GlobalPlayerLoaderResult.ParamError;
            return(null);
        }
        GlobalPlayer player = new GlobalPlayer();
        bool         ret    = player.Init(playerName, out result);

        if (!ret)
        {
            return(null);
        }
        return(player);
    }
Ejemplo n.º 5
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);
    }