예제 #1
0
    private bool LoadMissionScriptFile()
    {
        try
        {
            //UnityEngine.Object MissionFileObj = Resources.Load("Private/Script");

            //if (MissionFileObj == null)
            //{
            //    LogManager.LogError("\r\n----------------------------------------------------\r\n");
            //    LogManager.LogError("Load Resources Script.txt 出错。");
            //    LogManager.LogError("\r\n----------------------------------------------------\r\n");
            //    return false;
            //}

            //TextAsset MissionFileAsset = (TextAsset)MissionFileObj;

            string   scriptData   = DBStruct.GetResources("Private/Script");
            string[] MissionFiles = scriptData.Split(new string[1] {
                "\r\n"
            }, StringSplitOptions.None);

            for (int i = 0; i < MissionFiles.Length; i++)
            {
                IndexForLog++;
                MissionFiles[i].Trim();
                if (MissionFiles[i].Equals("") || MissionFiles[i].StartsWith(";"))
                {
                    continue;
                }
                else
                {
                    int npos = MissionFiles[i].IndexOf("=");
                    if (npos == -1)
                    {
                        continue;
                    }
                    int    ID = Convert.ToInt32(MissionFiles[i].Substring(0, npos).Trim());
                    string MissionFilePath = MissionFiles[i].Substring(npos + 1).Trim();
                    MissionFilePath = "Private" + MissionFilePath.Replace(".lua", "");
                    MissionFilePath = MissionFilePath.Replace("\\", "/");
                    m_mapQuestFile.Add(ID, MissionFilePath);
                }
            }

            return(true);
        }
        catch (Exception ex)
        {
            LogManager.LogError("--------------------出错行ID为:" + IndexForLog + " ,第二次出现该ID。--------------------");
            LogManager.LogError(ex.ToString());
            return(false);
        }
    }
    public bool OpenScript(string filename)
    {
        try
        {
            if (filename == string.Empty)
            {
                LogManager.LogError("--------------------要读取的名为: " + filename + " 的Lua脚本为空。--------------------");
                return(false);
            }

//             UnityEngine.Object FileObject = Resources.Load(filename);
//
//             if (FileObject == null)
//             {
//                 LogManager.LogError("\r\n----------------------------------------------------\r\n");
//                 LogManager.LogError("Load Resources名为: " + filename + " 的Lua脚本为空。");
//                 LogManager.LogError("\r\n----------------------------------------------------\r\n");
//                 return false;
//             }
//
            //             TextAsset asset = (TextAsset)FileObject;
            // 对文件名特殊处理 [3/16/2012 Ivan]
            filename = filename.Replace(".lua", ".txt");
            filename = filename.Replace("\\", "/");
            string fileContent = DBStruct.GetResources(filename);

            string[] strsTemp = fileContent.Split(new string[1] {
                "\r\n"
            }, StringSplitOptions.None);

            for (int i = 0; i < strsTemp.Length; i++)
            {
                strsTemp[i] = strsTemp[i].Trim();
                if (!strsTemp[i].Equals(""))
                {
                    if (!strsTemp[i].StartsWith("--"))
                    {
                        if (i >= 1)
                        {
                            if (!strsTemp[i].StartsWith("x"))
                            {
                                int j = 1;
                                while (strsTemp[i - j].Equals(""))
                                {
                                    j++;
                                }
                                strsTemp[i - j] += strsTemp[i];
                                strsTemp[i]      = string.Empty;
                            }
                        }
                        else
                        {
                            LogManager.LogError("--------------------脚本第一个属性出错,不是以x开头!--------------------");
                            return(false);
                        }
                    }
                }
            }

            ListTemp.Clear();
            for (int i = 0; i < strsTemp.Length; i++)
            {
                if (!strsTemp[i].Equals(""))
                {
                    if (!strsTemp[i].StartsWith("--"))
                    {
                        ListTemp.Add(strsTemp[i]);
                    }
                }
            }

            ScriptInfoMap.Clear();
            if (GetScriptInfoMap(ref ScriptInfoMap, ListTemp))
            {
                if (!ParseScript(ScriptInfoMap))
                {
                    LogManager.LogError("--------------------解析脚本出错。出错脚本名为:" + filename + " 。--------------------");
                    return(false);
                }
            }
            else
            {
                LogManager.LogError("--------------------从ScriptInfoMap中获取脚本信息出错。出错脚本名为:" + filename + " 。--------------------");
                return(false);
            }

            return(true);
        }
        catch (Exception ex)
        {
            CDataBaseSystem.StrError += "--------------------读取名为: " + filename + " 的Lua脚本出错。--------------------";
            CDataBaseSystem.StrError += ex.ToString();
            throw new Exception(CDataBaseSystem.StrError);
        }
    }