Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/Samples/InputRecorder/Game.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions Assets/Samples/InputRecorder/Game/BlueLaneMaterial.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: BlueLaneMaterial
m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.5299323, g: 0.6758197, b: 0.9924528, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []
8 changes: 8 additions & 0 deletions Assets/Samples/InputRecorder/Game/BlueLaneMaterial.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

224 changes: 224 additions & 0 deletions Assets/Samples/InputRecorder/Game/ButtonController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(Collider))]
public class ButtonController : MonoBehaviour
{
private MeshRenderer meshR;

[Header("Textures")]
public Texture2D defaultTexture;
public Texture2D pressedTexture;

[Header("Input System")]
public InputActionReference pressAction;

private System.Collections.Generic.List<NoteObject> notesInLane = new System.Collections.Generic.List<NoteObject>();

Check warning on line 17 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L17

Added line #L17 was not covered by tests

private bool _isButtonHeld = false;
private float _buttonPressTime = 0f;
private const float MIN_HOLD_DURATION = 0.05f; // Minimum 50ms to count as a real release

public float WorldXPosition => transform.position.x;

Check warning on line 23 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L23

Added line #L23 was not covered by tests

private void Awake()
{
meshR = GetComponent<MeshRenderer>();

Check warning on line 27 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L26-L27

Added lines #L26 - L27 were not covered by tests

Collider buttonCollider = GetComponent<Collider>();
if (buttonCollider != null)
{
buttonCollider.isTrigger = true;
if (GetComponent<Rigidbody>() == null)
{
Rigidbody rb = gameObject.AddComponent<Rigidbody>();
rb.isKinematic = true;
}
}

Check warning on line 38 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L29-L38

Added lines #L29 - L38 were not covered by tests
else
{
Debug.LogError("ButtonController needs a Collider component set to Is Trigger and a Rigidbody!", this);
}

Check warning on line 42 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L40-L42

Added lines #L40 - L42 were not covered by tests

if (defaultTexture != null)
meshR.material.mainTexture = defaultTexture;
}

Check warning on line 46 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L44-L46

Added lines #L44 - L46 were not covered by tests

private void OnEnable()
{
if (pressAction != null)
{
pressAction.action.performed += OnInputPressed;
pressAction.action.canceled += OnInputReleased;
pressAction.action.Enable();
}
}

Check warning on line 56 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L49-L56

Added lines #L49 - L56 were not covered by tests

private void OnDisable()
{
if (pressAction != null)
{
pressAction.action.performed -= OnInputPressed;
pressAction.action.canceled -= OnInputReleased;
pressAction.action.Disable();
}
}

Check warning on line 66 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L59-L66

Added lines #L59 - L66 were not covered by tests

private void OnInputPressed(InputAction.CallbackContext ctx)
{
ProcessButtonPress();
}

Check warning on line 71 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L69-L71

Added lines #L69 - L71 were not covered by tests

private void OnInputReleased(InputAction.CallbackContext ctx)
{
ProcessButtonRelease();
}

Check warning on line 76 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L74-L76

Added lines #L74 - L76 were not covered by tests

public void UIButton_Press()
{
ProcessButtonPress();
}

Check warning on line 81 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L79-L81

Added lines #L79 - L81 were not covered by tests

public void UIButton_Release()
{
ProcessButtonRelease();
}

Check warning on line 86 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L84-L86

Added lines #L84 - L86 were not covered by tests

private void ProcessButtonPress()
{

Check warning on line 89 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L89

Added line #L89 was not covered by tests
_isButtonHeld = true;
_buttonPressTime = Time.time;

if (pressedTexture != null)
meshR.material.mainTexture = pressedTexture;

Check warning on line 94 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L93-L94

Added lines #L93 - L94 were not covered by tests

NoteObject bestNormalNote = null;
NoteObject bestHoldNote = null;
float smallestNormalDistance = float.MaxValue;
float smallestHoldDistance = float.MaxValue;

for (int i = notesInLane.Count - 1; i >= 0; i--)
{
NoteObject note = notesInLane[i];

Check warning on line 103 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L101-L103

Added lines #L101 - L103 were not covered by tests

if (note != null && note.gameObject.activeInHierarchy && note.CanBePressed)
{
if (note.noteType == NoteObject.NoteType.Normal)
{
float distance = Mathf.Abs(note.transform.position.x - WorldXPosition);

Check warning on line 109 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L105-L109

Added lines #L105 - L109 were not covered by tests
if (distance < smallestNormalDistance)
{

Check warning on line 111 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L111

Added line #L111 was not covered by tests
smallestNormalDistance = distance;
bestNormalNote = note;
}
}
else if (note.noteType == NoteObject.NoteType.Hold && !note.IsHoldStarted())
{
float distance = Mathf.Abs(note.transform.position.x - WorldXPosition);

Check warning on line 118 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L114-L118

Added lines #L114 - L118 were not covered by tests
if (distance < smallestHoldDistance)
{

Check warning on line 120 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L120

Added line #L120 was not covered by tests
smallestHoldDistance = distance;
bestHoldNote = note;
}
}
}
}

Check warning on line 126 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L124-L126

Added lines #L124 - L126 were not covered by tests

NoteObject bestNoteToHit = bestNormalNote != null ? bestNormalNote : bestHoldNote;

if (bestNoteToHit != null)
{
bestNoteToHit.ProcessNoteHit(WorldXPosition);
}
}

Check warning on line 134 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L130-L134

Added lines #L130 - L134 were not covered by tests

private void ProcessButtonRelease()
{

Check warning on line 137 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L137

Added line #L137 was not covered by tests
float holdDuration = Time.time - _buttonPressTime;

if (holdDuration < MIN_HOLD_DURATION)
{
return;
}

_isButtonHeld = false;

if (defaultTexture != null)
meshR.material.mainTexture = defaultTexture;

Check warning on line 148 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L147-L148

Added lines #L147 - L148 were not covered by tests

for (int i = notesInLane.Count - 1; i >= 0; i--)
{
NoteObject note = notesInLane[i];
if (note != null && note.gameObject.activeInHierarchy && note.noteType == NoteObject.NoteType.Hold && note.IsHolding())
{
note.ProcessNoteRelease();
}
}
}

Check warning on line 158 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L150-L158

Added lines #L150 - L158 were not covered by tests

private void OnTriggerEnter(Collider other)
{
NoteObject note = other.GetComponent<NoteObject>();
if (note != null)
{
if (!notesInLane.Contains(note))
{
notesInLane.Add(note);
note.SetCanBePressed(true, this);
}
}
}

Check warning on line 171 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L161-L171

Added lines #L161 - L171 were not covered by tests

private void OnTriggerExit(Collider other)
{
NoteObject note = other.GetComponent<NoteObject>();
if (note != null)
{

Check warning on line 177 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L174-L177

Added lines #L174 - L177 were not covered by tests
// Check actual input device state using multiple methods
float rawInputValue = pressAction != null ? pressAction.action.ReadValue<float>() : 0f;
// Read raw values from input devices (works for both keyboard and UI/mouse input)
float mouseValue = Mouse.current != null ? Mouse.current.leftButton.ReadValue() : 0f;
float pointerValue = Pointer.current != null ? Pointer.current.press.ReadValue() : 0f;
bool actionPressed = pressAction != null && pressAction.action.IsPressed();
bool isButtonCurrentlyPressed = mouseValue > 0.5f || pointerValue > 0.5f || actionPressed || rawInputValue > 0.5f;

notesInLane.Remove(note);

Check warning on line 186 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L186

Added line #L186 was not covered by tests

if (note.gameObject.activeInHierarchy && note.CanBePressed)
{
if (note.noteType == NoteObject.NoteType.Normal)
{

Check warning on line 191 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L188-L191

Added lines #L188 - L191 were not covered by tests
GameManager.instance.NoteMissed(note);
}
else if (note.noteType == NoteObject.NoteType.Hold)
{

Check warning on line 195 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L193-L195

Added lines #L193 - L195 were not covered by tests
if (note.IsHoldStarted())
{

Check warning on line 197 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L197

Added line #L197 was not covered by tests
if (isButtonCurrentlyPressed)
{
GameManager.instance.NoteHoldPerfect(note);
}
else
{
GameManager.instance.NoteHoldMissedEarly(note);
}
}

Check warning on line 206 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L206

Added line #L206 was not covered by tests
else
{

Check warning on line 208 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L208

Added line #L208 was not covered by tests
GameManager.instance.NoteMissed(note); // Never started holding
}
}
}
note.ResetNoteStateInternal();
}
}

Check warning on line 215 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L210-L215

Added lines #L210 - L215 were not covered by tests

public void NotifyNoteDeactivated(NoteObject note)
{
if (notesInLane.Contains(note))
{
notesInLane.Remove(note);
}
}

Check warning on line 223 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L218-L223

Added lines #L218 - L223 were not covered by tests
}
11 changes: 11 additions & 0 deletions Assets/Samples/InputRecorder/Game/ButtonController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading