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.

190 changes: 190 additions & 0 deletions Assets/Samples/InputRecorder/Game/ButtonController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
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

public float WorldXPosition => transform.position.x;

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

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

Added line #L19 was not covered by tests

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

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#L22-L23

Added lines #L22 - L23 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 34 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L25-L34

Added lines #L25 - L34 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 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#L36-L38

Added lines #L36 - L38 were not covered by tests

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

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

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

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L45-L52

Added lines #L45 - L52 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 62 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L55-L62

Added lines #L55 - L62 were not covered by tests

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

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L65-L67

Added lines #L65 - L67 were not covered by tests

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

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L70-L72

Added lines #L70 - L72 were not covered by tests

public void UIButton_Press()
{
ProcessButtonPress();
}

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L75-L77

Added lines #L75 - L77 were not covered by tests

public void UIButton_Release()
{
ProcessButtonRelease();
}

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L80-L82

Added lines #L80 - L82 were not covered by tests

private void ProcessButtonPress()
{
if (pressedTexture != null)
meshR.material.mainTexture = pressedTexture;

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L85-L87

Added lines #L85 - L87 were not covered by tests

NoteObject bestNoteToHit = null;
float smallestDistance = float.MaxValue;

Check warning on line 90 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-L90

Added lines #L89 - L90 were not covered by tests

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

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#L92-L94

Added lines #L92 - L94 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);
if (distance < smallestDistance)
{
smallestDistance = distance;
bestNoteToHit = note;
}
}
else if (note.noteType == NoteObject.NoteType.Hold && !note.IsHoldStarted())
{
float distance = Mathf.Abs(note.transform.position.x - WorldXPosition);
if (distance <= 0.25f)
{
bestNoteToHit = note;
break;

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L96-L113

Added lines #L96 - L113 were not covered by tests
}
}
}
}

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L115-L117

Added lines #L115 - L117 were not covered by tests

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

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L119-L123

Added lines #L119 - L123 were not covered by tests

private void ProcessButtonRelease()
{
if (defaultTexture != null)
meshR.material.mainTexture = defaultTexture;

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

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

Added lines #L126 - L128 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 138 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-L138

Added lines #L130 - L138 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 151 in Assets/Samples/InputRecorder/Game/ButtonController.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L141-L151

Added lines #L141 - L151 were not covered by tests

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

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#L154-L158

Added lines #L154 - L158 were not covered by tests

if (note.gameObject.activeInHierarchy && note.CanBePressed)
{
if (note.noteType == NoteObject.NoteType.Normal)
{
GameManager.instance.NoteMissed(note); // Pass 'note'
}
else if (note.noteType == NoteObject.NoteType.Hold)
{
if (note.IsHoldStarted() && note.IsHolding())
{
GameManager.instance.NoteHoldPerfect(note); // Pass 'note'

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L160-L170

Added lines #L160 - L170 were not covered by tests
// note.gameObject.SetActive(false); Removed: NoteObject will handle deactivation
}
else if (!note.IsHoldStarted())
{
GameManager.instance.NoteMissed(note); // Pass 'note'
}
}
}
note.ResetNoteStateInternal();
}
}

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L172-L181

Added lines #L172 - L181 were not covered by tests

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

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

View check run for this annotation

Codecov GitHub.com / codecov/patch

Assets/Samples/InputRecorder/Game/ButtonController.cs#L184-L189

Added lines #L184 - L189 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