Skip to content

Commit

Permalink
feat: AutoPlay switch
Browse files Browse the repository at this point in the history
fix: Hold/TouchHold judge
fix: Wifi slide checker
feat: more scoring methods
  • Loading branch information
LeZi9916 committed Aug 9, 2024
1 parent 234175f commit 1ba9b67
Show file tree
Hide file tree
Showing 13 changed files with 567 additions and 318 deletions.
5 changes: 2 additions & 3 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -61.2, y: -35.86}
m_AnchoredPosition: {x: -61.2, y: -31.4}
m_SizeDelta: {x: 15.358, y: 33.7}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &393224021
Expand Down Expand Up @@ -4245,7 +4245,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
mainCamera: {fileID: 519420031}
AutoPlay: 1
--- !u!224 &601344169
RectTransform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -10672,7 +10671,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -77.116, y: -35.86}
m_AnchoredPosition: {x: -77.116, y: -31.4}
m_SizeDelta: {x: 15.358, y: 33.7}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1678688328
Expand Down
15 changes: 7 additions & 8 deletions Assets/Scripts/Misc/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
public class InputManager : MonoBehaviour
{
public Camera mainCamera;
public static bool AutoPlay { get; set; } = true;
public static AutoPlayMode Mode { get; private set; } = AutoPlayMode.DJAuto;
public Dictionary<int,List<Sensor>> triggerSensors = new();

//public event EventHandler<InputEventArgs> OnSensorStatusChanged;
public event EventHandler<InputEventArgs>? OnButtonStatusChanged;

Guid guid = Guid.NewGuid();

List<GameObject> sensorObjs = new();
Expand Down Expand Up @@ -52,7 +49,12 @@ void Update()
CheckButton();

if (Input.GetKeyDown(KeyCode.Home))
AutoPlay = !AutoPlay;
{
if (Mode == AutoPlayMode.Disable)
Mode = AutoPlayMode.Enable;
else
Mode++;
}
if (Input.GetMouseButton(0))
PositionHandle(-1, Input.mousePosition);
else
Expand Down Expand Up @@ -123,9 +125,6 @@ public bool CheckAreaStatus(SensorType sType,SensorStatus targetStatus)
}
public bool CheckSensorStatus(SensorType target,SensorStatus targetStatus)
{
if (target > SensorType.A8)
throw new InvalidOperationException("Button index cannot greater than A8");

var sensor = sensorObjs[(int)target].GetComponent<Sensor>();
return sensor.Status == targetStatus;
}
Expand Down
91 changes: 55 additions & 36 deletions Assets/Scripts/Notes/HoldDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ private void Start()
}
private void FixedUpdate()
{
var autoPlay = InputManager.AutoPlay;
var timing = GetJudgeTiming();
var remainingTime = GetRemainingTime();

Expand All @@ -116,22 +115,47 @@ private void FixedUpdate()
Destroy(holdEffect);
Destroy(gameObject);
}
else if (isJudged) // 头部判定完成后开始累计按压时长
else if(timing >= -0.01f)
{
var on = inputManager.CheckAreaStatus(sensorPos,SensorStatus.On);

if (remainingTime < 0.2f && remainingTime != 0)
return;
else if(timing > 0.1f)
// AutoPlay相关
switch (InputManager.Mode)
{
if (on)
{
userHoldTime += Time.fixedDeltaTime;
case AutoPlayMode.Enable:
if(!isJudged)
objectCounter.NextNote(startPosition);
judgeResult = JudgeType.Perfect;
isJudged = true;
PlayHoldEffect();
}
else
StopHoldEffect();
return;
case AutoPlayMode.DJAuto:
if (!isJudged)
manager.SetSensorOn(sensor.Type, guid);
break;
case AutoPlayMode.Random:
if (!isJudged)
{
objectCounter.NextNote(startPosition);
judgeResult = (JudgeType)UnityEngine.Random.Range(1, 14);
isJudged = true;
}
PlayHoldEffect();
return;
case AutoPlayMode.Disable:
manager.SetSensorOff(sensor.Type, guid);
break;
}
}

if (isJudged) // 头部判定完成后开始累计按压时长
{
var on = inputManager.CheckAreaStatus(sensorPos,SensorStatus.On);
if (on)
{
userHoldTime += Time.fixedDeltaTime;
PlayHoldEffect();
}
else
StopHoldEffect();
}
else if (timing > 0.15f) // 头部Miss
{
Expand All @@ -141,30 +165,14 @@ private void FixedUpdate()
isJudged = true;
objectCounter.NextNote(startPosition);
}

