Files
Convention-Unity-Demo/Assets/Scripts/Interaction/Interaction/FullScreenInteraction.cs
2025-12-15 17:20:55 +08:00

96 lines
2.9 KiB
C#

using Convention;
using Demo.Game.Attr;
using System.IO;
using UnityEngine;
namespace Demo.Game
{
namespace ConfigType
{
// FullScreenInteraction 配置
public class FullScreenInteractionConfig : IInteractionConfig
{
public bool IsNeedTap;
public override void Deserialize(BinaryReader reader)
{
IsNeedTap = BinarySerializeUtility.ReadBool(reader);
base.Deserialize(reader);
}
public override void Serialize(BinaryWriter writer)
{
BinarySerializeUtility.WriteBool(writer, IsNeedTap);
base.Serialize(writer);
}
}
}
[Scriptable]
public class FullScreenInteraction : IInteraction
{
public static FullScreenInteraction Make()
{
return new GameObject().AddComponent<FullScreenInteraction>();
}
[Content] public bool IsNeedTap = true;
[Content, SerializeField] private bool IsJudgement = false;
[Content, SerializeField] private bool IsReleaseJudgementEffect = false;
/// <summary>
/// 设置为Hold模式, 即不需要点按即可判定的模式
/// </summary>
[Convention.RScript.Variable.Attr.Method]
public void EnableHoldMode()
{
IsNeedTap = false;
}
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
{
base.UpdateTicks(currentTime, deltaTime, tickType);
if (tickType == TickType.Pause || tickType == TickType.Reset)
{
IsJudgement = false;
IsReleaseJudgementEffect = false;
}
}
public override JudgementLevel JudgementBehaviour(float timePoint)
{
var stats = timePoint > GetBestJudgementTimePoint();
if (IsJudgement)
{
if (IsNeedTap)
return JudgementLevel.None;
else if (stats && IsReleaseJudgementEffect == false)
{
IsReleaseJudgementEffect = true;
return JudgementLevel.BestLevel;
}
else
return JudgementLevel.None;
}
if (GetRoot().RootGameController.IsAutoPlay)
return stats ? JudgementLevel.BestLevel: JudgementLevel.None;
var inputs = GetRoot().InputCatch;
var index = inputs.FindIndex(x => IsInInteractiveDuration(x.TimePoint));
if (index != -1)
{
if (IsNeedTap)
{
inputs.RemoveAt(index);
return JudgementLevel.Default;
}
else
{
IsJudgement = true;
return JudgementLevel.None;
}
}
return JudgementLevel.None;
}
}
}