void Awake() { model = NotesEditorModel.Instance; rectTransform = GetComponent <RectTransform>(); rectTransform.localPosition = model.NoteToScreenPosition(notePosition); var image = GetComponent <Image>(); noteType.DistinctUntilChanged() .Select(type => type == NoteTypes.Long) .Subscribe(isLongNote => image.color = isLongNote ? Color.cyan : new Color(175 / 255f, 1, 78 / 255f)); this.UpdateAsObservable() .Select(_ => model.NoteToScreenPosition(notePosition)) .DistinctUntilChanged() .Subscribe(pos => rectTransform.localPosition = pos); var mouseDownObservable = onMouseDownObservable .Where(_ => model.ClosestNotePosition.Value.Equals(notePosition)); var editObservable = mouseDownObservable .Where(editType => editType == NoteTypes.Normal) .Where(editType => noteType.Value == editType) .Merge(mouseDownObservable .Where(editType => editType == NoteTypes.Long)); editObservable.Where(editType => editType == NoteTypes.Normal) .Subscribe(_ => model.NormalNoteObservable.OnNext(notePosition)); editObservable.Where(editType => editType == NoteTypes.Long) .Subscribe(_ => model.LongNoteObservable.OnNext(notePosition)); var longNoteLateUpdateObservable = this.LateUpdateAsObservable() .Where(_ => noteType.Value == NoteTypes.Long); longNoteLateUpdateObservable .Where(_ => next != null) .Select(_ => model.NoteToScreenPosition(next.notePosition)) .Merge(longNoteLateUpdateObservable .Where(_ => next == null) .Where(_ => model.EditType.Value == NoteTypes.Long) .Where(_ => model.LongNoteTailPosition.Value.Equals(notePosition)) .Select(_ => model.ScreenToCanvasPosition(Input.mousePosition))) .Select(nextPosition => new Line[] { new Line(model.NoteToScreenPosition(notePosition), nextPosition, 0 < nextPosition.x - model.NoteToScreenPosition(notePosition).x ? Color.cyan : Color.red) }) .Subscribe(lines => GLLineRenderer.RenderLines(notePosition.ToString(), lines)); }
void Awake() { model = NotesEditorModel.Instance; rectTransform = GetComponent<RectTransform>(); rectTransform.localPosition = model.NoteToScreenPosition(notePosition); var image = GetComponent<Image>(); noteType.DistinctUntilChanged() .Select(type => type == NoteTypes.Long) .Subscribe(isLongNote => image.color = isLongNote ? Color.cyan : new Color(175 / 255f, 1, 78 / 255f)); this.UpdateAsObservable() .Select(_ => model.NoteToScreenPosition(notePosition)) .DistinctUntilChanged() .Subscribe(pos => rectTransform.localPosition = pos); var mouseDownObservable = onMouseDownObservable .Where(_ => model.ClosestNotePosition.Value.Equals(notePosition)); var editObservable = mouseDownObservable .Where(editType => editType == NoteTypes.Normal) .Where(editType => noteType.Value == editType) .Merge(mouseDownObservable .Where(editType => editType == NoteTypes.Long)); editObservable.Where(editType => editType == NoteTypes.Normal) .Subscribe(_ => model.NormalNoteObservable.OnNext(notePosition)); editObservable.Where(editType => editType == NoteTypes.Long) .Subscribe(_ => model.LongNoteObservable.OnNext(notePosition)); var longNoteLateUpdateObservable = this.LateUpdateAsObservable() .Where(_ => noteType.Value == NoteTypes.Long); longNoteLateUpdateObservable .Where(_ => next != null) .Select(_ => model.NoteToScreenPosition(next.notePosition)) .Merge(longNoteLateUpdateObservable .Where(_ => next == null) .Where(_ => model.EditType.Value == NoteTypes.Long) .Where(_ => model.LongNoteTailPosition.Value.Equals(notePosition)) .Select(_ => model.ScreenToCanvasPosition(Input.mousePosition))) .Select(nextPosition => new Line[] { new Line(model.NoteToScreenPosition(notePosition), nextPosition, 0 < nextPosition.x - model.NoteToScreenPosition(notePosition).x ? Color.cyan : Color.red) }) .Subscribe(lines => GLLineRenderer.RenderLines(notePosition.ToString(), lines)); }
void Awake() { model = NotesEditorModel.Instance; var targetFrameObservable = this.UpdateAsObservable(); targetFrameObservable .Where(_ => Input.GetKeyDown(KeyCode.R)).Subscribe(_ => EnterNote(0)); targetFrameObservable .Where(_ => Input.GetKeyDown(KeyCode.F)).Subscribe(_ => EnterNote(1)); targetFrameObservable .Where(_ => Input.GetKeyDown(KeyCode.H)).Subscribe(_ => EnterNote(2)); targetFrameObservable .Where(_ => Input.GetKeyDown(KeyCode.I)).Subscribe(_ => EnterNote(3)); targetFrameObservable .Where(_ => Input.GetKeyDown(KeyCode.J)).Subscribe(_ => EnterNote(4)); }
void Awake() { model = NotesEditorModel.Instance; var saveActionObservable = this.UpdateAsObservable() .Where(_ => Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand) || Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.RightCommand)) .Where(_ => Input.GetKey(KeyCode.S)) .Merge(saveButton.OnClickAsObservable()); Observable.Merge( model.BPM.Select(_ => true), model.BeatOffsetSamples.Select(_ => true), model.NormalNoteObservable.Select(_ => true), model.LongNoteObservable.Select(_ => true), model.OnLoadedMusicObservable.Select(_ => false), saveActionObservable.Select(_ => false)) .SkipUntil(model.OnLoadedMusicObservable.DelayFrame(1)) .Do(unsaved => saveButton.GetComponent <Image>().color = unsaved ? new Color(253 / 255f, 230 / 255f, 3 / 255f) : Color.white) .SubscribeToText(messageText, unsaved => unsaved ? "保存が必要な状態" : ""); saveActionObservable.Subscribe(_ => { var fileName = Path.GetFileNameWithoutExtension(model.MusicName.Value) + ".json"; var filePath = Application.persistentDataPath + "/Notes/"; var fileFullPath = filePath + fileName; var text = model.SerializeNotesData(); if (!File.Exists(filePath)) { Directory.CreateDirectory(filePath); } File.WriteAllText(fileFullPath, text, System.Text.Encoding.UTF8); messageText.text = fileFullPath + " に保存しました"; }); }
void Awake() { model = NotesEditorModel.Instance; var saveActionObservable = this.UpdateAsObservable() .Where(_ => Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand) || Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.RightCommand)) .Where(_ => Input.GetKey(KeyCode.S)) .Merge(saveButton.OnClickAsObservable()); Observable.Merge( model.BPM.Select(_ => true), model.BeatOffsetSamples.Select(_ => true), model.NormalNoteObservable.Select(_ => true), model.LongNoteObservable.Select(_ => true), model.OnLoadedMusicObservable.Select(_ => false), saveActionObservable.Select(_ => false)) .SkipUntil(model.OnLoadedMusicObservable.DelayFrame(1)) .Do(unsaved => saveButton.GetComponent<Image>().color = unsaved ? new Color(253 / 255f, 230 / 255f, 3 / 255f) : Color.white) .SubscribeToText(messageText, unsaved => unsaved ? "保存が必要な状態" : ""); saveActionObservable.Subscribe(_ => { var fileName = Path.GetFileNameWithoutExtension(model.MusicName.Value) + ".json"; var filePath = Application.persistentDataPath + "/Notes/"; var fileFullPath = filePath + fileName; var text = model.SerializeNotesData(); if (!File.Exists(filePath)) { Directory.CreateDirectory(filePath); } File.WriteAllText(fileFullPath, text, System.Text.Encoding.UTF8); messageText.text = fileFullPath + " に保存しました"; }); }
void Awake() { model = NotesEditorModel.Instance; model.OnLoadedMusicObservable.First().Subscribe(_ => Init()); }
void Awake() { model = NotesEditorModel.Instance; var closestNoteAreaOnMouseDownObservable = canvasEvents.ScrollPadOnMouseDownObservable .Where(_ => !Input.GetMouseButtonDown(1)) .Where(_ => 0 <= model.ClosestNotePosition.Value.ToSamples(model.Audio.clip.frequency)); closestNoteAreaOnMouseDownObservable .Select(_ => model.EditType.Value == NoteTypes.Long ? model.LongNoteObservable : model.NormalNoteObservable) .Subscribe(observable => observable.OnNext(model.ClosestNotePosition.Value)); // Start editing of long note closestNoteAreaOnMouseDownObservable .Where(_ => model.EditType.Value == NoteTypes.Normal) .Where(_ => Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) .Do(notePosition => model.EditType.Value = NoteTypes.Long) .Subscribe(_ => model.LongNoteObservable.OnNext(model.ClosestNotePosition.Value)); // Finish editing of long note this.UpdateAsObservable() .Where(_ => model.EditType.Value == NoteTypes.Long) .Where(_ => Input.GetKeyDown(KeyCode.Escape) || Input.GetMouseButtonDown(1)) .Subscribe(_ => model.EditType.Value = NoteTypes.Normal); var finishEditLongNoteObservable = model.EditType.DistinctUntilChanged() .Where(editType => editType == NoteTypes.Normal) .Skip(1); finishEditLongNoteObservable.Subscribe(_ => model.LongNoteTailPosition.Value = new NotePosition(-1, -1, -1, -1)); // Update long note link and tail position model.AddedLongNoteObjectObservable .Subscribe(obj => { if (model.NoteObjects.ContainsKey(model.LongNoteTailPosition.Value)) { var tailObj = model.NoteObjects[model.LongNoteTailPosition.Value]; tailObj.next = obj; obj.prev = tailObj; } model.LongNoteTailPosition.Value = obj.notePosition; }); model.NormalNoteObservable.Subscribe(notePosition => { if (model.NoteObjects.ContainsKey(notePosition)) { RemoveNote(notePosition); } else { var noteObject = (Instantiate(notePrefab) as GameObject).GetComponent <NoteObject>(); noteObject.notePosition = notePosition; noteObject.noteType.Value = NoteTypes.Normal; noteObject.transform.SetParent(notesRegion.transform); model.NoteObjects.Add(notePosition, noteObject); } }); model.LongNoteObservable.Subscribe(notePosition => { if (model.NoteObjects.ContainsKey(notePosition)) { var noteObject = model.NoteObjects[notePosition]; if (noteObject.noteType.Value == NoteTypes.Long) { if (noteObject.prev != null) { noteObject.prev.next = noteObject.next; } if (noteObject.next != null) { noteObject.next.prev = noteObject.prev; } else { model.LongNoteTailPosition.Value = noteObject.prev == null ? new NotePosition(-1, -1, -1, -1) : noteObject.prev.notePosition; } RemoveNote(notePosition); } else { noteObject.noteType.Value = NoteTypes.Long; model.AddedLongNoteObjectObservable.OnNext(noteObject); } } else { var noteObject = (Instantiate(notePrefab) as GameObject).GetComponent <NoteObject>(); noteObject.notePosition = notePosition; noteObject.noteType.Value = NoteTypes.Long; noteObject.transform.SetParent(notesRegion.transform); model.NoteObjects.Add(notePosition, noteObject); model.AddedLongNoteObjectObservable.OnNext(noteObject); } }); }
void Awake() { model = NotesEditorModel.Instance; }