public void AddBlock() { GameObject newObj = null; if (MaxLine.Equals(5)) { newObj = Instantiate(L5Block); } else if (MaxLine.Equals(2)) { newObj = Instantiate(L2Block); } else if (MaxLine.Equals(4)) { newObj = Instantiate(L4Block); } else if (MaxLine.Equals(6)) { newObj = Instantiate(L6Block); } else if (MaxLine.Equals(1)) { newObj = Instantiate(L1Block); } else { MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_notenoughinfo"), LocaleManager.instance.GetLocaleText("creator_error_nolineval"), MessageBoxButton.OK); return; } newObj.GetComponent <Block>().Initialize(); newObj.GetComponent <Block>().Index = Blocks.Count; newObj.GetComponent <Block>().BPM = BPM; newObj.GetComponent <Block>().Beats = BeatVal; if (Blocks.Count > 0) { Blocks[Blocks.Count - 1].NextBlock = newObj.GetComponent <Block>(); } Blocks.Add(newObj.GetComponent <Block>()); newObj.transform.SetParent(BlockParent); newObj.GetComponent <RectTransform>().sizeDelta = new Vector2(newObj.GetComponent <RectTransform>().sizeDelta.x, 670 * ScopeVal); newObj.transform.localScale = new Vector3(1, 1, 1); newObj.transform.SetAsFirstSibling(); newObj.name = "block" + newObj.GetComponent <Block>().Index.ToString(); newObj.SetActive(true); UpdateBlockDivLine += newObj.GetComponent <Block>().UpdateDivLine; UpdateBlockSize += newObj.GetComponent <Block>().UpdateSize; UpdateSpecificView += newObj.GetComponent <Block>().SpecificView; }
public void WriteToTWx() { if (MaxLine.Equals(0)) { MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_notenoughinfo"), LocaleManager.instance.GetLocaleText("creator_error_nolineval"), MessageBoxButton.OK); return; } if (LevelVal < 1) { MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_notenoughinfo"), LocaleManager.instance.GetLocaleText("creator_error_nolevelval"), MessageBoxButton.OK); return; } if (NameField.text.Equals("")) { MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_notenoughinfo"), LocaleManager.instance.GetLocaleText("creator_error_nosongname"), MessageBoxButton.OK); return; } if (!OffsetField.text.Equals("") && !int.TryParse(OffsetField.text, out Offset)) { MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_notenoughinfo"), LocaleManager.instance.GetLocaleText("creator_error_wrongoffset"), MessageBoxButton.OK); return; } TWxMetadata metadata = new TWxMetadata(); metadata.level = LevelVal; metadata.artist = ArtistField.text; metadata.mapper = MapperField.text; metadata.density = DensityVal; metadata.offset = Offset; int noteID = 1; double absTime = Offset / 1000f; List <TWxNote> NoteBasket = new List <TWxNote>(); List <int> BPMs = new List <int>(), BPMQueues = new List <int>(), Beats = new List <int>(), BeatsQueues = new List <int>(); for (int i = 0; i < Blocks.Count; i++) { double blockTime = (60f * Blocks[i].Beats) / Blocks[i].BPM; if (i.Equals(0) || (!i.Equals(0) && Blocks[i].BPM != BPMs[BPMs.Count - 1])) { BPMs.Add(Blocks[i].BPM); BPMQueues.Add(Blocks[i].Index); } if (i.Equals(0) || (!i.Equals(0) && Blocks[i].Beats != Beats[Beats.Count - 1])) { Beats.Add(Blocks[i].Beats); BeatsQueues.Add(Blocks[i].Index); } for (int j = 0; j < Blocks[i].GetNoteArray().Length; j++) { CreatorNote baseNote = Blocks[i].GetNoteArray()[j]; TWxNote note = new TWxNote(); baseNote.FinalIndex = noteID; List <int> prevDatas = new List <int>(); if (baseNote.PreviousNotes.Count > 0) { for (int k = 0; k < baseNote.PreviousNotes.Count; k++) { prevDatas.Add(baseNote.PreviousNotes[k].FinalIndex); } } int[] prevArr; if (prevDatas.Count.Equals(0)) { prevArr = new int[] { 0 }; } else { prevArr = prevDatas.ToArray(); } note.SetValue(baseNote.YPos + 192 * baseNote.ParentBlock.Index, noteID, baseNote.Size, new byte[4] { baseNote.NoteColor.r, baseNote.NoteColor.g, baseNote.NoteColor.b, 255 }, baseNote.Type, baseNote.Flick, (float)absTime + ((float)blockTime * (baseNote.YPos / 192f)), baseNote.Speed, baseNote.StartPoint, baseNote.EndPoint, prevArr); NoteBasket.Add(note); noteID++; } absTime += blockTime; } metadata.bpm = BPMs.ToArray(); metadata.bpmQueue = BPMQueues.ToArray(); metadata.beats = Beats.ToArray(); metadata.beatsQueue = BeatsQueues.ToArray(); TWxData data = new TWxData(); data.metadata = metadata; data.notes = NoteBasket.ToArray(); string jsonText = JsonMapper.ToJson(data); FileStream stream = new FileStream(GamePath.CreatorPath() + NameField.text + ".tw" + MaxLine.ToString(), FileMode.Create, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); writer.Write(jsonText); writer.Close(); stream.Close(); MessageBox.Show(LocaleManager.instance.GetLocaleText("creator_saved"), LocaleManager.instance.GetLocaleText("creator_saveddesc") + NameField.text + ".tw" + MaxLine.ToString(), MessageBoxButton.OK); }