예제 #1
0
    public void InitializeCurve()
    {
        DragNote dragNote = GetComponent <NoteObject>().note
                            as DragNote;

        pointsOnCurve = new ListView <Vector2>();

        Vector2 headPosition = GetComponent <RectTransform>()
                               .anchoredPosition;

        foreach (FloatPoint p in dragNote.Interpolate())
        {
            Vector2 pointOnCurve = new Vector2(
                scanRef.FloatPulseToXPosition(
                    dragNote.pulse + p.pulse)
                - headPosition.x,
                scanRef.FloatLaneToYPosition(
                    dragNote.lane + p.lane)
                - headPosition.y);
            pointsOnCurve.Add(pointOnCurve);
        }

        curveEnd.anchoredPosition =
            pointsOnCurve[pointsOnCurve.Count - 1];
        curveXDirection = Mathf.Sign(
            pointsOnCurve[pointsOnCurve.Count - 1].x
            - pointsOnCurve[0].x);
        PlaceNoteImageOnCurve();
        curve.SetVerticesDirty();
    }
예제 #2
0
 public void CalculateTimeOfAllNotes()
 {
     foreach (Note n in notes)
     {
         n.time = PulseToTime(n.pulse);
         if (n is HoldNote)
         {
             HoldNote h = n as HoldNote;
             h.endTime = PulseToTime(h.pulse + h.duration);
             if (Ruleset.instance != null)
             {
                 h.gracePeriodStart = h.endTime -
                                      Ruleset.instance.longNoteGracePeriod;
             }
         }
         if (n is DragNote)
         {
             DragNote d = n as DragNote;
             d.endTime = PulseToTime(d.pulse + d.Duration());
             if (Ruleset.instance != null)
             {
                 d.gracePeriodStart = d.endTime -
                                      Ruleset.instance.longNoteGracePeriod;
             }
         }
     }
 }
예제 #3
0
    // This does not render anchors and control points; call
    // ResetAnchorsAndControlPoints for that.
    public void ResetCurve()
    {
        DragNote dragNote = GetComponent <NoteObject>().note
                            as DragNote;

        pointsOnCurve = new List <Vector2>();

        foreach (FloatPoint p in dragNote.Interpolate())
        {
            Vector2 pointOnCurve = new Vector2(
                p.pulse * PatternPanel.PulseWidth,
                -p.lane * PatternPanel.LaneHeight);
            pointsOnCurve.Add(pointOnCurve);
        }
        // TODO: do we need to smooth these points?

        // Rotate note head.
        UIUtils.RotateToward(self: noteImage,
                             selfPos: pointsOnCurve[0],
                             targetPos: pointsOnCurve[1]);

        // Draw curve.
        curvedImage.SetVerticesDirty();

        // Draw new anchor receivers. Reuse them if applicable.
        for (int i = 0;
             i < anchorReceiverContainer.childCount;
             i++)
        {
            anchorReceiverContainer.GetChild(i).gameObject
            .SetActive(false);
        }
        if (anchorReceiverTemplate.transform.GetSiblingIndex()
            != 0)
        {
            anchorReceiverTemplate.transform.SetAsFirstSibling();
        }
        for (int i = 0; i < pointsOnCurve.Count - 1; i++)
        {
            int childIndex = i + 1;
            while (anchorReceiverContainer.childCount - 1
                   < childIndex)
            {
                Instantiate(
                    anchorReceiverTemplate,
                    parent: anchorReceiverContainer);
            }
            RectTransform receiver =
                anchorReceiverContainer.GetChild(childIndex)
                .GetComponent <RectTransform>();
            receiver.gameObject.SetActive(true);
            receiver.anchoredPosition = pointsOnCurve[i];

            UIUtils.PointToward(receiver,
                                selfPos: pointsOnCurve[i],
                                targetPos: pointsOnCurve[i + 1]);
        }
    }
예제 #4
0
 public void UnpackAllNotes()
 {
     notes = new SortedSet <Note>(new NoteComparer());
     foreach (string s in packedNotes)
     {
         notes.Add(Note.Unpack(s));
     }
     foreach (string s in packedHoldNotes)
     {
         notes.Add(HoldNote.Unpack(s));
     }
     foreach (PackedDragNote n in packedDragNotes)
     {
         notes.Add(DragNote.Unpack(n));
     }
 }
예제 #5
0
 public Note Clone()
 {
     // If performance is necessary, then do it type-by-type and
     // field-by-field, as in NoteV1.Clone.
     if (this is HoldNote)
     {
         return(HoldNote.Unpack(Pack()));
     }
     else if (this is DragNote)
     {
         return(DragNote.Unpack((this as DragNote).Pack()));
     }
     else
     {
         return(Note.Unpack(Pack()));
     }
 }
