Commit 97d54097 authored by 16이상민's avatar 16이상민

Refactoring & Previous code integration complete

parent ea1802aa
...@@ -24,23 +24,23 @@ public class Guard : MotionNote ...@@ -24,23 +24,23 @@ public class Guard : MotionNote
{ {
case "BG": case "BG":
hand = Hand.Both; hand = Hand.Both;
image = LoadNewSprite("BG"); image = LoadNewSprite("Assets/MotionNotes/BG.png");
prepare = MotionState.GUARD_BASE_LEFT | MotionState.GUARD_BASE_RIGHT prepare = MotionState.GUARD_BASE_LEFT | MotionState.GUARD_BASE_RIGHT
| MotionState.HAND_MOVE_DOWN_LEFT | MotionState.HAND_MOVE_DOWN_RIGHT; | MotionState.HAND_MOVE_DOWN_LEFT | MotionState.HAND_MOVE_DOWN_RIGHT;
done = MotionState.GUARD_BASE_LEFT | MotionState.GUARD_BASE_RIGHT done = MotionState.GUARD_BASE_LEFT | MotionState.GUARD_BASE_RIGHT
| MotionState.HAND_MOVE_UP_LEFT | MotionState.HAND_MOVE_UP_RIGHT; | MotionState.HAND_MOVE_UP_LEFT | MotionState.HAND_MOVE_UP_RIGHT;
break; break;
case "LG": case "LG":
hand = Hand.Left; hand = Hand.Left;
image = LoadNewSprite("LG"); image = LoadNewSprite("Assets/MotionNotes/LG.png");
prepare = MotionState.GUARD_BASE_LEFT prepare = MotionState.GUARD_BASE_LEFT
| MotionState.HAND_MOVE_DOWN_LEFT; | MotionState.HAND_MOVE_DOWN_LEFT;
done = MotionState.GUARD_BASE_LEFT done = MotionState.GUARD_BASE_LEFT
| MotionState.HAND_MOVE_UP_LEFT; | MotionState.HAND_MOVE_UP_LEFT;
break; break;
case "RG": case "RG":
hand = Hand.Right; hand = Hand.Right;
image = LoadNewSprite("RG"); image = LoadNewSprite("Assets/MotionNotes/RG.png");
prepare = MotionState.GUARD_BASE_RIGHT prepare = MotionState.GUARD_BASE_RIGHT
| MotionState.HAND_MOVE_DOWN_RIGHT; | MotionState.HAND_MOVE_DOWN_RIGHT;
done = MotionState.GUARD_BASE_RIGHT done = MotionState.GUARD_BASE_RIGHT
......
...@@ -24,17 +24,17 @@ public class HandDown : MotionNote ...@@ -24,17 +24,17 @@ public class HandDown : MotionNote
{ {
case "BD": case "BD":
hand = Hand.Both; hand = Hand.Both;
image = LoadNewSprite("BD"); image = LoadNewSprite("Assets/MotionNotes/BD.png");
done = MotionState.HAND_DOWN_LEFT | MotionState.HAND_DOWN_RIGHT; done = MotionState.HAND_DOWN_LEFT | MotionState.HAND_DOWN_RIGHT;
break; break;
case "LD": case "LD":
hand = Hand.Left; hand = Hand.Left;
image = LoadNewSprite("LD"); image = LoadNewSprite("Assets/MotionNotes/LD.png");
done = MotionState.HAND_DOWN_LEFT; done = MotionState.HAND_DOWN_LEFT;
break; break;
case "RD": case "RD":
hand = Hand.Right; hand = Hand.Right;
image = LoadNewSprite("RD"); image = LoadNewSprite("Assets/MotionNotes/RD.png");
done = MotionState.HAND_DOWN_RIGHT; done = MotionState.HAND_DOWN_RIGHT;
break; break;
} }
...@@ -43,7 +43,7 @@ public class HandDown : MotionNote ...@@ -43,7 +43,7 @@ public class HandDown : MotionNote
{ {
} }
public override void Checkpoint() public override void Checkpoint()
{ {
IsChecked = true; IsChecked = true;
} }
......
...@@ -24,17 +24,17 @@ public class HandUp : MotionNote ...@@ -24,17 +24,17 @@ public class HandUp : MotionNote
{ {
case "BU": case "BU":
hand = Hand.Both; hand = Hand.Both;
image = LoadNewSprite("BU"); image = LoadNewSprite("Assets/MotionNotes/BU.png");
done = MotionState.HAND_UP_LEFT | MotionState.HAND_UP_RIGHT; done = MotionState.HAND_UP_LEFT | MotionState.HAND_UP_RIGHT;
break; break;
case "LU": case "LU":
hand = Hand.Left; hand = Hand.Left;
image = LoadNewSprite("LU"); image = LoadNewSprite("Assets/MotionNotes/LU.png");
done = MotionState.HAND_UP_LEFT; done = MotionState.HAND_UP_LEFT;
break; break;
case "RU": case "RU":
hand = Hand.Right; hand = Hand.Right;
image = LoadNewSprite("RU"); image = LoadNewSprite("Assets/MotionNotes/RU.png");
done = MotionState.HAND_UP_RIGHT; done = MotionState.HAND_UP_RIGHT;
break; break;
} }
...@@ -43,7 +43,7 @@ public class HandUp : MotionNote ...@@ -43,7 +43,7 @@ public class HandUp : MotionNote
{ {
} }
public override void Checkpoint() public override void Checkpoint()
{ {
IsChecked = true; IsChecked = true;
} }
......
...@@ -24,17 +24,17 @@ public class Headphone : MotionNote ...@@ -24,17 +24,17 @@ public class Headphone : MotionNote
{ {
case "BH": case "BH":
hand = Hand.Both; hand = Hand.Both;
image = LoadNewSprite("BH"); image = LoadNewSprite("Assets/MotionNotes/BH.png");
done = MotionState.HEADPHONE_LEFT | MotionState.HEADPHONE_RIGHT; done = MotionState.HEADPHONE_LEFT | MotionState.HEADPHONE_RIGHT;
break; break;
case "LH": case "LH":
hand = Hand.Left; hand = Hand.Left;
image = LoadNewSprite("LH"); image = LoadNewSprite("Assets/MotionNotes/LH.png");
done = MotionState.HEADPHONE_LEFT; done = MotionState.HEADPHONE_LEFT;
break; break;
case "RH": case "RH":
hand = Hand.Right; hand = Hand.Right;
image = LoadNewSprite("RH"); image = LoadNewSprite("Assets/MotionNotes/RH.png");
done = MotionState.HEADPHONE_RIGHT; done = MotionState.HEADPHONE_RIGHT;
break; break;
} }
......
...@@ -24,22 +24,40 @@ public class PushUp : MotionNote ...@@ -24,22 +24,40 @@ public class PushUp : MotionNote
{ {
case "BP": case "BP":
hand = Hand.Both; hand = Hand.Both;
image = LoadNewSprite("BP"); image = LoadNewSprite("Assets/MotionNotes/BP.png");
prepare = MotionState.HAND_MOVE_UP_LEFT | MotionState.HAND_MOVE_UP_RIGHT; prepare = MotionState.HAND_MOVE_UP_LEFT | MotionState.HAND_MOVE_UP_RIGHT;
done = MotionState.HAND_MOVE_DOWN_LEFT | MotionState.HAND_MOVE_DOWN_RIGHT; done = MotionState.HAND_MOVE_DOWN_LEFT | MotionState.HAND_MOVE_DOWN_RIGHT;
break; break;
case "LP": case "LP":
hand = Hand.Left; hand = Hand.Left;
image = LoadNewSprite("LP"); image = LoadNewSprite("Assets/MotionNotes/LP.png");
prepare = MotionState.HAND_MOVE_UP_LEFT; prepare = MotionState.HAND_MOVE_UP_LEFT;
done = MotionState.HAND_MOVE_DOWN_LEFT; done = MotionState.HAND_MOVE_DOWN_LEFT;
break; break;
case "RP": case "RP":
hand = Hand.Right; hand = Hand.Right;
image = LoadNewSprite("RP"); image = LoadNewSprite("Assets/MotionNotes/RP.png");
prepare = MotionState.HAND_MOVE_UP_RIGHT; prepare = MotionState.HAND_MOVE_UP_RIGHT;
done = MotionState.HAND_MOVE_DOWN_RIGHT; done = MotionState.HAND_MOVE_DOWN_RIGHT;
break; break;
case "BK":
hand = Hand.Both;
image = LoadNewSprite("Assets/MotionNotes/BK.png");
prepare = MotionState.HAND_MOVE_UP_LEFT | MotionState.HAND_MOVE_UP_RIGHT | MotionState.JUMP_PREPARE;
done = MotionState.HAND_MOVE_DOWN_LEFT | MotionState.HAND_MOVE_DOWN_RIGHT | MotionState.JUMP_DONE;
break;
case "LK":
hand = Hand.Left;
image = LoadNewSprite("Assets/MotionNotes/LK.png");
prepare = MotionState.HAND_MOVE_UP_LEFT | MotionState.JUMP_PREPARE;
done = MotionState.HAND_MOVE_DOWN_LEFT | MotionState.JUMP_DONE;
break;
case "RK":
hand = Hand.Right;
image = LoadNewSprite("Assets/MotionNotes/RK.png");
prepare = MotionState.HAND_MOVE_UP_RIGHT | MotionState.JUMP_PREPARE;
done = MotionState.HAND_MOVE_DOWN_RIGHT | MotionState.JUMP_DONE;
break;
} }
} }
public PushUp(float start, float end = 0f) : base(start, end) public PushUp(float start, float end = 0f) : base(start, end)
......
using System.Collections; using System;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Windows.Kinect;
using System.IO;
using UnityEngine.UI;
public class InputManager : MonoBehaviour { public class InputManager : MonoBehaviour {
private static InputManager instance; private static InputManager instance;
...@@ -29,40 +24,315 @@ public class InputManager : MonoBehaviour { ...@@ -29,40 +24,315 @@ public class InputManager : MonoBehaviour {
get { return Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.Joystick1Button0); } get { return Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.Joystick1Button0); }
} }
private MotionState PrevMotionState { get; set; }
public MotionState CurrentMotionState { get; set; } public MotionState CurrentMotionState { get; set; }
public bool IsButtonPressed public ButtonStatus ButtonStat
{ {
get get
{ {
return !IsButtonDownPrev && IsButtonDown; if (!IsButtonDown)
return ButtonStatus.Released;
if (IsButtonDownPrev)
return ButtonStatus.Holding;
return ButtonStatus.Pressed;
} }
} }
public bool IsButtonReleased public InputStatus ShortButtonStat
{ {
get get
{ {
return IsButtonDownPrev && !IsButtonDown; if (!IsButtonDownPrev &&
IsButtonDown)
return InputStatus.Entered;
return InputStatus.None;
} }
} }
public bool IsButtonHolding public InputStatus LongButtonStat
{ {
get get
{ {
return IsButtonDownPrev && IsButtonDown; if (!IsButtonDownPrev &&
IsButtonDown)
return InputStatus.Entered;
if (IsButtonDownPrev &&
IsButtonDown)
return InputStatus.Continuing;
if (IsButtonDownPrev &&
!IsButtonDown)
return InputStatus.Stopped;
return InputStatus.None;
} }
} }
// Use this for initialization public InputStatus ClapStat
void Start() { get { return ShortMotionToInput("Clap"); } }
{ public InputStatus JumpStat
} { get { return ShortMotionToInput("Jump"); } }
public InputStatus PushUpLeftStat
{ get { return ShortMotionToInput("PushUpLeft"); } }
public InputStatus PushUpRightStat
{ get { return ShortMotionToInput("PushUpRight"); } }
public InputStatus GuardLeftStat
{ get { return ShortMotionToInput("GuardLeft"); } }
public InputStatus GuardRightStat
{ get { return ShortMotionToInput("GuardRight"); } }
public InputStatus HandUpLeftStat
{ get { return LongMotionToInput("HandUpLeft"); } }
public InputStatus HandUpRightStat
{ get { return LongMotionToInput("HandUpRight"); } }
public InputStatus HandDownLeftStat
{ get { return LongMotionToInput("HandDownLeft"); } }
public InputStatus HandDownRightStat
{ get { return LongMotionToInput("HandDownRight"); } }
public InputStatus JesusStat
{ get { return LongMotionToInput("Jesus"); } }
public InputStatus HeadphoneLeftStat
{ get { return LongMotionToInput("HeadphoneLeft"); } }
public InputStatus HeadphoneRightStat
{ get { return LongMotionToInput("HeadphoneRight"); } }
public InputStatus OnTheTableStat
{ get { return LongMotionToInput("OnTheTable"); } }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
IsButtonDownPrev = IsButtonDown; IsButtonDownPrev = IsButtonDown;
PrevMotionState = CurrentMotionState;
}
private InputStatus LongMotionToInput(string name)
{
Func<MotionState, MotionStatus> extractor = MotionStatusExtractor.GetExtractor(name);
if (extractor == null)
return InputStatus.None;
MotionStatus prev = extractor(PrevMotionState),
curr = extractor(CurrentMotionState);
if (prev == MotionStatus.None &&
(curr & MotionStatus.Prepared) != MotionStatus.None)
return InputStatus.Entered;
if ((prev & MotionStatus.Done) != MotionStatus.None &&
curr == MotionStatus.None)
return InputStatus.Stopped;
if (prev == curr &&
(prev & (MotionStatus.Prepared | MotionStatus.Done)) != MotionStatus.None)
return InputStatus.Continuing;
return InputStatus.None;
} }
private InputStatus ShortMotionToInput(string name)
{
Func<MotionState, MotionStatus> extractor = MotionStatusExtractor.GetExtractor(name);
if (extractor == null)
return InputStatus.None;
MotionStatus prev = extractor(PrevMotionState),
curr = extractor(CurrentMotionState);
if (prev == MotionStatus.Prepared &&
curr == MotionStatus.Done)
return InputStatus.Entered;
return InputStatus.None;
}
private static class MotionStatusExtractor
{
private static bool IsContain(MotionState target, MotionState motion)
{
return (target & motion) == motion;
}
// SHORT NOTES
private static MotionStatus ExtractClap(MotionState state)
{
if (IsContain(state, MotionState.CLAP_PREPARE))
return MotionStatus.Prepared;
if (IsContain(state, MotionState.CLAP_DONE))
return MotionStatus.Prepared;
return MotionStatus.None;
}
private static MotionStatus ExtractJump(MotionState state)
{
if (IsContain(state, MotionState.JUMP_PREPARE))
return MotionStatus.Prepared;
if (IsContain(state, MotionState.JUMP_DONE))
return MotionStatus.Prepared;
return MotionStatus.None;
}
private static MotionStatus ExtractPushUpLeft(MotionState state)
{
if (IsContain(state, MotionState.HURRAY) &&
IsContain(state, MotionState.HAND_MOVE_UP_LEFT))
return MotionStatus.Prepared;
if (IsContain(state, MotionState.HURRAY) &&
IsContain(state, MotionState.HAND_MOVE_DOWN_LEFT))
return MotionStatus.Prepared;
return MotionStatus.None;
}
private static MotionStatus ExtractPushUpRight(MotionState state)
{
if (IsContain(state, MotionState.HURRAY) &&
IsContain(state, MotionState.HAND_MOVE_UP_RIGHT))
return MotionStatus.Prepared;
if (IsContain(state, MotionState.HURRAY) &&
IsContain(state, MotionState.HAND_MOVE_DOWN_RIGHT))
return MotionStatus.Prepared;
return MotionStatus.None;
}
private static MotionStatus ExtractGuardLeft(MotionState state)
{
if (IsContain(state, MotionState.GUARD_BASE_LEFT) &&
IsContain(state, MotionState.HAND_MOVE_UP_LEFT))
return MotionStatus.Prepared;
if (IsContain(state, MotionState.GUARD_BASE_LEFT) &&
IsContain(state, MotionState.HAND_MOVE_DOWN_LEFT))
return MotionStatus.Prepared;
return MotionStatus.None;
}
private static MotionStatus ExtractGuardRight(MotionState state)
{
if (IsContain(state, MotionState.GUARD_BASE_RIGHT) &&
IsContain(state, MotionState.HAND_MOVE_UP_RIGHT))
return MotionStatus.Prepared;
if (IsContain(state, MotionState.GUARD_BASE_RIGHT) &&
IsContain(state, MotionState.HAND_MOVE_DOWN_RIGHT))
return MotionStatus.Prepared;
return MotionStatus.None;
}
// LONG NOTES
private static MotionStatus ExtractHandUpLeft(MotionState state)
{
if (IsContain(state, MotionState.HAND_UP_LEFT))
return MotionStatus.Prepared |
MotionStatus.Done;
return MotionStatus.None;
}
private static MotionStatus ExtractHandUpRight(MotionState state)
{
if (IsContain(state, MotionState.HAND_UP_RIGHT))
return MotionStatus.Prepared |
MotionStatus.Done;
return MotionStatus.None;
}
private static MotionStatus ExtractHandDownLeft(MotionState state)
{
if (IsContain(state, MotionState.HAND_DOWN_LEFT))
return MotionStatus.Prepared |
MotionStatus.Done;
return MotionStatus.None;
}
private static MotionStatus ExtractHandDownRight(MotionState state)
{
if (IsContain(state, MotionState.HAND_DOWN_RIGHT))
return MotionStatus.Prepared |
MotionStatus.Done;
return MotionStatus.None;
}
private static MotionStatus ExtractJesus(MotionState state)
{
if (IsContain(state, MotionState.JESUS))
return MotionStatus.Prepared |
MotionStatus.Done;
return MotionStatus.None;
}
private static MotionStatus ExtractHeadphoneLeft(MotionState state)
{
if (IsContain(state, MotionState.HEADPHONE_LEFT))
return MotionStatus.Prepared |
MotionStatus.Done;
return MotionStatus.None;
}
private static MotionStatus ExtractHeadphoneRight(MotionState state)
{
if (IsContain(state, MotionState.HEADPHONE_RIGHT))
return MotionStatus.Prepared |
MotionStatus.Done;
return MotionStatus.None;
}
private static MotionStatus ExtractOnTheTable(MotionState state)
{
if (IsContain(state, MotionState.ON_THE_TABLE))
return MotionStatus.Prepared |
MotionStatus.Done;
return MotionStatus.None;
}
public static Func<MotionState, MotionStatus> GetExtractor(string name)
{
if (name.Equals("Clap"))
return ExtractClap;
if (name.Equals("Jump"))
return ExtractJump;
if (name.Equals("PushUpLeft"))
return ExtractPushUpLeft;
if (name.Equals("PushUpRight"))
return ExtractPushUpRight;
if (name.Equals("GuardLeft"))
return ExtractGuardLeft;
if (name.Equals("GuardRight"))
return ExtractGuardRight;
if (name.Equals("HandUpLeft"))
return ExtractHandUpLeft;
if (name.Equals("HandUpRight"))
return ExtractHandUpRight;
if (name.Equals("HandDownLeft"))
return ExtractHandDownLeft;
if (name.Equals("HandDownRight"))
return ExtractHandDownRight;
if (name.Equals("Jesus"))
return ExtractJesus;
if (name.Equals("HeadphoneLeft"))
return ExtractHeadphoneLeft;
if (name.Equals("HeadphoneRight"))
return ExtractHeadphoneRight;
if (name.Equals("OnTheTable"))
return ExtractOnTheTable;
return null;
}
}
}
public enum ButtonStatus
{
Pressed,
Released,
Holding
}
[Flags]
public enum MotionStatus : uint
{
Prepared = 0x1,
Done = 0x2,
None = 0x0
}
public enum InputStatus
{
Entered,
Continuing,
Stopped,
None
} }
\ No newline at end of file
...@@ -12,7 +12,7 @@ public class Judge ...@@ -12,7 +12,7 @@ public class Judge
new Judge("MISS") { Color = Color.red, IsBreak = true } new Judge("MISS") { Color = Color.red, IsBreak = true }
}; };
internal Judge() private Judge()
{ {
ButtonTimingRange = 0f; ButtonTimingRange = 0f;
Score = 0; Score = 0;
...@@ -20,7 +20,7 @@ public class Judge ...@@ -20,7 +20,7 @@ public class Judge
Color = Color.black; Color = Color.black;
} }
internal Judge(string name) : this() { Name = name; } private Judge(string name) : this() { Name = name; }
public string Name { get; private set; } public string Name { get; private set; }
...@@ -33,9 +33,9 @@ public class Judge ...@@ -33,9 +33,9 @@ public class Judge
public static readonly public static readonly
float MaxButtonTimingRange = JudgeList[2].ButtonTimingRange; float MaxButtonTimingRange = JudgeList[2].ButtonTimingRange;
public static Judge TestJudge(Note note, float elapsedTime, bool end = false, bool test = false) public static Judge TestJudge(Note note, float elapsedTime, bool isLong = false, bool test = false)
{ {
float timing = end ? note.EndTiming : note.StartTiming; float timing = isLong ? note.EndTiming : note.StartTiming;
float difference = elapsedTime - timing; float difference = elapsedTime - timing;
if (test) if (test)
...@@ -45,10 +45,4 @@ public class Judge ...@@ -45,10 +45,4 @@ public class Judge
return result.Count == 0 ? JudgeList.Last() : result[0]; return result.Count == 0 ? JudgeList.Last() : result[0];
} }
public static bool IsNonEmptyMiss(Note note, float elapsedTime, bool end = false)
{
float timing = end ? note.EndTiming : note.StartTiming;
return elapsedTime - timing > MaxButtonTimingRange;
}
} }
\ No newline at end of file
...@@ -28,15 +28,13 @@ public class JudgeManager : MonoBehaviour ...@@ -28,15 +28,13 @@ public class JudgeManager : MonoBehaviour
private GameObject offset; private GameObject offset;
private GameObject noteobj, smobj, lmobj; private GameObject noteobj, smobj, lmobj;
private GameObject motionGuage; private MotionGageManager motionGageManager;
private GameObject judgeText; private GameObject judgeText;
private GameObject motionSampleDisplayPrefab; private GameObject motionSampleDisplayPrefab;
private Vector3 initialPos; private Vector3 initialPos;
private float elapsedTime = 0;
private float MsPerBeat private float MsPerBeat
{ {
get get
...@@ -53,165 +51,107 @@ public class JudgeManager : MonoBehaviour ...@@ -53,165 +51,107 @@ public class JudgeManager : MonoBehaviour
} }
} }
private float elapsedMotion; void SetObjectRef()
private float motionTimeout;
private void MotionGuageReset(float timeout = 0f)
{
if (timeout <= 0f)
{
elapsedMotion = 0f;
motionGuage.transform.parent.gameObject.SetActive(false);
return;
}
motionTimeout = timeout;
motionGuage.transform.parent.gameObject.SetActive(true);
motionGuage.SetActive(true);
}
private void MotionGuageUpdate()
{
if (motionGuage.transform.parent.gameObject.activeInHierarchy)
elapsedMotion += Time.deltaTime * 1000f;
if (elapsedMotion >= motionTimeout)
MotionGuageReset();
else
motionGuage.GetComponent<Image>().fillAmount = elapsedMotion / motionTimeout;
}
// Use this for initialization
void Start()
{ {
offset = GameObject.Find("Offset"); offset = GameObject.Find("Offset");
noteobj = GameObject.Find("Noteobj"); noteobj = GameObject.Find("Noteobj");
smobj = GameObject.Find("SMobj"); smobj = GameObject.Find("SMobj");
lmobj = GameObject.Find("LMobj"); lmobj = GameObject.Find("LMobj");
judgeText = GameObject.Find("Judge"); judgeText = GameObject.Find("Judge");
motionGuage = GameObject.Find("Motion Guage"); motionGageManager = new MotionGageManager
{ motionGuage = GameObject.Find("Motion Guage") };
motionSampleDisplayPrefab = Resources.Load("Motion Sample Display") as GameObject; }
void JudgeInit()
{
initialPos = offset.transform.position; initialPos = offset.transform.position;
judgeText.SetActive(false); judgeText.SetActive(false);
MotionGuageReset(); motionGageManager.ResetGuage();
}
LoadNotes();
void LoadGameObjects()
{
motionSampleDisplayPrefab = Resources.Load("Motion Sample Display") as GameObject;
GameManager.Instance.CurrentTrack.Notes.ForEach(LoadNote);
Instantiate(GameManager.Instance.defaultSound); Instantiate(GameManager.Instance.defaultSound);
} }
// Use this for initialization
void Start()
{
SetObjectRef();
JudgeInit();
LoadGameObjects();
}
private bool IsNoteEnd()
{
return noteobj.transform.childCount <= 0 &&
smobj.transform.childCount <= 0 &&
lmobj.transform.childCount <= 0;
}
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
elapsedTime += Time.deltaTime * 1000; float timing = motionGageManager.UpdateTime(); ;
float timing = elapsedTime;
offset.transform.position = new Vector3(-timing * ScrollSpeed, 0, 0); offset.transform.position = Vector3.left * timing * ScrollSpeed;
motionGageManager.UpdateGuage();
MotionGuageUpdate(); if (IsNoteEnd())
if (noteobj.transform.childCount <= 0
&& smobj.transform.childCount <= 0
&& lmobj.transform.childCount <= 0)
Invoke("ShowResult", 2f); Invoke("ShowResult", 2f);
new Action(() => ButtonNoteProc(timing);
{
if (noteobj.transform.childCount <= 0)
return;
GameObject obj = noteobj.transform.GetChild(0).gameObject; MotionNoteProc(timing);
Note note = obj.GetComponent<Note.Controller>().Instance; }
if (note.IsLong && note.Activated) void MotionNoteProc(float timing)
{ {
if (InputManager.Instance.IsButtonHolding) if (smobj.transform.childCount <= 0)
{ return;
if (Judge.IsNonEmptyMiss(note, timing, true))
{
SetJudge(Judge.MISS);
DeactivateNote(note);
}
return;
}
if (InputManager.Instance.IsButtonReleased)
{
SetJudge(Judge.TestJudge(note, timing), true);
DeactivateNote(note);
return;
}
}
Judge judge = Judge.TestJudge(note, timing); GameObject smo = smobj.transform.GetChild(0).gameObject;
MotionNote smnote = (MotionNote)smo.GetComponent<Note.Controller>().Instance;
if (Judge.IsNonEmptyMiss(note, timing)) smnote.Checkpoint();
{
SetJudge(judge);
DeactivateNote(note);
}
if (InputManager.Instance.IsButtonPressed) 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); SetJudge(Judge.TestJudge(smnote, timing, true), true);
DeactivateNote(smnote);
if (judge == Judge.MISS) // Empty Miss
{
return;
}
if (note.IsLong)
note.Activated = true;
else
DeactivateNote(note);
} }
})(); }
new Action(() =>
{
if (smobj.transform.childCount <= 0)
return;
GameObject smo = smobj.transform.GetChild(0).gameObject;
MotionNote smnote = (MotionNote)smo.GetComponent<Note.Controller>().Instance;
smnote.Checkpoint(); // Debug.Log("T: " + timing + " nQ: " + activatedNotes.Count);
if (!smnote.Activated && timing >= (smnote.StartTiming - MsPerBeat)) /*
{ for(int i=activatedNotes.Count-1;i>=0;i--)
GameObject motionSample = Instantiate(motionSampleDisplayPrefab); {
MotionSampleDisplay msd = motionSample.GetComponent<MotionSampleDisplay>(); MotionNote note = activatedNotes[i];
msd.sprite = smnote.Image; if (note.FinalJudgeAction() || (timing > (note.EndTiming + Judge.MaxButtonTimingRange)))
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(note, timing + 350, false), true);
{ activatedNotes.RemoveAt(i);
SetJudge(Judge.TestJudge(smnote, timing, true), true); DeactivateNote(note);
DeactivateNote(smnote);
}
} }
}*/
// 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);
}
}*/
})();
/* /*
new Action(() => if (lmobj.transform.childCount <= 0)
{
if (lmobj.transform.childCount <= 0)
return; return;
GameObject lmo = lmobj.transform.GetChild(0).gameObject; GameObject lmo = lmobj.transform.GetChild(0).gameObject;
...@@ -244,8 +184,62 @@ public class JudgeManager : MonoBehaviour ...@@ -244,8 +184,62 @@ public class JudgeManager : MonoBehaviour
MotionGuageReset(); MotionGuageReset();
} }
} }
})(); */
*/ }
void ButtonNoteProc(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);
if (judge == Judge.MISS)
{
SetJudge(judge);
DeactivateNote(note);
}
if (InputManager.Instance.ButtonStat == ButtonStatus.Pressed)
{
SetJudge(judge);
if (judge == Judge.MISS) // Empty Miss
return;
if (note.IsLong)
note.Activated = true;
else
DeactivateNote(note);
}
}
bool IsRemainLongNoteProc(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;
}
if (Judge.TestJudge(note, timing, true) == Judge.MISS)
{
SetJudge(Judge.MISS);
DeactivateNote(note);
}
return true;
} }
private void DeactivateNote(Note note) private void DeactivateNote(Note note)
...@@ -258,7 +252,7 @@ public class JudgeManager : MonoBehaviour ...@@ -258,7 +252,7 @@ public class JudgeManager : MonoBehaviour
private void SetJudge(Judge judge, bool isMotion = false) private void SetJudge(Judge judge, bool isMotion = false)
{ {
if (!judge.IsBreak) if (!judge.IsBreak)
GameManager.Instance.Combo++; ++GameManager.Instance.Combo;
else else
GameManager.Instance.Combo = 0; GameManager.Instance.Combo = 0;
GameManager.Instance.Score += judge.Score; GameManager.Instance.Score += judge.Score;
...@@ -271,27 +265,22 @@ public class JudgeManager : MonoBehaviour ...@@ -271,27 +265,22 @@ public class JudgeManager : MonoBehaviour
judgeText.GetComponent<Text>().color = judge.Color; judgeText.GetComponent<Text>().color = judge.Color;
} }
private void LoadNotes() void LoadNote(Note note)
{ {
var notes = GameManager.Instance.CurrentTrack.Notes; GameObject obj = Instantiate(
foreach (Note note in notes)
{
GameObject obj = Instantiate(
Resources.Load(note.Type.ToString(), typeof(GameObject)), Resources.Load(note.Type.ToString(), typeof(GameObject)),
noteobj.transform) noteobj.transform)
as GameObject; as GameObject;
SetNoteParent(note, obj); obj.AddComponent<Note.Controller>().Instance = note;
if (note.IsLong) SetNoteParent(note, obj);
StretchLongNote(note, obj);
obj.transform.position += initialPos + if (note.IsLong)
(Vector3.right * (note.StartTiming * ScrollSpeed)); StretchLongNote(note, obj);
obj.AddComponent<Note.Controller>().Instance = note; obj.transform.position += initialPos +
} (Vector3.right * (note.StartTiming * ScrollSpeed));
} }
void SetNoteParent(Note note, GameObject obj) void SetNoteParent(Note note, GameObject obj)
...@@ -315,8 +304,8 @@ public class JudgeManager : MonoBehaviour ...@@ -315,8 +304,8 @@ public class JudgeManager : MonoBehaviour
holdTransform.SetSizeWithCurrentAnchors( holdTransform.SetSizeWithCurrentAnchors(
RectTransform.Axis.Horizontal, length); RectTransform.Axis.Horizontal, length);
holdTransform.position += new Vector3(length / 2, 0, 0); holdTransform.position += (Vector3.right * length / 2);
endTransform.position += new Vector3(length, 0, 0); endTransform.position += (Vector3.right * length);
} }
private bool onResult = false; private bool onResult = false;
...@@ -330,3 +319,42 @@ public class JudgeManager : MonoBehaviour ...@@ -330,3 +319,42 @@ public class JudgeManager : MonoBehaviour
} }
} }
} }
internal class MotionGageManager : MonoBehaviour
{
public GameObject motionGuage;
private float elapsedMotion;
private float motionTimeout;
private float elapsedTime = 0;
public void ResetGuage(float timeout = 0f)
{
if (timeout <= 0f)
{
elapsedMotion = 0f;
motionGuage.transform.parent.gameObject.SetActive(false);
return;
}
motionTimeout = timeout;
motionGuage.transform.parent.gameObject.SetActive(true);
motionGuage.SetActive(true);
}
public void UpdateGuage()
{
if (motionGuage.transform.parent.gameObject.activeInHierarchy)
UpdateTime();
if (elapsedMotion >= motionTimeout)
ResetGuage();
else
motionGuage.GetComponent<Image>().fillAmount = elapsedMotion / motionTimeout;
}
public float UpdateTime()
{
elapsedTime += Time.deltaTime * 1000;
return elapsedTime;
}
}
\ No newline at end of file
...@@ -27,10 +27,7 @@ public class MotionView : MonoBehaviour ...@@ -27,10 +27,7 @@ public class MotionView : MonoBehaviour
{ {
var tracked = body.Where(x => x != null && x.IsTracked).ToList(); var tracked = body.Where(x => x != null && x.IsTracked).ToList();
if (tracked.Count() == 0 || tracked[0].Joints == null) if (tracked.Count() == 0 || tracked[0].Joints == null)
{
discriminator.Initialize();
return MotionState.UNKNOWN; return MotionState.UNKNOWN;
}
discriminator.Update(tracked[0]); discriminator.Update(tracked[0]);
...@@ -67,8 +64,6 @@ internal class MotionDiscriminator ...@@ -67,8 +64,6 @@ internal class MotionDiscriminator
{ {
DistItvExtractor extractor; DistItvExtractor extractor;
bool initialized = true;
private MotionState _Motion; private MotionState _Motion;
public MotionState Motion public MotionState Motion
...@@ -84,19 +79,17 @@ internal class MotionDiscriminator ...@@ -84,19 +79,17 @@ internal class MotionDiscriminator
Initialize(); Initialize();
} }
public void Initialize() private void Initialize()
{ {
_Motion = MotionState.UNKNOWN; _Motion = MotionState.UNKNOWN;
initialized = true;
} }
public void Update(KinectModule.IBody body) public void Update(KinectModule.IBody body)
{ {
extractor.Extract(body); extractor.Extract(body);
Initialize();
Determine(); Determine();
initialized = false;
} }
float Distance(CameraSpacePoint a, CameraSpacePoint b) float Distance(CameraSpacePoint a, CameraSpacePoint b)
...@@ -110,6 +103,7 @@ internal class MotionDiscriminator ...@@ -110,6 +103,7 @@ internal class MotionDiscriminator
{ {
Clap(); Clap();
Jump(); Jump();
Hurray();
HandMove(); HandMove();
GuardBase(); GuardBase();
HandUp(); HandUp();
...@@ -135,21 +129,21 @@ internal class MotionDiscriminator ...@@ -135,21 +129,21 @@ internal class MotionDiscriminator
void Jump() void Jump()
{ {
const float distPrepare = 0.05f, distDone = 0.0f; const float distPrepare = 0.05f, distDone = 0.0f;
if (initialized)
return;
if (extractor.DistSpine < distPrepare) if (extractor.DistSpine < distPrepare)
_Motion |= MotionState.JUMP_PREPARE; _Motion |= MotionState.JUMP_PREPARE;
else if (extractor.DistSpine > distDone) else if (extractor.DistSpine > distDone)
_Motion |= MotionState.JUMP_DONE; _Motion |= MotionState.JUMP_DONE;
} }
void HandMove() void Hurray()
{ {
if (initialized || extractor.DistHandBaseHead <= 0.0f) if (extractor.DistHandBaseHead > 0)
return; _Motion |= MotionState.HURRAY;
}
void HandMove()
{
if (extractor.DistHandLeft > 0) if (extractor.DistHandLeft > 0)
_Motion |= MotionState.HAND_MOVE_UP_LEFT; _Motion |= MotionState.HAND_MOVE_UP_LEFT;
else if (extractor.DistHandLeft < 0) else if (extractor.DistHandLeft < 0)
......
...@@ -28,6 +28,21 @@ public class TrackManager : MonoBehaviour { ...@@ -28,6 +28,21 @@ public class TrackManager : MonoBehaviour {
private GameObject selected = null; private GameObject selected = null;
private KeyDown Pressed
{
get
{
if (Input.GetKeyDown(KeyCode.DownArrow))
return KeyDown.Down;
if (Input.GetKeyDown(KeyCode.UpArrow))
return KeyDown.Up;
return KeyDown.None;
}
}
bool IsPressedStart
{ get { return InputManager.Instance.Status == ButtonStatus.Pressed; } }
// Use this for initialization // Use this for initialization
void Start() void Start()
{ {
...@@ -41,23 +56,32 @@ public class TrackManager : MonoBehaviour { ...@@ -41,23 +56,32 @@ public class TrackManager : MonoBehaviour {
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
if (trackList.transform.childCount < 0) ScrollTrackList();
return;
if (Input.GetKeyDown(KeyCode.DownArrow)) if (IsPressedStart)
{
trackList.transform.GetChild(0).SetAsLastSibling();
TrackBrowse();
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
trackList.transform.GetChild(trackList.transform.childCount - 1).SetAsFirstSibling();
TrackBrowse();
}
if (InputManager.Instance.IsButtonPressed)
StartTrack(); StartTrack();
} }
void ScrollTrackList()
{
if (Pressed == KeyDown.Down)
DownScroll();
else if (Pressed == KeyDown.Up)
UpScroll();
}
void UpScroll()
{
trackList.transform.GetChild(trackList.transform.childCount - 1).SetAsFirstSibling();
TrackBrowse();
}
void DownScroll()
{
trackList.transform.GetChild(0).SetAsLastSibling();
TrackBrowse();
}
IEnumerable<TrackInfo> GenerateTrackInfos() IEnumerable<TrackInfo> GenerateTrackInfos()
{ {
return new DirectoryInfo("Assets/Tracks") return new DirectoryInfo("Assets/Tracks")
...@@ -117,4 +141,11 @@ public class TrackManager : MonoBehaviour { ...@@ -117,4 +141,11 @@ public class TrackManager : MonoBehaviour {
GameManager.Instance.SceneTransition("InGame"); GameManager.Instance.SceneTransition("InGame");
} }
private enum KeyDown
{
Up,
Down,
None
}
} }
\ No newline at end of file
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