97 lines
3.1 KiB
C#
97 lines
3.1 KiB
C#
using System.Collections;
|
|
using Ichni.RhythmGame.Beatmap;
|
|
using UnityEngine;
|
|
|
|
namespace Ichni.RhythmGame
|
|
{
|
|
public class TouchAreaJudgeUnit : NoteJudgeUnit
|
|
{
|
|
public float areaRadius;
|
|
|
|
protected override GameObject GetHintImagePrefab()
|
|
{
|
|
return GameManager.instance.basePrefabs.areaHint;
|
|
}
|
|
|
|
private float CurrentScreenRatio()
|
|
{
|
|
float ratio = Screen.width / 1920f;
|
|
return ratio;
|
|
}
|
|
|
|
public TouchAreaJudgeUnit(NoteBase note, float areaRadius) : base(note)
|
|
{
|
|
this.areaRadius = areaRadius;
|
|
}
|
|
|
|
public override void UpdateJudge()
|
|
{
|
|
if ((note is not Hold && note.isFirstJudged)||(note is Hold && note.isFinalJudged)) return;
|
|
Vector2 noteScreenPosition = note.noteScreenPosition;
|
|
RectTransform canvasRect = GameManager.instance.judgeHintCanvas.GetComponent<RectTransform>();
|
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, noteScreenPosition, null, out Vector2 uiPosition))
|
|
{
|
|
judgeHintImage.anchoredPosition = uiPosition;
|
|
judgeHintImage.sizeDelta = new Vector2(areaRadius * 2, areaRadius * 2) * CurrentScreenRatio();
|
|
}
|
|
}
|
|
|
|
public override NoteJudgeUnit_BM ConvertToBM()
|
|
{
|
|
return new TouchAreaJudgeUnit_BM(areaRadius);
|
|
}
|
|
|
|
public override bool CheckJudgeAvailability(InputUnit inputUnit)
|
|
{
|
|
Vector2 inputScreenPosition = inputUnit.inputPosition;
|
|
Vector2 noteScreenPosition = note.GetScreenPosition();
|
|
|
|
float distance = Vector2.Distance(inputScreenPosition, noteScreenPosition);
|
|
|
|
if (distance <= areaRadius * CurrentScreenRatio())
|
|
{
|
|
if (inputUnit is InputUnitSwipe swipe && note is Flick flick)
|
|
{
|
|
return flick.CheckSwipeDirection(swipe);
|
|
}
|
|
#if UNITY_EDITOR
|
|
Debug.Log("Input Position: " + inputScreenPosition +
|
|
", Note Position: " + noteScreenPosition +
|
|
", Distance: " + distance +
|
|
", Area Radius: " + areaRadius +
|
|
", Current Screen Ratio: " + CurrentScreenRatio());
|
|
#endif
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
namespace Beatmap
|
|
{
|
|
public class TouchAreaJudgeUnit_BM : NoteJudgeUnit_BM
|
|
{
|
|
public float areaRadius;
|
|
|
|
public TouchAreaJudgeUnit_BM()
|
|
{
|
|
|
|
}
|
|
|
|
public TouchAreaJudgeUnit_BM(float areaRadius)
|
|
{
|
|
this.areaRadius = areaRadius;
|
|
}
|
|
|
|
public override NoteJudgeUnit ConvertToGameType(NoteBase attachedNote)
|
|
{
|
|
#if UNITY_EDITOR || UNITY_STANDALONE
|
|
return new FullScreenNearTimeJudgeUnit(attachedNote);
|
|
#elif UNITY_ANDROID || UNITY_IOS
|
|
return new TouchAreaJudgeUnit(attachedNote, areaRadius);
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
} |