Skip to content

Commit

Permalink
AttachedPoint from AttachedTiming instead
Browse files Browse the repository at this point in the history
  • Loading branch information
yojohanshinwataikei committed Sep 17, 2023
1 parent 89bc672 commit a15fb1d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
1 change: 1 addition & 0 deletions Assets/Misc/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- 修复编辑数值时, 可能会触发滚动相关的快捷键的问题
- 修复正在播放时难以向后滚动的问题
- 修复 Arc 坐标网格线被地面 Note 覆盖的问题
- 修复滚动时, 时间和网格线之间可能出现 1 毫秒误差的问题

---

Expand Down
14 changes: 9 additions & 5 deletions Assets/Scripts/Compose/Editing/Cursor/AdeCursorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ public Vector3 AttachedTrackPoint
}
else
{
z = AdeGridManager.Instance.AttachBeatline(trackHit.point.z);
z = ArcTimingManager.Instance.CalculatePositionByTiming(
AttachedTiming + ArcAudioManager.Instance.AudioOffset,
AdeTimingEditor.Instance.currentTimingGroup
) / -1000f;
}
return new Vector3(trackHit.point.x, trackHit.point.y, z);
}
Expand Down Expand Up @@ -221,9 +224,7 @@ public int AttachedTiming
{
return overriddenCursorTiming.Value;
}
Vector3 pos = AttachedTrackPoint;
var timingGroup = AdeTimingEditor.Instance.currentTimingGroup;
return ArcTimingManager.Instance.CalculateTimingByPosition(-pos.z * 1000, timingGroup) - ArcAudioManager.Instance.AudioOffset;
return AdeGridManager.Instance.AttachBeatlineTimingFromFos(trackHit.point.z);
}
}

Expand Down Expand Up @@ -272,7 +273,10 @@ private void UpdateTrackCursor()
}
else
{
z = AdeGridManager.Instance.AttachBeatline(trackHit.point.z);
z = ArcTimingManager.Instance.CalculatePositionByTiming(
AttachedTiming + ArcAudioManager.Instance.AudioOffset,
AdeTimingEditor.Instance.currentTimingGroup
) / -1000f;;
}
if (TrackEnabled)
{
Expand Down
39 changes: 25 additions & 14 deletions Assets/Scripts/Compose/Editing/Cursor/AdeGridManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public string PreferencesSavePath
private List<float> verticalXPositions = new List<float>();
private List<float> verticalYPositions = new List<float>();

private List<LineRenderer> beatlineInstances = new List<LineRenderer>();
private struct RenderingBeatlineInfo{
public LineRenderer renderer;
public int timing;
};

private List<RenderingBeatlineInfo> beatlineInstances = new List<RenderingBeatlineInfo>();
private List<LineRenderer> verticalInstances = new List<LineRenderer>();

private CustomGrid customGrid;
Expand Down Expand Up @@ -125,7 +130,7 @@ private void HideExceededBeatlineInstance()
int count = beatlineInstances.Count;
while (count > beatlineInUse)
{
beatlineInstances[count - 1].enabled = false;
beatlineInstances[count - 1].renderer.enabled = false;
count--;
}
}
Expand All @@ -139,13 +144,16 @@ private void HideExceededVerticalInstance()
}
}

private LineRenderer GetBeatlineInstance()
private LineRenderer GetBeatlineInstance(int timing)
{
while (beatlineInstances.Count < beatlineInUse + 1)
{
beatlineInstances.Add(Instantiate(BeatlinePrefab, transform).GetComponent<LineRenderer>());
beatlineInstances.Add(new RenderingBeatlineInfo{
renderer=Instantiate(BeatlinePrefab, transform).GetComponent<LineRenderer>(),
timing=timing,
});
}
return beatlineInstances[beatlineInUse++];
return beatlineInstances[beatlineInUse++].renderer;
}
private LineRenderer GetVerticalInstance()
{
Expand Down Expand Up @@ -408,7 +416,7 @@ private void UpdateBeatline()
continue;
}
float z = pos / 1000f;
LineRenderer l = GetBeatlineInstance();
LineRenderer l = GetBeatlineInstance(t.Timing);
l.enabled = true;
l.DrawLine(new Vector3(-xEdgePos, -z), new Vector3(xEdgePos, -z));
l.endColor = l.startColor = BeatlineColors[t.Importance];
Expand Down Expand Up @@ -442,24 +450,27 @@ private void UpdateVertical()
HideExceededVerticalInstance();
}

public float AttachBeatline(float z)
public int AttachBeatlineTimingFromFos(float z)
{
if (!EnableBeatline) return z;
if (beatlineInUse == 0) return z;
var timingGroup = AdeTimingEditor.Instance.currentTimingGroup;
int defaultTiming=ArcTimingManager.Instance.CalculateTimingByPosition(-z * 1000, timingGroup) - ArcAudioManager.Instance.AudioOffset;
if (!EnableBeatline) return defaultTiming;
if (beatlineInUse == 0) return defaultTiming;
List<float> deltas = new List<float>();
for (int i = 0; i < beatlineInUse; ++i)
{
float lz = beatlineInstances[i].GetPosition(0).y;
float lz = beatlineInstances[i].renderer.GetPosition(0).y;
deltas.Add(Mathf.Abs(lz - z));
}
int index = deltas.IndexOf(deltas.Min());
if (index < 0)
{
return z;
return defaultTiming;
}
float tz = beatlineInstances[index].GetPosition(0).y;
if (Mathf.Abs(tz - z) < 5f) return tz;
return z;
float tz = beatlineInstances[index].renderer.GetPosition(0).y;
int t = beatlineInstances[index].timing;
if (Mathf.Abs(tz - z) < 5f) return t;
return defaultTiming;
}
public float AttachVerticalX(float x)
{
Expand Down

0 comments on commit a15fb1d

Please sign in to comment.