Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
ButtonPusher
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Button Pusher
ButtonPusher
Commits
b6e8f197
Commit
b6e8f197
authored
7 years ago
by
16이상민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring JudgeManager
parent
97d54097
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
270 additions
and
139 deletions
+270
-139
InputManager.cs
Assets/Script/InputManager.cs
+93
-0
Judge.cs
Assets/Script/Judge.cs
+28
-6
JudgeManager.cs
Assets/Script/JudgeManager.cs
+148
-132
TrackManager.cs
Assets/Script/TrackManager.cs
+1
-1
No files found.
Assets/Script/InputManager.cs
View file @
b6e8f197
...
...
@@ -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"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Assets/Script/Judge.cs
View file @
b6e8f197
...
...
@@ -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
].
ButtonTimingRang
e
;
float
MaxButtonTimingRange
=
BadTim
e
;
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
This diff is collapsed.
Click to expand it.
Assets/Script/JudgeManager.cs
View file @
b6e8f197
...
...
@@ -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,148 +96,106 @@ 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
(!
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
))
{
if
(
smnote
.
FinalJudgeAction
()
||
(
timing
>
(
smnote
.
EndTiming
+
Judge
.
MaxButtonTimingRange
)))
{
SetJudge
(
Judge
.
TestJudge
(
smnote
,
timing
,
true
),
true
);
DeactivateNote
(
smnote
);
}
if
(
note
.
IsLong
)
JudgeLongNote
(
note
,
timing
);
else
JudgeShortNote
(
note
,
timing
);
}
// Debug.Log("T: " + timing + " nQ: " + activatedNotes.Count);
/*
for(int i=activatedNotes.Count-1;i>=0;i--)
Note
GetLastNote
(
float
timing
)
{
MotionNote note = activatedNotes[i];
if (note.FinalJudgeAction() || (timing > (note.EndTiming + Judge.MaxButtonTimingRange)))
while
(
noteobj
.
transform
.
childCount
!=
0
)
{
SetJudge(Judge.TestJudge(note, timing + 350, false), true);
activatedNotes.RemoveAt(i);
var
note
=
noteobj
.
transform
.
GetChild
(
0
).
gameObject
.
GetComponent
<
Note
.
Controller
>().
Instance
;
if
(!
Judge
.
IsPastNote
(
note
,
timing
))
return
note
;
SetJudge
(
Judge
.
MISS
);
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();
return
null
;
}
if (!lmnote.Activated && elapsedTime >= (lmnote.StartTiming - MsPerBeat)
)
void
JudgeShortNote
(
Note
note
,
float
timing
)
{
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);
if
(
NoteCondition
.
IsWrongInput
(
note
))
WrongNoteProc
(
note
);
else
if
(
NoteCondition
.
IsShortNoteEntered
(
note
))
EnteredNoteProc
(
note
,
timing
);
}
for (int i = activatedNotes.Count - 1; i >= 0; i--
)
void
JudgeLongNote
(
Note
note
,
float
timing
)
{
MotionNote note = activatedNotes[i];
if (elapsedTime > note.StartTiming)
MotionGuageReset(note.Length);
if (note.FinalJudgeAction() || elapsedTime > note.EndTiming + Judge.MaxButtonTimingRange)
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
);
}
void
WrongNoteProc
(
Note
note
)
{
SetJudge(Judge.TestJudge(note, timing, true));
activatedNotes.RemoveAt(i);
SetJudge
(
Judge
.
MISS
);
DeactivateNote
(
note
);
MotionGuageReset();
}
if
(!(
note
is
MotionNote
))
{
IsGameEnd
=
true
;
Invoke
(
"ShowResult"
,
2f
);
}
*/
}
void
ButtonNoteProc
(
float
timing
)
void
EnteredNoteProc
(
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
(
IsRemainLongNoteProc
(
note
,
timing
))
return
;
Judge
judge
=
Judge
.
TestJudge
(
note
,
timing
);
SetJudge
(
Judge
.
TestJudge
(
note
,
timing
));
if
(
judge
==
Judge
.
MISS
)
{
SetJudge
(
judge
);
if
(!
note
.
IsLong
)
DeactivateNote
(
note
);
}
if
(
InputManager
.
Instance
.
ButtonStat
==
ButtonStatus
.
Pressed
)
void
ContinuingNoteProc
(
Note
note
,
float
timing
)
{
bool
isNoteEnd
=
Judge
.
IsNoteEnd
(
note
,
timing
);
var
judge
=
Judge
.
TestJudge
(
note
,
timing
,
isNoteEnd
);
SetJudge
(
judge
);
if
(
judge
==
Judge
.
MISS
)
// Empty Miss
return
;
if
(
note
.
IsLong
)
note
.
Activated
=
true
;
else
if
(
isNoteEnd
||
NoteCondition
.
IsNoteBroken
(
note
,
timing
,
judge
))
DeactivateNote
(
note
);
}
}
bool
IsRemainLong
NoteProc
(
Note
note
,
float
timing
)
void
CorrectlyStopped
NoteProc
(
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
);
SetJudge
(
Judge
.
TestJudge
(
note
,
timing
,
true
));
DeactivateNote
(
note
);
return
true
;
}
if
(
Judge
.
TestJudge
(
note
,
timing
,
true
)
==
Judge
.
MISS
)
void
IncorrectlyStoppedNoteProc
(
Note
note
,
float
timing
)
{
SetJudge
(
Judge
.
MISS
);
var
judge
=
Judge
.
TestJudge
(
note
,
timing
,
note
.
Activated
);
SetJudge
(
Judge
.
IsNoteComboBroken
(
judge
)
?
judge
:
Judge
.
MISS
);
DeactivateNote
(
note
);
}
return
true
;
}
private
void
DeactivateNote
(
Note
note
)
{
note
.
Activated
=
false
;
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
Assets/Script/TrackManager.cs
View file @
b6e8f197
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment