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>();

public float WorldXPosition => transform.position.x;

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

Collider buttonCollider = GetComponent<Collider>();
if (buttonCollider != null)
{
buttonCollider.isTrigger = true;
if (GetComponent<Rigidbody>() == null)
{
Rigidbody rb = gameObject.AddComponent<Rigidbody>();
rb.isKinematic = true;
}
}
else
{
Debug.LogError("ButtonController needs a Collider component set to Is Trigger and a Rigidbody!", this);
}

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

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

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

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

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

public void UIButton_Press()
{
ProcessButtonPress();
}

public void UIButton_Release()
{
ProcessButtonRelease();
}

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

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

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

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;
}
}
}
}

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

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

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();
}
}
}

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

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

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'
// note.gameObject.SetActive(false); Removed: NoteObject will handle deactivation
}
else if (!note.IsHoldStarted())
{
GameManager.instance.NoteMissed(note); // Pass 'note'
}
}
}
note.ResetNoteStateInternal();
}
}

public void NotifyNoteDeactivated(NoteObject note)
{
if (notesInLane.Contains(note))
{
notesInLane.Remove(note);
}
}
}
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