Пример #1
0
    public bool Init(CNSConfig config)
    {
        ResetDatas();
        if (config == null)
        {
            return(false);
        }

        if (IntPersistIndex <= 0)
        {
            m_IntVars = null;
        }
        else
        {
            if (m_IntVars == null || m_IntVars.Length != IntPersistIndex)
            {
                m_IntVars = new int[IntPersistIndex];
            }
        }

        if (FloatPersistIndex <= 0)
        {
            m_FloatVars = null;
        }
        else
        {
            if (m_FloatVars == null || m_FloatVars.Length != FloatPersistIndex)
            {
                m_FloatVars = new float[FloatPersistIndex];
            }
        }

        return(true);
    }
Пример #2
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;
     }
 }
Пример #3
0
    public bool RunCmd(string cmdName)
    {
        if (string.IsNullOrEmpty(cmdName))
        {
            return(false);
        }
        GlobalPlayer ply = this.GPlayer;

        if (ply == null || ply.CmdCfg == null)
        {
            return(false);
        }
        Cmd_Command cmd = ply.CmdCfg.GetCommand(cmdName);

        if (cmd == null)
        {
            return(false);
        }

        bool       mustCheckTrigger;
        AI_Command aiCmd = ply.CmdCfg.GetAICommand(cmd, this, out mustCheckTrigger);

        if (aiCmd == null || (mustCheckTrigger && !aiCmd.CanTrigger(this, cmdName)))
        {
            return(false);
        }

        CNSConfig cnsCfg = ply.CnsCfg;

        if (cnsCfg == null)
        {
            if (ply.LuaCfg != null)
            {
                cnsCfg = ply.LuaCfg.CnsCfg;
                if (cnsCfg == null)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        int id;

        if (!cnsCfg.GetCNSStateId(aiCmd.value, out id))
        {
            return(false);
        }
        return(ChangeState((PlayerState)id, true));
    }
Пример #4
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);
    }