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

Refactoring & Previous code integration complete

parent ea1802aa
......@@ -24,23 +24,23 @@ public class Guard : MotionNote
{
case "BG":
hand = Hand.Both;
image = LoadNewSprite("BG");
image = LoadNewSprite("Assets/MotionNotes/BG.png");
prepare = MotionState.GUARD_BASE_LEFT | MotionState.GUARD_BASE_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;
break;
case "LG":
hand = Hand.Left;
image = LoadNewSprite("LG");
image = LoadNewSprite("Assets/MotionNotes/LG.png");
prepare = MotionState.GUARD_BASE_LEFT
| MotionState.HAND_MOVE_DOWN_LEFT;
done = MotionState.GUARD_BASE_LEFT
done = MotionState.GUARD_BASE_LEFT
| MotionState.HAND_MOVE_UP_LEFT;
break;
case "RG":
hand = Hand.Right;
image = LoadNewSprite("RG");
image = LoadNewSprite("Assets/MotionNotes/RG.png");
prepare = MotionState.GUARD_BASE_RIGHT
| MotionState.HAND_MOVE_DOWN_RIGHT;
done = MotionState.GUARD_BASE_RIGHT
......
......@@ -24,17 +24,17 @@ public class HandDown : MotionNote
{
case "BD":
hand = Hand.Both;
image = LoadNewSprite("BD");
done = MotionState.HAND_DOWN_LEFT | MotionState.HAND_DOWN_RIGHT;
image = LoadNewSprite("Assets/MotionNotes/BD.png");
done = MotionState.HAND_DOWN_LEFT | MotionState.HAND_DOWN_RIGHT;
break;
case "LD":
hand = Hand.Left;
image = LoadNewSprite("LD");
done = MotionState.HAND_DOWN_LEFT;
image = LoadNewSprite("Assets/MotionNotes/LD.png");
done = MotionState.HAND_DOWN_LEFT;
break;
case "RD":
hand = Hand.Right;
image = LoadNewSprite("RD");
image = LoadNewSprite("Assets/MotionNotes/RD.png");
done = MotionState.HAND_DOWN_RIGHT;
break;
}
......@@ -43,7 +43,7 @@ public class HandDown : MotionNote
{
}
public override void Checkpoint()
public override void Checkpoint()
{
IsChecked = true;
}
......
......@@ -24,17 +24,17 @@ public class HandUp : MotionNote
{
case "BU":
hand = Hand.Both;
image = LoadNewSprite("BU");
done = MotionState.HAND_UP_LEFT | MotionState.HAND_UP_RIGHT;
image = LoadNewSprite("Assets/MotionNotes/BU.png");
done = MotionState.HAND_UP_LEFT | MotionState.HAND_UP_RIGHT;
break;
case "LU":
hand = Hand.Left;
image = LoadNewSprite("LU");
done = MotionState.HAND_UP_LEFT;
image = LoadNewSprite("Assets/MotionNotes/LU.png");
done = MotionState.HAND_UP_LEFT;
break;
case "RU":
hand = Hand.Right;
image = LoadNewSprite("RU");
image = LoadNewSprite("Assets/MotionNotes/RU.png");
done = MotionState.HAND_UP_RIGHT;
break;
}
......@@ -43,7 +43,7 @@ public class HandUp : MotionNote
{
}
public override void Checkpoint()
public override void Checkpoint()
{
IsChecked = true;
}
......
......@@ -24,17 +24,17 @@ public class Headphone : MotionNote
{
case "BH":
hand = Hand.Both;
image = LoadNewSprite("BH");
done = MotionState.HEADPHONE_LEFT | MotionState.HEADPHONE_RIGHT;
image = LoadNewSprite("Assets/MotionNotes/BH.png");
done = MotionState.HEADPHONE_LEFT | MotionState.HEADPHONE_RIGHT;
break;
case "LH":
hand = Hand.Left;
image = LoadNewSprite("LH");
done = MotionState.HEADPHONE_LEFT;
image = LoadNewSprite("Assets/MotionNotes/LH.png");
done = MotionState.HEADPHONE_LEFT;
break;
case "RH":
hand = Hand.Right;
image = LoadNewSprite("RH");
image = LoadNewSprite("Assets/MotionNotes/RH.png");
done = MotionState.HEADPHONE_RIGHT;
break;
}
......
......@@ -24,22 +24,40 @@ public class PushUp : MotionNote
{
case "BP":
hand = Hand.Both;
image = LoadNewSprite("BP");
image = LoadNewSprite("Assets/MotionNotes/BP.png");
prepare = MotionState.HAND_MOVE_UP_LEFT | MotionState.HAND_MOVE_UP_RIGHT;
done = MotionState.HAND_MOVE_DOWN_LEFT | MotionState.HAND_MOVE_DOWN_RIGHT;
break;
case "LP":
hand = Hand.Left;
image = LoadNewSprite("LP");
image = LoadNewSprite("Assets/MotionNotes/LP.png");
prepare = MotionState.HAND_MOVE_UP_LEFT;
done = MotionState.HAND_MOVE_DOWN_LEFT;
break;
case "RP":
hand = Hand.Right;
image = LoadNewSprite("RP");
image = LoadNewSprite("Assets/MotionNotes/RP.png");
prepare = MotionState.HAND_MOVE_UP_RIGHT;
done = MotionState.HAND_MOVE_DOWN_RIGHT;
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)
......
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using Windows.Kinect;
using System.IO;
using UnityEngine.UI;
public class InputManager : MonoBehaviour {
private static InputManager instance;
......@@ -29,40 +24,315 @@ public class InputManager : MonoBehaviour {
get { return Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.Joystick1Button0); }
}
private MotionState PrevMotionState { get; set; }
public MotionState CurrentMotionState { get; set; }
public bool IsButtonPressed
public ButtonStatus ButtonStat
{
get
{
return !IsButtonDownPrev && IsButtonDown;
if (!IsButtonDown)
return ButtonStatus.Released;
if (IsButtonDownPrev)
return ButtonStatus.Holding;
return ButtonStatus.Pressed;
}
}
public bool IsButtonReleased
public InputStatus ShortButtonStat
{
get
{
return IsButtonDownPrev && !IsButtonDown;
if (!IsButtonDownPrev &&
IsButtonDown)
return InputStatus.Entered;
return InputStatus.None;
}
}
public bool IsButtonHolding
public InputStatus LongButtonStat
{
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
void Start()
{
}
public InputStatus ClapStat
{ 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
void Update()
{
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
new Judge("MISS") { Color = Color.red, IsBreak = true }
};
internal Judge()
private Judge()
{
ButtonTimingRange = 0f;
Score = 0;
......@@ -20,7 +20,7 @@ public class Judge
Color = Color.black;
}
internal Judge(string name) : this() { Name = name; }
private Judge(string name) : this() { Name = name; }
public string Name { get; private set; }
......@@ -33,9 +33,9 @@ public class Judge
public static readonly
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;
if (test)
......@@ -45,10 +45,4 @@ public class Judge
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
private GameObject offset;
private GameObject noteobj, smobj, lmobj;
private GameObject motionGuage;
private MotionGageManager motionGageManager;
private GameObject judgeText;
private GameObject motionSampleDisplayPrefab;
private Vector3 initialPos;
private float elapsedTime = 0;
private float MsPerBeat
{
get
......@@ -53,165 +51,107 @@ public class JudgeManager : MonoBehaviour
}
}
private float elapsedMotion;
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()
void SetObjectRef()
{
offset = GameObject.Find("Offset");
noteobj = GameObject.Find("Noteobj");
smobj = GameObject.Find("SMobj");
lmobj = GameObject.Find("LMobj");
judgeText = GameObject.Find("Judge");
motionGuage = GameObject.Find("Motion Guage");
motionSampleDisplayPrefab = Resources.Load("Motion Sample Display") as GameObject;
motionGageManager = new MotionGageManager
{ motionGuage = GameObject.Find("Motion Guage") };
}
void JudgeInit()
{
initialPos = offset.transform.position;
judgeText.SetActive(false);
MotionGuageReset();
LoadNotes();
motionGageManager.ResetGuage();
}
void LoadGameObjects()
{
motionSampleDisplayPrefab = Resources.Load("Motion Sample Display") as GameObject;
GameManager.Instance.CurrentTrack.Notes.ForEach(LoadNote);
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
void Update()
{
elapsedTime += Time.deltaTime * 1000;
float timing = elapsedTime;
float timing = motionGageManager.UpdateTime(); ;
offset.transform.position = new Vector3(-timing * ScrollSpeed, 0, 0);
offset.transform.position = Vector3.left * timing * ScrollSpeed;
motionGageManager.UpdateGuage();
MotionGuageUpdate();
if (noteobj.transform.childCount <= 0
&& smobj.transform.childCount <= 0
&& lmobj.transform.childCount <= 0)
if (IsNoteEnd())
Invoke("ShowResult", 2f);
new Action(() =>
{
if (noteobj.transform.childCount <= 0)
return;
ButtonNoteProc(timing);
GameObject obj = noteobj.transform.GetChild(0).gameObject;
Note note = obj.GetComponent<Note.Controller>().Instance;
MotionNoteProc(timing);
}
if (note.IsLong && note.Activated)
{
if (InputManager.Instance.IsButtonHolding)
{
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;
}
}
void MotionNoteProc(float timing)
{
if (smobj.transform.childCount <= 0)
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))
{
SetJudge(judge);
DeactivateNote(note);
}
smnote.Checkpoint();
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);
if (judge == Judge.MISS) // Empty Miss
{
return;
}
if (note.IsLong)
note.Activated = true;
else
DeactivateNote(note);
SetJudge(Judge.TestJudge(smnote, timing, true), true);
DeactivateNote(smnote);
}
})();
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))
{
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))
/*
for(int i=activatedNotes.Count-1;i>=0;i--)
{
MotionNote note = activatedNotes[i];
if (note.FinalJudgeAction() || (timing > (note.EndTiming + Judge.MaxButtonTimingRange)))
{
if (smnote.FinalJudgeAction() || (timing > (smnote.EndTiming + Judge.MaxButtonTimingRange)))
{
SetJudge(Judge.TestJudge(smnote, timing, true), true);
DeactivateNote(smnote);
}
SetJudge(Judge.TestJudge(note, timing + 350, false), true);
activatedNotes.RemoveAt(i);
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);
}
}*/
})();
/*
new Action(() =>
{
if (lmobj.transform.childCount <= 0)
if (lmobj.transform.childCount <= 0)
return;
GameObject lmo = lmobj.transform.GetChild(0).gameObject;
......@@ -244,8 +184,62 @@ public class JudgeManager : MonoBehaviour
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)
......@@ -258,7 +252,7 @@ public class JudgeManager : MonoBehaviour
private void SetJudge(Judge judge, bool isMotion = false)
{
if (!judge.IsBreak)
GameManager.Instance.Combo++;
++GameManager.Instance.Combo;
else
GameManager.Instance.Combo = 0;
GameManager.Instance.Score += judge.Score;
......@@ -271,27 +265,22 @@ public class JudgeManager : MonoBehaviour
judgeText.GetComponent<Text>().color = judge.Color;
}
private void LoadNotes()
void LoadNote(Note note)
{
var notes = GameManager.Instance.CurrentTrack.Notes;
foreach (Note note in notes)
{
GameObject obj = Instantiate(
GameObject obj = Instantiate(
Resources.Load(note.Type.ToString(), typeof(GameObject)),
noteobj.transform)
as GameObject;
SetNoteParent(note, obj);
obj.AddComponent<Note.Controller>().Instance = note;
if (note.IsLong)
StretchLongNote(note, obj);
SetNoteParent(note, obj);
obj.transform.position += initialPos +
(Vector3.right * (note.StartTiming * ScrollSpeed));
if (note.IsLong)
StretchLongNote(note, obj);
obj.AddComponent<Note.Controller>().Instance = note;
}
obj.transform.position += initialPos +
(Vector3.right * (note.StartTiming * ScrollSpeed));
}
void SetNoteParent(Note note, GameObject obj)
......@@ -315,8 +304,8 @@ public class JudgeManager : MonoBehaviour
holdTransform.SetSizeWithCurrentAnchors(
RectTransform.Axis.Horizontal, length);
holdTransform.position += new Vector3(length / 2, 0, 0);
endTransform.position += new Vector3(length, 0, 0);
holdTransform.position += (Vector3.right * length / 2);
endTransform.position += (Vector3.right * length);
}
private bool onResult = false;
......@@ -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
{
var tracked = body.Where(x => x != null && x.IsTracked).ToList();
if (tracked.Count() == 0 || tracked[0].Joints == null)
{
discriminator.Initialize();
return MotionState.UNKNOWN;
}
discriminator.Update(tracked[0]);
......@@ -67,8 +64,6 @@ internal class MotionDiscriminator
{
DistItvExtractor extractor;
bool initialized = true;
private MotionState _Motion;
public MotionState Motion
......@@ -84,19 +79,17 @@ internal class MotionDiscriminator
Initialize();
}
public void Initialize()
private void Initialize()
{
_Motion = MotionState.UNKNOWN;
initialized = true;
}
public void Update(KinectModule.IBody body)
{
extractor.Extract(body);
Initialize();
Determine();
initialized = false;
}
float Distance(CameraSpacePoint a, CameraSpacePoint b)
......@@ -110,6 +103,7 @@ internal class MotionDiscriminator
{
Clap();
Jump();
Hurray();
HandMove();
GuardBase();
HandUp();
......@@ -135,21 +129,21 @@ internal class MotionDiscriminator
void Jump()
{
const float distPrepare = 0.05f, distDone = 0.0f;
if (initialized)
return;
if (extractor.DistSpine < distPrepare)
_Motion |= MotionState.JUMP_PREPARE;
else if (extractor.DistSpine > distDone)
_Motion |= MotionState.JUMP_DONE;
}
void HandMove()
void Hurray()
{
if (initialized || extractor.DistHandBaseHead <= 0.0f)
return;
if (extractor.DistHandBaseHead > 0)
_Motion |= MotionState.HURRAY;
}
void HandMove()
{
if (extractor.DistHandLeft > 0)
_Motion |= MotionState.HAND_MOVE_UP_LEFT;
else if (extractor.DistHandLeft < 0)
......
......@@ -28,6 +28,21 @@ public class TrackManager : MonoBehaviour {
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
void Start()
{
......@@ -41,23 +56,32 @@ public class TrackManager : MonoBehaviour {
// Update is called once per frame
void Update()
{
if (trackList.transform.childCount < 0)
return;
ScrollTrackList();
if (Input.GetKeyDown(KeyCode.DownArrow))
{
trackList.transform.GetChild(0).SetAsLastSibling();
TrackBrowse();
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
trackList.transform.GetChild(trackList.transform.childCount - 1).SetAsFirstSibling();
TrackBrowse();
}
if (InputManager.Instance.IsButtonPressed)
if (IsPressedStart)
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()
{
return new DirectoryInfo("Assets/Tracks")
......@@ -117,4 +141,11 @@ public class TrackManager : MonoBehaviour {
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