2025-06-03 02:42:28 -04:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2025-07-21 05:42:20 -04:00
|
|
|
using System.Linq;
|
2025-06-03 02:42:28 -04:00
|
|
|
using Ichni.RhythmGame;
|
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
using UnityEngine.InputSystem.EnhancedTouch;
|
|
|
|
|
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
|
|
|
|
|
using TouchPhase = UnityEngine.InputSystem.TouchPhase;
|
|
|
|
|
|
|
|
|
|
namespace Ichni
|
|
|
|
|
{
|
|
|
|
|
public class InputManager : SerializedMonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public List<Tap> checkingTapList;
|
|
|
|
|
public List<Stay> checkingStayList;
|
|
|
|
|
public List<Hold> checkingHoldList;
|
|
|
|
|
public List<Flick> checkingFlickList;
|
|
|
|
|
|
|
|
|
|
public List<InputUnitTap> inputUnitTapList;
|
2025-07-21 05:42:20 -04:00
|
|
|
public List<InputUnitTouch> inputUnitTouchList;
|
|
|
|
|
public List<InputUnitSwipe> inputUnitSwipeList;
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
checkingTapList = new List<Tap>();
|
|
|
|
|
checkingStayList = new List<Stay>();
|
|
|
|
|
checkingHoldList = new List<Hold>();
|
|
|
|
|
checkingFlickList = new List<Flick>();
|
|
|
|
|
inputUnitTapList = new List<InputUnitTap>();
|
|
|
|
|
inputUnitTouchList = new List<InputUnitTouch>();
|
|
|
|
|
inputUnitSwipeList = new List<InputUnitSwipe>();
|
|
|
|
|
RhythmInputManager.OnTap += SetNewInputUnitTap;
|
|
|
|
|
RhythmInputManager.OnTouch += SetNewInputUnitTouch;
|
|
|
|
|
RhythmInputManager.OnSwipe += SetNewInputUnitSwipe;
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2025-07-08 14:28:40 -04:00
|
|
|
if (!GameManager.instance.audioManager.isPlaying)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
foreach (InputUnitTap inputUnitTap in inputUnitTapList)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
|
|
|
|
List<Tap> availableTaps = new List<Tap>();
|
|
|
|
|
foreach (Tap tap in checkingTapList)
|
|
|
|
|
{
|
|
|
|
|
if (tap.CheckJudgeAvailability(inputUnitTap))
|
|
|
|
|
{
|
|
|
|
|
availableTaps.Add(tap);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
|
|
|
List<Hold> availableHolds = new List<Hold>();
|
|
|
|
|
foreach (Hold hold in checkingHoldList)
|
|
|
|
|
{
|
|
|
|
|
if (hold.CheckJudgeAvailability(inputUnitTap))
|
|
|
|
|
{
|
|
|
|
|
availableHolds.Add(hold);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool haveHold = availableHolds.Count > 0;
|
|
|
|
|
bool haveTap = availableTaps.Count > 0;
|
|
|
|
|
|
|
|
|
|
Hold closestHold = availableHolds.Min();
|
|
|
|
|
Tap closestTap = availableTaps.Min();
|
2025-06-03 02:42:28 -04:00
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
if (haveHold && haveTap)
|
|
|
|
|
{
|
|
|
|
|
if (closestHold.exactJudgeTime < closestTap.exactJudgeTime)
|
|
|
|
|
{
|
|
|
|
|
closestHold.ExecuteStartJudge();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
closestTap.ExecuteStartJudge();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (haveHold)
|
|
|
|
|
{
|
|
|
|
|
closestHold.ExecuteStartJudge();
|
|
|
|
|
}
|
|
|
|
|
else if (haveTap)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
|
|
|
|
closestTap.ExecuteStartJudge();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
|
|
|
foreach (InputUnitSwipe inputUnitSwipe in inputUnitSwipeList)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
List<Flick> availableFlicks = new List<Flick>();
|
|
|
|
|
|
2025-06-03 02:42:28 -04:00
|
|
|
foreach (Flick flick in checkingFlickList)
|
|
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
if (flick.CheckJudgeAvailability(inputUnitSwipe))
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
|
|
|
|
availableFlicks.Add(flick);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-21 05:42:20 -04:00
|
|
|
|
2025-06-03 02:42:28 -04:00
|
|
|
if (availableFlicks.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
availableFlicks.Sort();
|
|
|
|
|
Flick closestFlick = availableFlicks[0];
|
2025-07-21 05:42:20 -04:00
|
|
|
closestFlick.ExecuteStartJudge();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (InputUnitTouch inputUnitTouch in inputUnitTouchList)
|
|
|
|
|
{
|
2025-06-03 02:42:28 -04:00
|
|
|
List<Stay> availableStays = new List<Stay>();
|
|
|
|
|
foreach (Stay stay in checkingStayList)
|
|
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
if (stay.CheckJudgeAvailability(inputUnitTouch))
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
|
|
|
|
availableStays.Add(stay);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
|
|
|
List<Hold> availableHolds = new List<Hold>();
|
|
|
|
|
foreach (Hold hold in checkingHoldList)
|
|
|
|
|
{
|
|
|
|
|
if (hold.CheckJudgeAvailability(inputUnitTouch))
|
|
|
|
|
{
|
|
|
|
|
availableHolds.Add(hold);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
|
|
|
foreach (Stay stay in availableStays)
|
|
|
|
|
{
|
|
|
|
|
stay.ExecuteStartJudge();
|
|
|
|
|
}
|
2025-07-21 05:42:20 -04:00
|
|
|
|
|
|
|
|
foreach (Hold hold in availableHolds)
|
|
|
|
|
{
|
|
|
|
|
hold.ExecuteProcessJudge();
|
|
|
|
|
}
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
inputUnitTapList.Clear();
|
|
|
|
|
inputUnitTouchList.Clear();
|
|
|
|
|
inputUnitSwipeList.Clear();
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
public void SetNewInputUnitTap(int fingerId, Vector2 inputPosition)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
InputUnitTap inputUnitTap = new InputUnitTap(fingerId, inputPosition);
|
|
|
|
|
if(!inputUnitTapList.Exists(x => x.fingerId == fingerId))
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
inputUnitTapList.Add(inputUnitTap);
|
|
|
|
|
//Debug.Log("Tap: " + fingerId + " " + inputPosition);
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
public void SetNewInputUnitTouch(int fingerId, Vector2 inputPosition)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
InputUnitTouch inputUnitTouch = new InputUnitTouch(fingerId, inputPosition);
|
|
|
|
|
if(!inputUnitTouchList.Exists(x => x.fingerId == fingerId))
|
|
|
|
|
{
|
|
|
|
|
inputUnitTouchList.Add(inputUnitTouch);
|
|
|
|
|
}
|
|
|
|
|
//Debug.Log("Touch: " + fingerId + " " + inputPosition);
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
2025-07-26 04:20:25 -04:00
|
|
|
public void SetNewInputUnitSwipe(int fingerId, Vector2 inputPosition, bool isGeneric, Vector2 delta)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
2025-07-26 04:20:25 -04:00
|
|
|
InputUnitSwipe inputUnitSwipe = new InputUnitSwipe(fingerId, inputPosition, isGeneric, delta);
|
2025-07-21 05:42:20 -04:00
|
|
|
if(!inputUnitSwipeList.Exists(x => x.fingerId == fingerId))
|
|
|
|
|
{
|
|
|
|
|
inputUnitSwipeList.Add(inputUnitSwipe);
|
|
|
|
|
}
|
|
|
|
|
//Debug.Log("Swipe: " + fingerId + " " + inputPosition + " " + delta);
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class InputUnit
|
|
|
|
|
{
|
|
|
|
|
public int fingerId;
|
|
|
|
|
public Vector2 inputPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class InputUnitTap : InputUnit
|
|
|
|
|
{
|
|
|
|
|
public InputUnitTap(int fingerId, Vector2 inputPosition)
|
|
|
|
|
{
|
|
|
|
|
this.fingerId = fingerId;
|
|
|
|
|
this.inputPosition = inputPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
public class InputUnitTouch : InputUnit
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
public InputUnitTouch(int fingerId, Vector2 inputPosition)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
|
|
|
|
this.fingerId = fingerId;
|
|
|
|
|
this.inputPosition = inputPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-21 05:42:20 -04:00
|
|
|
public class InputUnitSwipe : InputUnit
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
public Vector2 swipeDirection;
|
2025-07-26 04:20:25 -04:00
|
|
|
public bool isGeneric;
|
2025-07-21 05:42:20 -04:00
|
|
|
|
2025-07-26 04:20:25 -04:00
|
|
|
public InputUnitSwipe(int fingerId, Vector2 inputPosition, bool isGeneric, Vector2 swipeDirection)
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
|
|
|
|
this.fingerId = fingerId;
|
|
|
|
|
this.inputPosition = inputPosition;
|
2025-07-26 04:20:25 -04:00
|
|
|
this.isGeneric = isGeneric;
|
2025-07-21 05:42:20 -04:00
|
|
|
this.swipeDirection = swipeDirection.normalized;
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|