add sound while hovering over logo

This commit is contained in:
minenice55 2023-08-16 01:07:38 -04:00
parent cdade51109
commit 1ab426ba34
5 changed files with 60 additions and 5 deletions

View file

@ -1020,6 +1020,7 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 1612412234317559814} - component: {fileID: 1612412234317559814}
- component: {fileID: 1934842100097612374} - component: {fileID: 1934842100097612374}
- component: {fileID: 6291913669464459655}
m_Layer: 0 m_Layer: 0
m_Name: Logo m_Name: Logo
m_TagString: Untagged m_TagString: Untagged
@ -1054,6 +1055,32 @@ SortingGroup:
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 1 m_SortingOrder: 1
--- !u!61 &6291913669464459655
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3100003515355048895}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -3.32, y: 1.19}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 13.75, y: 10}
m_EdgeRadius: 0
--- !u!1 &3289918358035214086 --- !u!1 &3289918358035214086
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -1955,6 +1955,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 27.1 value: 27.1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6291913669464459655, guid: 0254202fd7d5ca84c8cf0950a645230b, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6344996612592602760, guid: 0254202fd7d5ca84c8cf0950a645230b, type: 3} - target: {fileID: 6344996612592602760, guid: 0254202fd7d5ca84c8cf0950a645230b, type: 3}
propertyPath: m_AnchoredPosition.x propertyPath: m_AnchoredPosition.x
value: -28.5 value: -28.5
@ -2709,6 +2713,11 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1178120458} m_GameObject: {fileID: 1178120458}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!61 &1269393217 stripped
BoxCollider2D:
m_CorrespondingSourceObject: {fileID: 6291913669464459655, guid: 0254202fd7d5ca84c8cf0950a645230b, type: 3}
m_PrefabInstance: {fileID: 869323822}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1336149017 --- !u!1 &1336149017
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3829,9 +3838,11 @@ MonoBehaviour:
- {fileID: 1400026815} - {fileID: 1400026815}
pressAnyKeyAnim: {fileID: 976586349} pressAnyKeyAnim: {fileID: 976586349}
bpm: 114 bpm: 114
offset: 0.082
bg: {fileID: 1178120460} bg: {fileID: 1178120460}
bgXSpeed: -0.08 bgXSpeed: -0.08
bgYSpeed: 0.08 bgYSpeed: 0.08
logoHoverCollider: {fileID: 1269393217}
--- !u!82 &1811344143 --- !u!82 &1811344143
AudioSource: AudioSource:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -19,12 +19,15 @@ namespace HeavenStudio
[SerializeField] private Animator pressAnyKeyAnim; [SerializeField] private Animator pressAnyKeyAnim;
[SerializeField] private float bpm = 114f; [SerializeField] private float bpm = 114f;
[SerializeField] private float offset = 0f;
[SerializeField] private RawImage bg; [SerializeField] private RawImage bg;
[SerializeField] private float bgXSpeed; [SerializeField] private float bgXSpeed;
[SerializeField] private float bgYSpeed; [SerializeField] private float bgYSpeed;
[SerializeField] private Collider2D logoHoverCollider;
private AudioSource musicSource; private AudioSource musicSource;
private double songPosBeat; private double songPosBeat;
@ -68,7 +71,7 @@ namespace HeavenStudio
time += dt; time += dt;
songPos = time; songPos = time + offset;
songPosBeat = SecsToBeats(songPos); songPosBeat = SecsToBeats(songPos);
if (logoRevealed && !menuMode && Input.anyKeyDown) if (logoRevealed && !menuMode && Input.anyKeyDown)
@ -118,6 +121,10 @@ namespace HeavenStudio
altBop = !altBop; altBop = !altBop;
} }
targetBopBeat += 1; targetBopBeat += 1;
if (logoRevealed && logoHoverCollider.OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition)))
{
SoundByte.PlayOneShotScheduled("count-ins/cowbell", AudioSettings.dspTime + BeatsToSecs(targetBopBeat - songPosBeat, bpm));
}
} }
} }
@ -126,6 +133,11 @@ namespace HeavenStudio
return s / 60f * bpm; return s / 60f * bpm;
} }
public double BeatsToSecs(double beats, float bpm)
{
return beats / bpm * 60f;
}
public float GetPositionFromBeat(float startBeat, float length) public float GetPositionFromBeat(float startBeat, float length)
{ {
float a = Mathp.Normalize((float)songPosBeat, startBeat, startBeat + length); float a = Mathp.Normalize((float)songPosBeat, startBeat, startBeat + length);

View file

@ -56,8 +56,11 @@ namespace HeavenStudio.Util
else else
{ {
playInstant = false; playInstant = false;
scheduledPitch = cnd.SongPitch; if (cnd != null)
startTime = (AudioSettings.dspTime + (cnd.GetSongPosFromBeat(beat) - cnd.songPositionAsDouble)/(double)scheduledPitch) - offset; {
scheduledPitch = cnd?.SongPitch ?? 1f;
startTime = (AudioSettings.dspTime + (cnd.GetSongPosFromBeat(beat) - cnd.songPositionAsDouble)/(double)scheduledPitch) - offset;
}
if (scheduledPitch != 0 && AudioSettings.dspTime >= startTime) if (scheduledPitch != 0 && AudioSettings.dspTime >= startTime)
{ {
@ -173,7 +176,8 @@ namespace HeavenStudio.Util
public void Delete() public void Delete()
{ {
GameManager.instance.SoundObjects.Remove(gameObject); if (GameManager.instance != null)
GameManager.instance.SoundObjects.Remove(gameObject);
Destroy(gameObject); Destroy(gameObject);
} }

View file

@ -236,7 +236,8 @@ namespace HeavenStudio.Util
snd.scheduled = true; snd.scheduled = true;
snd.scheduledTime = targetTime; snd.scheduledTime = targetTime;
GameManager.instance.SoundObjects.Add(oneShot); if (GameManager.instance != null)
GameManager.instance.SoundObjects.Add(oneShot);
return snd; return snd;
} }