예제 #6
0
    public static DragNote Unpack(PackedDragNote packed)
    {
        Note     unpackedNote = Note.Unpack(packed.packedNote);
        DragNote dragNote     = new DragNote()
        {
            type  = unpackedNote.type,
            pulse = unpackedNote.pulse,
            lane  = unpackedNote.lane,
            sound = unpackedNote.sound,
            nodes = new List <DragNode>()
        };

        foreach (string packedNode in packed.packedNodes)
        {
            dragNote.nodes.Add(DragNode.Unpack(packedNode));
        }
        return(dragNote);
    }
예제 #7
0
 private void AdjustDragNoteAnchorsForScrollSpeed(Pattern p)
 {
     if (p.patternMetadata.bps == 4)
     {
         return;
     }
     foreach (Note n in p.notes)
     {
         if (n.type != NoteType.Drag)
         {
             continue;
         }
         DragNote dragNote = n as DragNote;
         foreach (DragNode node in dragNote.nodes)
         {
             node.anchor.lane *= 0.5f;
         }
     }
 }
예제 #8
0
    public static DragNote Unpack(PackedDragNote packed)
    {
        char[] delim = new char[] { '|' };
        // Beware that the "sound" portion may contain |.
        string[] splits = packed.packedNote.Split(delim, 2);
        DragNote dragNote;

        // Extended?
        if (splits[0] == "E")
        {
            splits   = packed.packedNote.Split(delim, 8);
            dragNote = new DragNote()
            {
                pulse         = int.Parse(splits[2]),
                lane          = int.Parse(splits[3]),
                volumePercent = int.Parse(splits[4]),
                panPercent    = int.Parse(splits[5]),
                curveType     = (CurveType)int.Parse(splits[6]),
                sound         = splits[7]
            };
        }
        else
        {
            splits   = packed.packedNote.Split(delim, 4);
            dragNote = new DragNote()
            {
                pulse = int.Parse(splits[1]),
                lane  = int.Parse(splits[2]),
                sound = splits[3]
            };
        }

        dragNote.type      = NoteType.Drag;
        dragNote.endOfScan = false;
        dragNote.nodes     = new List <DragNode>();
        foreach (string packedNode in packed.packedNodes)
        {
            dragNote.nodes.Add(DragNode.Unpack(packedNode));
        }
        return(dragNote);
    }
예제 #9
0
 // This does not modify type, pulse and lane.
 public void CopyFrom(Note other)
 {
     sound         = other.sound;
     volumePercent = other.volumePercent;
     panPercent    = other.panPercent;
     endOfScan     = other.endOfScan;
     if (this is HoldNote && other is HoldNote)
     {
         (this as HoldNote).duration = (other as HoldNote).duration;
     }
     if (this is DragNote && other is DragNote)
     {
         DragNote d = this as DragNote;
         d.nodes = new List <DragNode>();
         foreach (DragNode node in (other as DragNote).nodes)
         {
             d.nodes.Add(node.Clone());
         }
         d.curveType = (other as DragNote).curveType;
     }
 }
예제 #10
0
    public void InitializeCurve()
    {
        DragNote dragNote = GetComponent <NoteObject>().note
                            as DragNote;

        visiblePointsOnCurve = new ListView <Vector2>();
        pointsOnCurve        = new List <Vector2>();

        Vector2 headPosition = GetComponent <RectTransform>()
                               .anchoredPosition;

        foreach (FloatPoint p in dragNote.Interpolate())
        {
            Vector2 pointOnCurve = new Vector2(
                scanRef.FloatPulseToXPosition(
                    dragNote.pulse + p.pulse)
                - headPosition.x,
                scanRef.FloatLaneToYPosition(
                    dragNote.lane + p.lane)
                - headPosition.y);
            visiblePointsOnCurve.Add(pointOnCurve);
            pointsOnCurve.Add(pointOnCurve);
        }

        curveEnd.anchoredPosition =
            visiblePointsOnCurve[visiblePointsOnCurve.Count - 1];
        curveXDirection = Mathf.Sign(
            visiblePointsOnCurve[visiblePointsOnCurve.Count - 1].x
            - visiblePointsOnCurve[0].x);
        curve.SetVerticesDirty();

        noteImage.rectTransform.anchoredPosition = Vector2.zero;
        hitbox.anchoredPosition = Vector2.zero;
        UIUtils.RotateToward(noteImage.rectTransform,
                             selfPos: pointsOnCurve[0],
                             targetPos: pointsOnCurve[1]);
    }
