Commit b6e8f197 authored by 16이상민's avatar 16이상민

Refactoring JudgeManager

parent 97d54097
......@@ -67,6 +67,54 @@ public class InputManager : MonoBehaviour {
}
}
public InputStatus ShortMotionStat
{
get
{
if (ClapStat == InputStatus.Entered ||
JumpStat == InputStatus.Entered ||
PushUpLeftStat == InputStatus.Entered ||
PushUpRightStat == InputStatus.Entered ||
PushUpBothStat == InputStatus.Entered ||
GuardLeftStat == InputStatus.Entered ||
GuardRightStat == InputStatus.Entered ||
GuardBothStat == InputStatus.Entered)
return InputStatus.Entered;
return InputStatus.None;
}
}
public InputStatus LongMotionStat
{
get
{
if (HandUpLeftStat == InputStatus.Entered ||
HandUpLeftStat == InputStatus.Continuing ||
HandUpRightStat == InputStatus.Entered ||
HandUpRightStat == InputStatus.Continuing ||
HandUpBothStat == InputStatus.Entered ||
HandUpBothStat == InputStatus.Continuing ||
HandDownLeftStat == InputStatus.Entered ||
HandDownLeftStat == InputStatus.Continuing ||
HandDownRightStat == InputStatus.Entered ||
HandDownRightStat == InputStatus.Continuing ||
HandDownBothStat == InputStatus.Entered ||
HandDownBothStat == InputStatus.Continuing ||
JesusStat == InputStatus.Entered ||
JesusStat == InputStatus.Continuing ||
HeadphoneLeftStat == InputStatus.Entered ||
HeadphoneLeftStat == InputStatus.Continuing ||
HeadphoneRightStat == InputStatus.Entered ||
HeadphoneRightStat == InputStatus.Continuing ||
HeadphoneBothStat == InputStatus.Entered ||
HeadphoneBothStat == InputStatus.Continuing ||
OnTheTableStat == InputStatus.Entered ||
OnTheTableStat == InputStatus.Continuing)
return InputStatus.Entered;
return InputStatus.None;
}
}
public InputStatus ClapStat
{ get { return ShortMotionToInput("Clap"); } }
public InputStatus JumpStat
......@@ -75,25 +123,70 @@ public class InputManager : MonoBehaviour {
{ get { return ShortMotionToInput("PushUpLeft"); } }
public InputStatus PushUpRightStat
{ get { return ShortMotionToInput("PushUpRight"); } }
public InputStatus PushUpBothStat
{
get
{
var left = PushUpLeftStat;
var right = PushUpRightStat;
return left == right ? left : InputStatus.None;
}
}
public InputStatus GuardLeftStat
{ get { return ShortMotionToInput("GuardLeft"); } }
public InputStatus GuardRightStat
{ get { return ShortMotionToInput("GuardRight"); } }
public InputStatus GuardBothStat
{
get
{
var left = GuardLeftStat;
var right = GuardRightStat;
return left == right ? left : InputStatus.None;
}
}
public InputStatus HandUpLeftStat
{ get { return LongMotionToInput("HandUpLeft"); } }
public InputStatus HandUpRightStat
{ get { return LongMotionToInput("HandUpRight"); } }
public InputStatus HandUpBothStat
{
get
{
var left = HandUpLeftStat;
var right = HandUpRightStat;
return left == right ? left : InputStatus.None;
}
}
public InputStatus HandDownLeftStat
{ get { return LongMotionToInput("HandDownLeft"); } }
public InputStatus HandDownRightStat
{ get { return LongMotionToInput("HandDownRight"); } }
public InputStatus HandDownBothStat
{
get
{
var left = HandDownLeftStat;
var right = HandDownRightStat;
return left == right ? left : InputStatus.None;
}
}
public InputStatus JesusStat
{ get { return LongMotionToInput("Jesus"); } }
public InputStatus HeadphoneLeftStat
{ get { return LongMotionToInput("HeadphoneLeft"); } }
public InputStatus HeadphoneRightStat
{ get { return LongMotionToInput("HeadphoneRight"); } }
public InputStatus HeadphoneBothStat
{
get
{
var left = HeadphoneLeftStat;
var right = HeadphoneRightStat;
return left == right ? left : InputStatus.None;
}
}
public InputStatus OnTheTableStat
{ get { return LongMotionToInput("OnTheTable"); } }
......
......@@ -6,9 +6,9 @@ public class Judge
{
public static readonly List<Judge> JudgeList = new List<Judge>
{
new Judge("PERFECT") { ButtonTimingRange = 80f, Score = 2, Color = Color.cyan },
new Judge("GOOD") { ButtonTimingRange = 100f, Score = 1, Color = Color.yellow },
new Judge("BAD") { ButtonTimingRange = 120f, Color = Color.blue, IsBreak = true },
new Judge("PERFECT") { ButtonTimingRange = PerfectTime, Score = 2, Color = Color.cyan },
new Judge("GOOD") { ButtonTimingRange = GoodTime, Score = 1, Color = Color.yellow },
new Judge("BAD") { ButtonTimingRange = BadTime, Color = Color.blue, IsBreak = true },
new Judge("MISS") { Color = Color.red, IsBreak = true }
};
......@@ -24,18 +24,23 @@ public class Judge
public string Name { get; private set; }
private const float PerfectTime = 80f,
GoodTime = 100f,
BadTime = 120f;
public float ButtonTimingRange { get; private set; }
public int Score { get; private set; }
public bool IsBreak { get; private set; }
public Color Color { get; private set; }
public static readonly Judge BAD = JudgeList[2];
public static readonly Judge MISS = JudgeList.Last();
public static readonly
float MaxButtonTimingRange = JudgeList[2].ButtonTimingRange;
float MaxButtonTimingRange = BadTime;
public static Judge TestJudge(Note note, float elapsedTime, bool isLong = false, bool test = false)
public static Judge TestJudge(Note note, float elapsedTime, bool end = false, bool test = false)
{
float timing = isLong ? note.EndTiming : note.StartTiming;
float timing = end ? note.EndTiming : note.StartTiming;
float difference = elapsedTime - timing;
if (test)
......@@ -45,4 +50,21 @@ public class Judge
return result.Count == 0 ? JudgeList.Last() : result[0];
}
public static bool IsPastNote(Note note, float elapsedTime)
{
float timing = note.IsLong && note.Activated ? note.EndTiming : note.StartTiming;
return elapsedTime - timing > BadTime;
}
public static bool IsNoteEnd(Note note, float elapsedTime)
{
return elapsedTime - note.EndTiming <= BadTime;
}
public static bool IsNoteComboBroken(Judge judge)
{
return judge == BAD ||
judge == MISS;
}
}
\ No newline at end of file
......@@ -26,6 +26,8 @@ public class JudgeManager : MonoBehaviour
float scrollMultiplier = 1.0f;
float startOffset = -5f;
bool IsGameEnd;
private GameObject offset;
private GameObject noteobj, smobj, lmobj;
private MotionGageManager motionGageManager;
......@@ -67,6 +69,7 @@ public class JudgeManager : MonoBehaviour
initialPos = offset.transform.position;
judgeText.SetActive(false);
motionGageManager.ResetGuage();
IsGameEnd = false;
}
void LoadGameObjects()
......@@ -84,13 +87,6 @@ public class JudgeManager : MonoBehaviour
LoadGameObjects();
}
private bool IsNoteEnd()
{
return noteobj.transform.childCount <= 0 &&
smobj.transform.childCount <= 0 &&
lmobj.transform.childCount <= 0;
}
// Update is called once per frame
void Update()
{
......@@ -100,146 +96,104 @@ public class JudgeManager : MonoBehaviour
motionGageManager.UpdateGuage();
if (IsNoteEnd())
if (noteobj.transform.childCount == 0 ||
IsGameEnd)
Invoke("ShowResult", 2f);
ButtonNoteProc(timing);
MotionNoteProc(timing);
JudgeNote(timing);
}
void MotionNoteProc(float timing)
void JudgeNote(float timing)
{
if (smobj.transform.childCount <= 0)
Note note = GetLastNote(timing);
if (note == null)
return;
GameObject smo = smobj.transform.GetChild(0).gameObject;
MotionNote smnote = (MotionNote)smo.GetComponent<Note.Controller>().Instance;
smnote.Checkpoint();
if (note.IsLong)
JudgeLongNote(note, timing);
else
JudgeShortNote(note, timing);
}
if (!smnote.Activated && timing >= (smnote.StartTiming - MsPerBeat))
{
GameObject motionSample = Instantiate(motionSampleDisplayPrefab);
MotionSampleDisplay msd = motionSample.GetComponent<MotionSampleDisplay>();
msd.sprite = smnote.Image;
msd.timeout = MsPerBeat;
smnote.MotionSampleDisplay = msd;
smnote.Activated = true;
}
if (timing >= (smnote.StartTiming - Judge.MaxButtonTimingRange))
Note GetLastNote(float timing)
{
while (noteobj.transform.childCount != 0)
{
if (smnote.FinalJudgeAction() || (timing > (smnote.EndTiming + Judge.MaxButtonTimingRange)))
{
SetJudge(Judge.TestJudge(smnote, timing, true), true);
DeactivateNote(smnote);
}
var note = noteobj.transform.GetChild(0).gameObject
.GetComponent<Note.Controller>().Instance;
if (!Judge.IsPastNote(note, timing))
return note;
SetJudge(Judge.MISS);
DeactivateNote(note);
}
// Debug.Log("T: " + timing + " nQ: " + activatedNotes.Count);
/*
for(int i=activatedNotes.Count-1;i>=0;i--)
{
MotionNote note = activatedNotes[i];
if (note.FinalJudgeAction() || (timing > (note.EndTiming + Judge.MaxButtonTimingRange)))
{
SetJudge(Judge.TestJudge(note, timing + 350, false), true);
activatedNotes.RemoveAt(i);
DeactivateNote(note);
}
}*/
/*
if (lmobj.transform.childCount <= 0)
return;
GameObject lmo = lmobj.transform.GetChild(0).gameObject;
MotionNote lmnote = (MotionNote)lmo.GetComponent<Note.Controller>().Instance;
lmnote.Checkpoint();
if (!lmnote.Activated && elapsedTime >= (lmnote.StartTiming - MsPerBeat))
{
GameObject motionSample = Instantiate(motionSampleDisplayPrefab);
MotionSampleDisplay msd = motionSample.GetComponent<MotionSampleDisplay>();
msd.sprite = lmnote.Image;
msd.timeout = MsPerBeat;
lmnote.Activated = true;
lmnote.MotionSampleDisplay = msd;
activatedNotes.Add(lmnote);
}
for (int i = activatedNotes.Count - 1; i >= 0; i--)
{
MotionNote note = activatedNotes[i];
if (elapsedTime > note.StartTiming)
MotionGuageReset(note.Length);
if (note.FinalJudgeAction() || elapsedTime > note.EndTiming + Judge.MaxButtonTimingRange)
{
SetJudge(Judge.TestJudge(note, timing, true));
activatedNotes.RemoveAt(i);
DeactivateNote(note);
MotionGuageReset();
}
}
*/
return null;
}
void ButtonNoteProc(float timing)
void JudgeShortNote(Note note, float timing)
{
if (noteobj.transform.childCount <= 0)
return;
GameObject obj = noteobj.transform.GetChild(0).gameObject;
Note note = obj.GetComponent<Note.Controller>().Instance;
if (NoteCondition.IsWrongInput(note))
WrongNoteProc(note);
else if (NoteCondition.IsShortNoteEntered(note))
EnteredNoteProc(note, timing);
}
if (IsRemainLongNoteProc(note, timing))
return;
void JudgeLongNote(Note note, float timing)
{
if (NoteCondition.IsWrongInput(note))
WrongNoteProc(note);
else if (NoteCondition.IsLongNoteStartCorrectly(note))
EnteredNoteProc(note, timing);
else if (NoteCondition.IsLongNoteHoldCorrectly(note))
ContinuingNoteProc(note, timing);
else if (NoteCondition.IsLongNoteFinishCorrectly(note, timing))
CorrectlyStoppedNoteProc(note, timing);
else if (NoteCondition.IsLongNoteFinishIncorrectly(note, timing))
IncorrectlyStoppedNoteProc(note, timing);
}
Judge judge = Judge.TestJudge(note, timing);
void WrongNoteProc(Note note)
{
SetJudge(Judge.MISS);
DeactivateNote(note);
if (judge == Judge.MISS)
if (!(note is MotionNote))
{
SetJudge(judge);
DeactivateNote(note);
IsGameEnd = true;
Invoke("ShowResult", 2f);
}
}
if (InputManager.Instance.ButtonStat == ButtonStatus.Pressed)
{
SetJudge(judge);
if (judge == Judge.MISS) // Empty Miss
return;
void EnteredNoteProc(Note note, float timing)
{
SetJudge(Judge.TestJudge(note, timing));
if (note.IsLong)
note.Activated = true;
else
DeactivateNote(note);
}
if (!note.IsLong)
DeactivateNote(note);
}
bool IsRemainLongNoteProc(Note note, float timing)
void ContinuingNoteProc(Note note, float timing)
{
if (!note.IsLong ||
!note.Activated ||
InputManager.Instance.ButtonStat == ButtonStatus.Pressed)
return false;
if (InputManager.Instance.ButtonStat == ButtonStatus.Released)
{
SetJudge(Judge.TestJudge(note, timing), true);
DeactivateNote(note);
return true;
}
bool isNoteEnd = Judge.IsNoteEnd(note, timing);
var judge = Judge.TestJudge(note, timing, isNoteEnd);
SetJudge(judge);
if (Judge.TestJudge(note, timing, true) == Judge.MISS)
{
SetJudge(Judge.MISS);
if (isNoteEnd ||
NoteCondition.IsNoteBroken(note, timing, judge))
DeactivateNote(note);
}
}
void CorrectlyStoppedNoteProc(Note note, float timing)
{
SetJudge(Judge.TestJudge(note, timing, true));
DeactivateNote(note);
}
return true;
void IncorrectlyStoppedNoteProc(Note note, float timing)
{
var judge = Judge.TestJudge(note, timing, note.Activated);
SetJudge(Judge.IsNoteComboBroken(judge) ? judge : Judge.MISS);
DeactivateNote(note);
}
private void DeactivateNote(Note note)
......@@ -274,7 +228,8 @@ public class JudgeManager : MonoBehaviour
obj.AddComponent<Note.Controller>().Instance = note;
SetNoteParent(note, obj);
if (note.Type == NoteType.MeasureLine || note.Type == NoteType.BeatLine)
obj.transform.SetParent(offset.transform);
if (note.IsLong)
StretchLongNote(note, obj);
......@@ -283,16 +238,6 @@ public class JudgeManager : MonoBehaviour
(Vector3.right * (note.StartTiming * ScrollSpeed));
}
void SetNoteParent(Note note, GameObject obj)
{
if (note is MotionNote && !note.IsLong)
obj.transform.SetParent(smobj.transform);
else if (note is MotionNote && note.IsLong)
obj.transform.SetParent(lmobj.transform);
else if (note.Type == NoteType.MeasureLine || note.Type == NoteType.BeatLine)
obj.transform.SetParent(offset.transform);
}
void StretchLongNote(Note note, GameObject obj)
{
float length = note.Length * ScrollSpeed;
......@@ -318,9 +263,80 @@ public class JudgeManager : MonoBehaviour
onResult = true;
}
}
private class NoteCondition
{
public static Dictionary<string, InputStatus> JudgeInput(Note note)
{
if (note is MotionNote)
return new Dictionary<string, InputStatus>
{
{ "short", InputManager.Instance.ShortMotionStat },
{ "long", InputManager.Instance.LongMotionStat }
};
return new Dictionary<string, InputStatus>
{
{ "short", InputManager.Instance.ShortButtonStat },
{ "long", InputManager.Instance.LongButtonStat }
};
}
public static bool IsShortNoteEntered(Note note)
{
return JudgeInput(note)["short"] == InputStatus.Entered;
}
public static bool IsLongNoteStartCorrectly(Note note)
{
return JudgeInput(note)["long"] == InputStatus.Entered &&
!note.Activated;
}
public static bool IsLongNoteHoldCorrectly(Note note)
{
var stat = JudgeInput(note);
return (
stat["long"] == InputStatus.Entered ||
stat["long"] == InputStatus.Continuing
) &&
note.Activated;
}
public static bool IsLongNoteFinishCorrectly(Note note, float timing)
{
return JudgeInput(note)["long"] == InputStatus.Stopped &&
note.Activated &&
Judge.IsNoteEnd(note, timing);
}
public static bool IsLongNoteFinishIncorrectly(Note note, float timing)
{
var stat = JudgeInput(note);
return stat["long"] == InputStatus.Stopped &&
(
!note.Activated ||
!Judge.IsNoteEnd(note, timing)
);
}
public static bool IsWrongInput(Note note)
{
var stat = JudgeInput(note);
return stat["short"] == InputStatus.Entered ||
stat["long"] == InputStatus.Entered ||
stat["long"] == InputStatus.Continuing;
}
public static bool IsNoteBroken(Note note, float timing, Judge judge)
{
return note.IsLong &&
!Judge.IsNoteEnd(note, timing) &&
(judge == Judge.BAD || judge == Judge.MISS);
}
}
}
internal class MotionGageManager : MonoBehaviour
class MotionGageManager : MonoBehaviour
{
public GameObject motionGuage;
private float elapsedMotion;
......
......@@ -41,7 +41,7 @@ public class TrackManager : MonoBehaviour {
}
bool IsPressedStart
{ get { return InputManager.Instance.Status == ButtonStatus.Pressed; } }
{ get { return InputManager.Instance.ButtonStat == ButtonStatus.Pressed; } }
// Use this for initialization
void Start()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment