예제 #1
0
        public void UpdateLocalizationToSB()
        {
            int col   = 0;
            int row   = 0;
            var excel = CaomaoEditorHelper.ReadExcelRow(this.ExcelFilePath, ref col, ref row);

            if (excel == null)
            {
                Debug.LogError("No Excel:" + this.ExcelFilePath);
                return;
            }
            DataRow firstRow = excel[0];

            for (int c = 2; c < col; c++)
            {
                var lang = firstRow[c] as string;
                if (string.IsNullOrEmpty(lang))
                {
                    continue;
                }
                Debug.Log(lang);
                this.AddConfigName(lang);
            }
            this.InitSbData();
            if (this.allSbData.Count > 0)
            {
                //第一行,第一列是id,接下来是各国语言
                for (int r = 1; r < row; r++)
                {
                    var nextRow = excel[r];
                    var id      = nextRow[1].ToString();
                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }
                    for (int c = 2; c < col; c++)
                    {
                        var index = c - 2;
                        if (index < this.Config.Count)
                        {
                            var content = excel[r][c].ToString();
                            if (string.IsNullOrEmpty(content))
                            {
                                continue;
                            }
                            Debug.Log(content);
                            var lang = this.Config[index].Language;
                            LocalizationData data = null;
                            this.allSbData.TryGetValue(lang, out data);
                            if (data != null)
                            {
                                data.AddData(id.ToString(), content);
                            }
                        }
                    }
                }
                this.SaveLocalizationData();
            }
        }
예제 #2
0
        public void GenLocalizationConst()
        {
            //var templatePath = $"Assets/{this.TemplateFilePath}";
            var templateText = AssetDatabase.LoadAssetAtPath <TextAsset>(this.TemplateFilePath);

            if (templateText == null)
            {
                Debug.LogError("Template文件不存在:" + this.TemplateFilePath);
                return;
            }
            CaomaoScriptGenerateModule.Instance.Restart(templateText.text);
            int col = 0; int row = 0;
            var excel = CaomaoEditorHelper.ReadExcelRow(this.ExcelFilePath, ref col, ref row);

            if (excel == null)
            {
                Debug.LogError("No Excel:" + this.ExcelFilePath);
                return;
            }
            List <object[]> allV = new List <object[]>();

            for (int r = 1; r < row; r++)
            {
                var nextRow    = excel[r];
                var constValue = nextRow[0].ToString();
                if (string.IsNullOrEmpty(constValue))
                {
                    //Debug.LogError("Const常量为null:"+r);
                    continue;
                }
                Debug.Log(constValue);
                var id = nextRow[1].ToString();
                if (string.IsNullOrEmpty(id))
                {
                    //Debug.LogError("Id为null:" + r);
                    continue;
                }
                Debug.Log(id);
                var objects = new object[]
                {
                    constValue,
                    id
                };
                allV.Add(objects);
            }
            CaomaoScriptGenerateModule.Instance.AddVariable("variables", allV.ToArray());
            var script = CaomaoScriptGenerateModule.Instance.Parse();

            File.WriteAllText(Application.dataPath + "/CaomaoFramework/LocalizationModule/LocalizationConst.cs", script);
            AssetDatabase.Refresh();
        }