예제 #11
0
    public void ResetAllAnchorsAndControlPoints()
    {
        DragNote dragNote = GetComponent <NoteObject>().note
                            as DragNote;

        for (int i = 0; i < anchorContainer.childCount; i++)
        {
            if (anchorContainer.GetChild(i).gameObject !=
                anchorTemplate)
            {
                Destroy(anchorContainer.GetChild(i).gameObject);
            }
        }
        for (int i = 0; i < dragNote.nodes.Count; i++)
        {
            DragNode dragNode = dragNote.nodes[i];

            GameObject anchor = Instantiate(anchorTemplate,
                                            parent: anchorContainer);
            anchor.SetActive(true);
            anchor.GetComponent <DragNoteAnchor>().anchorIndex = i;
            anchor.GetComponent <RectTransform>().anchoredPosition
                = new Vector2(
                      dragNode.anchor.pulse * PatternPanel.PulseWidth,
                      -dragNode.anchor.lane * PatternPanel.LaneHeight);

            for (int control = 0; control < 2; control++)
            {
                ResetControlPointPosition(dragNode,
                                          anchor, control);
            }

            ResetPathsToControlPoints(
                anchor.GetComponent <DragNoteAnchor>());
        }
    }
예제 #12
0
    private void SpawnNote(NoteData _data)
    {
        Note note = PopNote(_data.noteType);

        note.data             = _data;
        note.time             = _data.time;
        note.lineNum          = _data.lineNum;
        note.transform.parent = g.lines[_data.lineNum];

        switch (_data.noteType)
        {
        case Note.N_LONG:
            LongNote ln = (LongNote)note;
            ln.UpdateTimeInterval();
            ln.length = _data.length;
            break;

        case Note.N_DRAG:
            DragNote dn = (DragNote)note;
            dn.drag = _data.drag;
            break;

        case Note.N_BATTER:
            BatterNote bn = (BatterNote)note;
            bn.maxHit             = _data.batterHit;
            bn.endTime            = _data.batterEndTime;
            note.transform.parent = g.lines[0].parent;
            break;
        }

        note.UpdatePosition();
        note.gameObject.SetActive(true);
        note.Start();

        notes.Add(note);
    }
예제 #13
0
    private void TouchLine(TouchInfo _info)
    {
        Vector3 worldPos = Camera.main.ScreenToWorldPoint(_info.position);
        int     lineNum  = (worldPos.x < 0) ? 0 : 1;

        // Vector3 localPos = g.lines[lineNum].InverseTransformPoint(worldPos);
        // Vector3 startPos = g.lines[lineNum].InverseTransformPoint(Camera.main.ScreenToWorldPoint(_info.startPosition));

        // 연타 노트 체크.
        if (currentBatter != null)
        {
            if (_info.state == TouchState.Press)
            {
                HitNote(currentBatter);
            }
            return;
        }

        // Press의 경우.
        if (_info.state == TouchState.Press)
        {
            Note targetNote = null;
            for (int i = 0; i < g.noteSpawn.notes.Count; ++i)
            {
                Note n = g.noteSpawn.notes[i];
                if (n.lineNum != lineNum)
                {
                    continue;
                }
                Judge judge = CheckJudgement(n);
                if (judge == Judge.None || judge == Judge.Miss)
                {
                    continue;
                }
                if (n.data.noteType == Note.N_DRAG)
                {
                    continue;
                }

                if (targetNote == null || n.time < targetNote.time)
                {
                    targetNote = n;
                }
            }
            if (targetNote != null)
            {
                HitNote(targetNote);
            }
        }
        // Stay의 경우.
        else if (_info.state == TouchState.Stay)
        {
            DragNote targetDrag = null;
            for (int i = 0; i < g.noteSpawn.notes.Count; ++i)
            {
                Note n = g.noteSpawn.notes[i];
                if (n.lineNum != lineNum)
                {
                    continue;
                }

                // 롱 노트 체크.
                if (n.data.noteType == Note.N_LONG)
                {
                    LongNote ln = (LongNote)n;
                    if (ln.firstTouched)
                    {
                        ln.touched = true;
                    }
                }
                // 드래그 노트 체크.
                else if (n.data.noteType == Note.N_DRAG)
                {
                    Judge judge = CheckJudgement(n);
                    if (judge == Judge.None || judge == Judge.Miss)
                    {
                        continue;
                    }
                    DragNote dn = (DragNote)n;
                    if (targetDrag == null || n.time < targetDrag.time)
                    {
                        targetDrag = dn;
                    }
                }
            }
            if (targetDrag != null &&
                _info.CheckDrag() == targetDrag.drag * (targetDrag.lineNum == 1 ? -1 : 1))
            {
                HitNote(targetDrag);
                _info.ResetDrag();
            }
        }
    }