// AutoPlay相关
if(autoPlay)
{
if(timing > 0 && !isJudged ||
isJudged && remainingTime > 0)
{
manager.SetSensorOn(sensor.Type, guid);
isAutoTrigger = true;
}
else if(remainingTime == 0)
manager.SetSensorOff(sensor.Type, guid);
}
else if(isAutoTrigger)
{
manager.SetSensorOff(sensor.Type, guid);
isAutoTrigger = false;
}
}
void Check(object sender, InputEventArgs arg)
{
if (arg.Type != sensor.Type)
return;
if (isJudged || !noteManager.CanJudge(gameObject, startPosition))
else if (isJudged || !noteManager.CanJudge(gameObject, startPosition))
return;
else if (InputManager.Mode is AutoPlayMode.Enable or AutoPlayMode.Random)
return;
if (arg.IsClick)
{
Expand Down Expand Up @@ -322,7 +330,7 @@ private void OnDestroy()
if (HttpHandler.IsReloding)
return;
var realityHT = LastFor - 0.3f - (judgeDiff / 1000f);
var percent = MathF.Min(1, userHoldTime / realityHT);
var percent = MathF.Min(1, (userHoldTime - 0.3f) / realityHT);
JudgeType result = judgeResult;
if(realityHT > 0)
{
Expand Down Expand Up @@ -361,6 +369,19 @@ private void OnDestroy()
result = (int)judgeResult < 7 ? JudgeType.LateGood : JudgeType.FastGood;
}
}

switch (InputManager.Mode)
{
case AutoPlayMode.Enable:
result = JudgeType.Perfect;
break;
case AutoPlayMode.Random:
result = (JudgeType)UnityEngine.Random.Range(1, 14);
break;
case AutoPlayMode.DJAuto:
case AutoPlayMode.Disable:
break;
}
var effectManager = GameObject.Find("NoteEffects").GetComponent<NoteEffectManager>();
effectManager.PlayEffect(startPosition, isBreak, result);
effectManager.PlayFastLate(startPosition, result);
Expand All @@ -370,9 +391,7 @@ private void OnDestroy()
if (!isJudged)
objectCounter.NextNote(startPosition);

if (InputManager.AutoPlay)
manager.SetSensorOff(sensor.Type, guid);

manager.SetSensorOff(sensor.Type, guid);
inputManager.UnbindArea(Check, sensorPos);
}
protected override void PlayHoldEffect()
Expand Down
2 changes: 0 additions & 2 deletions Assets/Scripts/Notes/NoteDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public class NoteLongDrop : NoteDrop

