private Sound parseSound(LuaArgs args, int index) { LuaTable table = args.GetTable(index); string waveform = table.IsNil("waveform") ? "square" : table.GetString("waveform"); float volume = table.IsNil("volume") ? 1.0f : table.GetFloat("volume"); float duty = table.IsNil("duty") ? 0.5f : table.GetFloat("duty"); float duration = table.GetFloat("duration"); float attack = table.IsNil("attack") ? 0.0f : table.GetFloat("attack"); float decay = table.IsNil("decay") ? 0.0f : table.GetFloat("decay"); float frequency = table.GetFloat("frequency"); float slide = table.IsNil("slide") ? 0.0f : table.GetFloat("slide"); float vibratoDepth = table.IsNil("vibrato_depth") ? 0.0f : table.GetFloat("vibrato_depth"); float vibratoFrequency = table.IsNil("vibrato_frequency") ? 0.0f : table.GetFloat("vibrato_frequency"); bool loop = table.IsNil("loop") ? false : table.GetBool("loop"); var sound = new Sound(); sound.Waveform = ParseWaveform(waveform); sound.Volume = Clamp(volume, 0.0f, 1.0f); sound.Duty = Clamp(duty, 0.0f, 1.0f); sound.Attack = Math.Max(attack, 0.0f); sound.Duration = Math.Max(duration, 0.0f); sound.Decay = Math.Max(decay, 0.0f); sound.Frequency = Math.Max(frequency, 0.0f); sound.Slide = slide; sound.VibratoDepth = Math.Max(vibratoDepth, 0.0f); sound.VibratoFrequency = Math.Max(vibratoFrequency, 0.0f); sound.Loop = loop; return(sound); }
public static string WriteTo(Sheet sheet, string targetDir) { LuaTable luaTable = new LuaTable(); for (int i = 0; i < sheet.LineCount; ++i) { Line line = sheet.GetLineByIndex(i); int id = int.Parse(sheet.GetLineIDByIndex(i)); LuaTable lineTable = new LuaTable(); luaTable.AddItem(id, lineTable); for (int j = 0; j < sheet.FieldCount; ++j) { Field field = sheet.GetFieldByIndex(j); object value = field.GetValue(line.GetCellByIndex(j)); if (value != null) { lineTable.AddItem(field.Name, value); } } } string luaStr = luaTable.GetString(1); if (!string.IsNullOrEmpty(targetDir)) { string filePath = $"{targetDir}/{sheet.Name}.txt"; luaStr = $"local {sheet.Name} = {luaStr}\r\nreturn {sheet.Name}"; File.WriteAllText(filePath, luaStr); } return(luaStr); }
//加载所有模块 void LoadAllModules() { string modulesRootDir = Path.Combine(Application.dataPath, LuaModulesDir); string[] moduleDirs = Directory.GetDirectories(modulesRootDir); moduleInfoList = new List <LuaModuleInfo>(); for (int i = 0; i < moduleDirs.Length; i++) { string moduleDirPath = moduleDirs[i]; //模块目录路径 LuaModuleInfo moduleInfo = new LuaModuleInfo(Path.GetFileName(moduleDirs[i])); moduleInfo.moduleDirPath = moduleDirPath; //模块目录路径 moduleInfo.viewDirPath = moduleDirPath + ToLuaGenerater.Folder2Directory(LuaFolder.View); moduleInfo.modelDirPath = moduleDirPath + ToLuaGenerater.Folder2Directory(LuaFolder.Model); moduleInfo.serviceDirPath = moduleDirPath + ToLuaGenerater.Folder2Directory(LuaFolder.Service); moduleInfo.voDirPath = moduleDirPath + ToLuaGenerater.Folder2Directory(LuaFolder.Vo); //Views string[] mdrFiles = Directory.GetFiles(moduleInfo.viewDirPath, "*.lua"); for (int j = 0; j < mdrFiles.Length; j++) { string mdrFilePath = mdrFiles[j]; string mdrName = Path.GetFileNameWithoutExtension(mdrFilePath); mdrName = mdrName.Replace("Mdr", ""); LuaViewInfo viewInfo = new LuaViewInfo(mdrName); viewInfo.viewName = mdrName; viewInfo.viewDirPath = moduleInfo.viewDirPath; if (luaTable.HasTable(mdrName)) {//已经存在配置 Dictionary <string, object> table = luaTable.SetTable(mdrName); viewInfo.prefabUrl = luaTable.GetString(mdrName, "prefab"); } moduleInfo.viewList.Add(viewInfo); } //Vo RefreshVos(moduleInfo); moduleInfoList.Add(moduleInfo); } }