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)); }
/// <summary> /// Base for rendering a note. /// </summary> /// <param name="position">The position of the note.</param> /// <param name="participant">Optional participant. The position is relative to this participant.</param> /// <param name="style">Optional style of note. Default <see cref="NoteStyle.Normal"/>.</param> /// <param name="color">Optional backgrond color.</param> /// <param name="alignWithPrevious">Optional alignment with the previous note. Default <c>false</c>.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="stringBuilder"/> is <c>null</c>.</exception> internal static void NoteBase(this StringBuilder stringBuilder, NotePosition position, string participant = null, NoteStyle style = NoteStyle.Normal, Color color = null, bool alignWithPrevious = false) { if (stringBuilder is null) { throw new ArgumentNullException(nameof(stringBuilder)); } if (alignWithPrevious) { stringBuilder.Append(Constant.AlignNote); stringBuilder.Append(Constant.Space); } switch (style) { case NoteStyle.Hexagonal: stringBuilder.Append(Constant.NoteHexagon); break; case NoteStyle.Box: stringBuilder.Append(Constant.NoteBox); break; } stringBuilder.Append(Constant.Note); stringBuilder.Append(Constant.Space); stringBuilder.Append(position.ToString().ToLowerInvariant()); if (!string.IsNullOrWhiteSpace(participant)) { if (position != NotePosition.Over) { stringBuilder.Append(Constant.Space); stringBuilder.Append(Constant.Of); } stringBuilder.Append(Constant.Space); stringBuilder.Append(participant); } if (color is not null && color.ToString() != string.Empty) { stringBuilder.Append(Constant.Space); stringBuilder.Append(color); } }