protected virtual void PlayHoldEffect()
{
if (InputManager.AutoPlay)
manager.SetSensorOn(sensor.Type, guid);
var material = holdEffect.GetComponent<ParticleSystemRenderer>().material;
switch (judgeResult)
{
Expand Down
92 changes: 71 additions & 21 deletions Assets/Scripts/Notes/SlideDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ void GetSensors(RectTransform[] sensors)
}
private void FixedUpdate()
{
if (InputManager.Mode is AutoPlayMode.Enable or AutoPlayMode.Random)
return;

/// time 是Slide启动的时间点
/// timeStart 是Slide完全显示但未启动
/// LastFor 是Slide的时值
Expand All @@ -323,12 +326,12 @@ private void FixedUpdate()

if (ConnectInfo.IsGroupPart)
{
if (ConnectInfo.IsGroupPartHead && startTiming >= -0.050f)
if (ConnectInfo.IsGroupPartHead && startTiming >= -0.05f)
canCheck = true;
else if (!ConnectInfo.IsGroupPartHead)
canCheck = ConnectInfo.ParentFinished || ConnectInfo.ParentPendingFinish;
}
else if (startTiming >= -0.050f)
else if (startTiming >= -0.05f)
canCheck = true;

if (timing > 0)
Expand Down Expand Up @@ -367,9 +370,15 @@ private void Update()
var startiming = timeProvider.AudioTime - timeStart;
if (startiming <= 0f)
{
if (!fadeInAnimator.enabled && startiming >= fadeInTime)
if (startiming >= -0.05f)
{
fadeInAnimator.enabled = false;
setSlideBarAlpha(1f);
}
else if (!fadeInAnimator.enabled && startiming >= fadeInTime)
fadeInAnimator.enabled = true;
return;

}
fadeInAnimator.enabled = false;
setSlideBarAlpha(1f);
Expand Down Expand Up @@ -423,6 +432,8 @@ public void Check()
return;
else if (isChecking)
return;
else if (InputManager.Mode is AutoPlayMode.Enable or AutoPlayMode.Random)
return;
isChecking = true;
if (ConnectInfo.Parent != null && judgeQueue.Count < _judgeQueue.Count)
{
Expand Down Expand Up @@ -491,7 +502,9 @@ void HideBar(int endIndex)
/// </summary>
void Running()
{
if (star_slide == null || !InputManager.AutoPlay)
if (star_slide == null)
return;
else if (InputManager.Mode is AutoPlayMode.Enable or AutoPlayMode.Random or AutoPlayMode.Disable)
return;

var starRadius = 0.763736616f;
Expand Down Expand Up @@ -571,32 +584,39 @@ void Judge()
else
judge = JudgeType.Perfect;
}

switch (judge)
{
case JudgeType.FastGreat:
slideOK.GetComponent<LoadJustSprite>().setFastGr();
break;
case JudgeType.FastGood:
slideOK.GetComponent<LoadJustSprite>().setFastGd();
break;
case JudgeType.LateGood:
slideOK.GetComponent<LoadJustSprite>().setLateGd();
break;
case JudgeType.LateGreat:
slideOK.GetComponent<LoadJustSprite>().setLateGr();
break;

}
print($"Slide diff : {MathF.Round(diff * 1000,2)} ms");
judgeResult = judge ?? JudgeType.Miss;
SetJust();
isJudged = true;
}
else if (arriveTime < starTiming && timeProvider.AudioTime >= starTiming + stayTime * 0.8)
DestroySelf();
else if (arriveTime >= starTiming && timeProvider.AudioTime >= arriveTime + stayTime * 0.8)
DestroySelf();
}
void SetJust()
{
switch (judgeResult)
{
case JudgeType.FastGreat2:
case JudgeType.FastGreat1:
case JudgeType.FastGreat:
slideOK.GetComponent<LoadJustSprite>().setFastGr();
break;
case JudgeType.FastGood:
slideOK.GetComponent<LoadJustSprite>().setFastGd();
break;
case JudgeType.LateGood:
slideOK.GetComponent<LoadJustSprite>().setLateGd();
break;
case JudgeType.LateGreat1:
case JudgeType.LateGreat2:
case JudgeType.LateGreat:
slideOK.GetComponent<LoadJustSprite>().setLateGr();
break;

}
}
/// <summary>
/// 计算引导Star进入最后一个判定区的时机
/// </summary>
Expand Down Expand Up @@ -685,6 +705,17 @@ void OnDestroy()
Destroy(star_slide);
if (ConnectInfo.IsGroupPartEnd || !ConnectInfo.IsConnSlide)
{
switch(InputManager.Mode)
{
case AutoPlayMode.Enable:
judgeResult = JudgeType.Perfect;
SetJust();
break;
case AutoPlayMode.Random:
judgeResult = (JudgeType)UnityEngine.Random.Range(1, 14);
SetJust();
break;
}
// 只有组内最后一个Slide完成 才会显示判定条并增加总数
objectCounter.ReportResult(this, judgeResult, isBreak);
if (isBreak && judgeResult == JudgeType.Perfect)
Expand Down Expand Up @@ -717,6 +748,16 @@ void UpdateStar()

if(process == 1)
{
switch (InputManager.Mode)
{
case AutoPlayMode.Enable:
case AutoPlayMode.Random:
var barIndex = areaStep[(int)(process * (areaStep.Count - 1))];
HideBar(barIndex);
DestroySelf();
judgeQueue.Clear();
return;
}
star_slide.transform.position = slidePositions.LastOrDefault();
applyStarRotation(slideRotations.LastOrDefault());
if (ConnectInfo.IsConnSlide && !ConnectInfo.IsGroupPartEnd)
Expand All @@ -743,6 +784,15 @@ void UpdateStar()
applyStarRotation(newRotation);
}
}
switch(InputManager.Mode)
{
case AutoPlayMode.Enable:
case AutoPlayMode.Random:
var barIndex = areaStep[(int)(process * (areaStep.Count - 1))];
judgeQueue = judgeQueue.Skip((int)(process * (judgeQueue.Count - 1))).ToList();
HideBar(barIndex);
break;
}
}

private void setSlideBarAlpha(float alpha)
Expand Down
Loading

0 comments on commit 1ba9b67

Please sign in to comment.