Fix Vive controllers, add repeating game loop to breakout

This commit is contained in:
Toomas Tamm 2021-03-28 19:02:41 +03:00
parent 12343127d0
commit aeea9359af
29 changed files with 319 additions and 86 deletions

View File

@ -354,7 +354,7 @@ GameObject:
- component: {fileID: 6830999020486091146} - component: {fileID: 6830999020486091146}
- component: {fileID: 8579609115951157415} - component: {fileID: 8579609115951157415}
- component: {fileID: 8606222079484180125} - component: {fileID: 8606222079484180125}
m_Layer: 0 m_Layer: 31
m_Name: VR-door m_Name: VR-door
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}

View File

@ -14,7 +14,7 @@ GameObject:
- component: {fileID: 8722459144436683749} - component: {fileID: 8722459144436683749}
- component: {fileID: 8722459144436683745} - component: {fileID: 8722459144436683745}
- component: {fileID: 8722459144436683744} - component: {fileID: 8722459144436683744}
m_Layer: 0 m_Layer: 19
m_Name: Ball m_Name: Ball
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}

View File

@ -29,7 +29,7 @@ Transform:
m_GameObject: {fileID: 683641809410680648} m_GameObject: {fileID: 683641809410680648}
m_LocalRotation: {x: 0.5, y: 0.5, z: -0.5, w: 0.5} m_LocalRotation: {x: 0.5, y: 0.5, z: -0.5, w: 0.5}
m_LocalPosition: {x: 0.050354015, y: 2.664, z: -0.050353996} m_LocalPosition: {x: 0.050354015, y: 2.664, z: -0.050353996}
m_LocalScale: {x: 10, y: 0.4999999, z: 5} m_LocalScale: {x: 12, y: 0.5, z: 5}
m_Children: [] m_Children: []
m_Father: {fileID: 683641811316564866} m_Father: {fileID: 683641811316564866}
m_RootOrder: 0 m_RootOrder: 0
@ -133,7 +133,7 @@ Transform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 683641810726029905} m_GameObject: {fileID: 683641810726029905}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 176.99866, y: -15.076772, z: 23.519966} m_LocalPosition: {x: 176.99866, y: -15.076772, z: 23.519966}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
@ -171,7 +171,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 683641811316564867} m_GameObject: {fileID: 683641811316564867}
m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.7071068} m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.7071068}
m_LocalPosition: {x: -153.767, y: 19.684, z: -23.217} m_LocalPosition: {x: -153.767, y: 19.684, z: -23.389}
m_LocalScale: {x: 0.02, y: 0.15, z: 0.02} m_LocalScale: {x: 0.02, y: 0.15, z: 0.02}
m_Children: m_Children:
- {fileID: 683641809410680631} - {fileID: 683641809410680631}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: b10b65f998c66784c914dc3f22b0ca09
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -73196,7 +73196,7 @@ Transform:
- {fileID: 34859688} - {fileID: 34859688}
- {fileID: 861502100} - {fileID: 861502100}
m_Father: {fileID: 1772291665} m_Father: {fileID: 1772291665}
m_RootOrder: 4 m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &278670420 --- !u!1001 &278670420
PrefabInstance: PrefabInstance:
@ -138466,6 +138466,114 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 519196612} m_PrefabInstance: {fileID: 519196612}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1 &520108848
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 520108849}
- component: {fileID: 520108853}
- component: {fileID: 520108852}
- component: {fileID: 520108851}
- component: {fileID: 520108850}
m_Layer: 20
m_Name: Wall Back (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &520108849
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 520108848}
m_LocalRotation: {x: -0, y: 0.7071068, z: -0, w: 0.7071068}
m_LocalPosition: {x: 22.201, y: 4.547095, z: -0.23943138}
m_LocalScale: {x: 2, y: 2, z: 0.10000002}
m_Children: []
m_Father: {fileID: 615924707}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!114 &520108850
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 520108848}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9028d8e31a1966540aff16d72263c97d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!65 &520108851
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 520108848}
m_Material: {fileID: 13400000, guid: 2d5b273ec9081ca4684e185030431ebf, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &520108852
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 520108848}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 9e16357c77c1b754c9c1244356e3682f, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &520108853
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 520108848}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1001 &520669751 --- !u!1001 &520669751
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -165546,8 +165654,9 @@ Transform:
- {fileID: 985893360} - {fileID: 985893360}
- {fileID: 1090764316} - {fileID: 1090764316}
- {fileID: 747981557} - {fileID: 747981557}
- {fileID: 520108849}
m_Father: {fileID: 1772291665} m_Father: {fileID: 1772291665}
m_RootOrder: 3 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &617173121 --- !u!1 &617173121
GameObject: GameObject:
@ -222247,18 +222356,18 @@ MonoBehaviour:
m_AudioClipForOnHoverEntered: {fileID: 0} m_AudioClipForOnHoverEntered: {fileID: 0}
m_PlayAudioClipOnHoverExited: 0 m_PlayAudioClipOnHoverExited: 0
m_AudioClipForOnHoverExited: {fileID: 0} m_AudioClipForOnHoverExited: {fileID: 0}
m_PlayHapticsOnSelectEntered: 0 m_PlayHapticsOnSelectEntered: 1
m_HapticSelectEnterIntensity: 0 m_HapticSelectEnterIntensity: 0.5
m_HapticSelectEnterDuration: 0 m_HapticSelectEnterDuration: 0.2
m_PlayHapticsOnSelectExited: 0 m_PlayHapticsOnSelectExited: 1
m_HapticSelectExitIntensity: 0 m_HapticSelectExitIntensity: 0.5
m_HapticSelectExitDuration: 0 m_HapticSelectExitDuration: 0.2
m_PlayHapticsOnHoverEntered: 0 m_PlayHapticsOnHoverEntered: 1
m_HapticHoverEnterIntensity: 0 m_HapticHoverEnterIntensity: 0.1
m_HapticHoverEnterDuration: 0 m_HapticHoverEnterDuration: 0.1
m_PlayHapticsOnHoverExited: 0 m_PlayHapticsOnHoverExited: 1
m_HapticHoverExitIntensity: 0 m_HapticHoverExitIntensity: 0.1
m_HapticHoverExitDuration: 0 m_HapticHoverExitDuration: 0.1
--- !u!114 &835737638 --- !u!114 &835737638
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -238653,7 +238762,7 @@ PrefabInstance:
- target: {fileID: 683641810726029904, guid: b3aa1fd769428e5478861349062a763b, - target: {fileID: 683641810726029904, guid: b3aa1fd769428e5478861349062a763b,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 2 value: 3
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 683641810726029904, guid: b3aa1fd769428e5478861349062a763b, - target: {fileID: 683641810726029904, guid: b3aa1fd769428e5478861349062a763b,
type: 3} type: 3}
@ -238710,11 +238819,6 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: Paddle (1) value: Paddle (1)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 683641811316564866, guid: b3aa1fd769428e5478861349062a763b,
type: 3}
propertyPath: m_LocalPosition.z
value: -23.389
objectReference: {fileID: 0}
- target: {fileID: 683641811316564878, guid: b3aa1fd769428e5478861349062a763b, - target: {fileID: 683641811316564878, guid: b3aa1fd769428e5478861349062a763b,
type: 3} type: 3}
propertyPath: m_InteractionManager propertyPath: m_InteractionManager
@ -289728,6 +289832,7 @@ GameObject:
- component: {fileID: 1090764315} - component: {fileID: 1090764315}
- component: {fileID: 1090764314} - component: {fileID: 1090764314}
- component: {fileID: 1090764313} - component: {fileID: 1090764313}
- component: {fileID: 1090764317}
m_Layer: 7 m_Layer: 7
m_Name: Wall Back m_Name: Wall Back
m_TagString: Untagged m_TagString: Untagged
@ -289767,7 +289872,7 @@ MeshRenderer:
m_RenderingLayerMask: 1 m_RenderingLayerMask: 1
m_RendererPriority: 0 m_RendererPriority: 0
m_Materials: m_Materials:
- {fileID: 2100000, guid: f60634ab3acc0b04fa94e2089ebe467c, type: 2} - {fileID: 2100000, guid: 9e16357c77c1b754c9c1244356e3682f, type: 2}
m_StaticBatchInfo: m_StaticBatchInfo:
firstSubMesh: 0 firstSubMesh: 0
subMeshCount: 0 subMeshCount: 0
@ -289811,6 +289916,18 @@ Transform:
m_Father: {fileID: 615924707} m_Father: {fileID: 615924707}
m_RootOrder: 4 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!114 &1090764317
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1090764312}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9acb76ffa96cc784e9f873c1c22c695c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1091142290 --- !u!1001 &1091142290
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -315530,6 +315647,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 89.99999 value: 89.99999
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 7641886289678632063, guid: c7190c7182dc47944b0a50b8b43c2a0a,
type: 3}
propertyPath: m_Layer
value: 31
objectReference: {fileID: 0}
- target: {fileID: 8606222079484180125, guid: c7190c7182dc47944b0a50b8b43c2a0a, - target: {fileID: 8606222079484180125, guid: c7190c7182dc47944b0a50b8b43c2a0a,
type: 3} type: 3}
propertyPath: m_ConnectedAnchor.x propertyPath: m_ConnectedAnchor.x
@ -392206,18 +392328,18 @@ MonoBehaviour:
m_AudioClipForOnHoverEntered: {fileID: 0} m_AudioClipForOnHoverEntered: {fileID: 0}
m_PlayAudioClipOnHoverExited: 0 m_PlayAudioClipOnHoverExited: 0
m_AudioClipForOnHoverExited: {fileID: 0} m_AudioClipForOnHoverExited: {fileID: 0}
m_PlayHapticsOnSelectEntered: 0 m_PlayHapticsOnSelectEntered: 1
m_HapticSelectEnterIntensity: 0 m_HapticSelectEnterIntensity: 0.5
m_HapticSelectEnterDuration: 0 m_HapticSelectEnterDuration: 0.2
m_PlayHapticsOnSelectExited: 0 m_PlayHapticsOnSelectExited: 1
m_HapticSelectExitIntensity: 0 m_HapticSelectExitIntensity: 0.5
m_HapticSelectExitDuration: 0 m_HapticSelectExitDuration: 0.2
m_PlayHapticsOnHoverEntered: 0 m_PlayHapticsOnHoverEntered: 1
m_HapticHoverEnterIntensity: 0 m_HapticHoverEnterIntensity: 0.1
m_HapticHoverEnterDuration: 0 m_HapticHoverEnterDuration: 0.1
m_PlayHapticsOnHoverExited: 0 m_PlayHapticsOnHoverExited: 1
m_HapticHoverExitIntensity: 0 m_HapticHoverExitIntensity: 0.1
m_HapticHoverExitDuration: 0 m_HapticHoverExitDuration: 0.1
--- !u!114 &1463275262 --- !u!114 &1463275262
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -473342,6 +473464,7 @@ Transform:
m_LocalPosition: {x: -49.554653, y: 0.94090503, z: -19.973568} m_LocalPosition: {x: -49.554653, y: 0.94090503, z: -19.973568}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 1237042454827495307}
- {fileID: 1027123931} - {fileID: 1027123931}
- {fileID: 968308519} - {fileID: 968308519}
- {fileID: 897260790} - {fileID: 897260790}
@ -473366,6 +473489,9 @@ MonoBehaviour:
type: 3} type: 3}
extraBallBreakablePrefab: {fileID: 4446013279578327973, guid: 5353b5457960d5644a286e6f8f1bed7a, extraBallBreakablePrefab: {fileID: 4446013279578327973, guid: 5353b5457960d5644a286e6f8f1bed7a,
type: 3} type: 3}
startBallSpawnPoint: {fileID: 1237042454827495303}
ballPrefab: {fileID: 8722459144436683754, guid: c4c82be1460eebd429189ea1df531212,
type: 3}
spawnPoints: spawnPoints:
- {fileID: 1634963956} - {fileID: 1634963956}
- {fileID: 1266635511} - {fileID: 1266635511}
@ -575504,7 +575630,7 @@ PrefabInstance:
- target: {fileID: 683641810726029904, guid: b3aa1fd769428e5478861349062a763b, - target: {fileID: 683641810726029904, guid: b3aa1fd769428e5478861349062a763b,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 1 value: 2
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 683641810726029904, guid: b3aa1fd769428e5478861349062a763b, - target: {fileID: 683641810726029904, guid: b3aa1fd769428e5478861349062a763b,
type: 3} type: 3}
@ -575800,6 +575926,36 @@ MeshRenderer:
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0} m_AdditionalVertexStreams: {fileID: 0}
--- !u!1 &1237042454827495303
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1237042454827495307}
m_Layer: 19
m_Name: StartBallSpawnPoint
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1237042454827495307
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1237042454827495303}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 22.764, y: 4.44, z: -0.345}
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
m_Children: []
m_Father: {fileID: 1772291665}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1286284988653536608 --- !u!1001 &1286284988653536608
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -607443,12 +607599,12 @@ PrefabInstance:
- target: {fileID: 8722459144436683750, guid: c4c82be1460eebd429189ea1df531212, - target: {fileID: 8722459144436683750, guid: c4c82be1460eebd429189ea1df531212,
type: 3} type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 0 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8722459144436683750, guid: c4c82be1460eebd429189ea1df531212, - target: {fileID: 8722459144436683750, guid: c4c82be1460eebd429189ea1df531212,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: 21.92 value: 22.764
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8722459144436683750, guid: c4c82be1460eebd429189ea1df531212, - target: {fileID: 8722459144436683750, guid: c4c82be1460eebd429189ea1df531212,
type: 3} type: 3}

View File

@ -19,14 +19,19 @@ namespace Breakout
private void Awake() private void Awake()
{ {
Events.OnBreakoutEndGame += DestroyCube; Events.OnBreakoutEndGame += EventDestroyCube;
Events.OnBreakoutSetSpeed += SetSpeed; Events.OnBreakoutSetSpeed += SetSpeed;
_hasSpawnedBall = false; _hasSpawnedBall = false;
} }
private void EventDestroyCube()
{
DestroyCube(false);
}
private void OnDestroy() private void OnDestroy()
{ {
Events.OnBreakoutEndGame -= DestroyCube; Events.OnBreakoutEndGame -= EventDestroyCube;
Events.OnBreakoutSetSpeed -= SetSpeed; Events.OnBreakoutSetSpeed -= SetSpeed;
} }
@ -40,13 +45,13 @@ namespace Breakout
BreakoutBall ball = other.gameObject.GetComponent<BreakoutBall>(); BreakoutBall ball = other.gameObject.GetComponent<BreakoutBall>();
if (ball == null) return; if (ball == null) return;
DestroyCube(); DestroyCube(true);
} }
public virtual void DestroyCube() private void DestroyCube(bool allowBallSpawn)
{ {
if (spawnBall & !_hasSpawnedBall) if (spawnBall & !_hasSpawnedBall & allowBallSpawn)
{ {
_hasSpawnedBall = true; _hasSpawnedBall = true;
var ball = Instantiate(ballPrefab, transform.position, Quaternion.identity, null); var ball = Instantiate(ballPrefab, transform.position, Quaternion.identity, null);
@ -57,6 +62,8 @@ namespace Breakout
Random.Range(-2.0f, 2.0f), Random.Range(-2.0f, 2.0f),
Random.Range(-2.0f, 2.0f) Random.Range(-2.0f, 2.0f)
)); ));
Events.AddBalls();
} }
speed.x = 0; speed.x = 0;

View File

@ -36,5 +36,14 @@ namespace Breakout
{ {
Destroy(gameObject); Destroy(gameObject);
} }
private void OnCollisionEnter(Collision other)
{
KinematicSpeedTransfer kst = other.gameObject.GetComponent<KinematicSpeedTransfer>();
if (kst == null) return;
Events.BreakoutStartGame();
}
} }
} }

View File

@ -8,49 +8,55 @@ using Random = UnityEngine.Random;
public class BreakoutManager : MonoBehaviour public class BreakoutManager : MonoBehaviour
{ {
private static BreakoutManager _instance;
public static BreakoutManager Instance { get { return _instance; } }
public GameObject defaultBreakablePrefab; public GameObject defaultBreakablePrefab;
public GameObject extraBallBreakablePrefab; public GameObject extraBallBreakablePrefab;
public GameObject startBallSpawnPoint;
public GameObject ballPrefab;
public List<Transform> spawnPoints; public List<Transform> spawnPoints;
public float timeBetweenRows = 5f; public float timeBetweenRows = 5f;
public float startRowSpeed = 0.15f; public float startRowSpeed = 0.15f;
private float speedIncreasePerRow = 0.01f; //private float _speedIncreasePerRow = 0.01f;
public float extraBallBreakableChance = 0.1f; public float extraBallBreakableChance = 0.1f;
private float nextRowTime; private float _nextRowTime;
private float currentRowSpeed; private float _currentRowSpeed;
private bool gameStarted; private int _ballCount;
private bool _gameStarted;
private void Awake() private void Awake()
{ {
if (_instance != null && _instance != this) _gameStarted = false;
{ _ballCount = 1;
Destroy(gameObject); _nextRowTime = Time.time;
} else { _currentRowSpeed = startRowSpeed;
_instance = this;
}
gameStarted = true;
Events.OnBreakoutEndGame += EndGame; Events.OnBreakoutEndGame += EndGame;
nextRowTime = Time.time; Events.OnBreakoutStartGame += StartGame;
currentRowSpeed = startRowSpeed;
Events.OnBreakoutReduceBalls += ReduceBalls;
Events.OnBreakoutAddBalls += AddBalls;
} }
void OnDestroy() void OnDestroy()
{ {
Events.OnBreakoutEndGame -= EndGame; Events.OnBreakoutEndGame -= EndGame;
Events.OnBreakoutStartGame -= StartGame;
Events.OnBreakoutReduceBalls -= ReduceBalls;
Events.OnBreakoutAddBalls -= AddBalls;
} }
void Update() void Update()
{ {
if (!gameStarted) return; if (!_gameStarted) return;
if (nextRowTime < Time.time) if (_nextRowTime < Time.time)
{ {
SpawnRow(); SpawnRow();
} }
@ -58,18 +64,29 @@ public class BreakoutManager : MonoBehaviour
void StartGame() void StartGame()
{ {
gameStarted = true; if (_gameStarted) return;
SpawnRow(); _gameStarted = true;
_nextRowTime = Time.time;
}
private void SpawnBall()
{
Instantiate(ballPrefab, startBallSpawnPoint.transform.position, Quaternion.identity, null);
_ballCount += 1;
} }
void EndGame() void EndGame()
{ {
gameStarted = false; if (!_gameStarted) return;
_gameStarted = false;
SpawnBall();
_ballCount = 1;
} }
void SpawnRow() void SpawnRow()
{ {
nextRowTime = Time.time + timeBetweenRows; _nextRowTime = Time.time + timeBetweenRows;
//currentRowSpeed += speedIncreasePerRow; //currentRowSpeed += speedIncreasePerRow;
foreach (var point in spawnPoints) foreach (var point in spawnPoints)
@ -87,9 +104,25 @@ public class BreakoutManager : MonoBehaviour
var cube = box.GetComponent<BreakableCube>(); var cube = box.GetComponent<BreakableCube>();
cube.speed.x = currentRowSpeed; cube.speed.x = _currentRowSpeed;
} }
Events.BreakoutSetSpeed(currentRowSpeed); Events.BreakoutSetSpeed(_currentRowSpeed);
}
void ReduceBalls()
{
_ballCount -= 1;
if (_ballCount <= 0)
{
Events.BreakoutEndGame();
}
}
void AddBalls()
{
_ballCount += 1;
} }
} }

View File

@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using Breakout;
using UnityEngine;
public class DestroyBallForcefield : MonoBehaviour
{
private void OnCollisionEnter(Collision other)
{
BreakoutBall ball = other.gameObject.GetComponent<BreakoutBall>();
if (ball == null) return;
Events.ReduceBalls();
Destroy(ball.gameObject);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9acb76ffa96cc784e9f873c1c22c695c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,8 +4,17 @@ public static class Events
{ {
public static event Action OnBreakoutEndGame; public static event Action OnBreakoutEndGame;
public static void BreakoutEndGame() => OnBreakoutEndGame?.Invoke(); public static void BreakoutEndGame() => OnBreakoutEndGame?.Invoke();
public static event Action OnBreakoutStartGame;
public static void BreakoutStartGame() => OnBreakoutStartGame?.Invoke();
public static event Action<float> OnBreakoutSetSpeed; public static event Action<float> OnBreakoutSetSpeed;
public static void BreakoutSetSpeed(float speed) => OnBreakoutSetSpeed?.Invoke(speed); public static void BreakoutSetSpeed(float speed) => OnBreakoutSetSpeed?.Invoke(speed);
public static event Action OnBreakoutReduceBalls;
public static void ReduceBalls() => OnBreakoutReduceBalls?.Invoke();
public static event Action OnBreakoutAddBalls;
public static void AddBalls() => OnBreakoutAddBalls?.Invoke();
} }

View File

@ -424,7 +424,7 @@
{ {
"name": "", "name": "",
"id": "20496338-aab2-43d6-bbe3-4ebe5b229c1f", "id": "20496338-aab2-43d6-bbe3-4ebe5b229c1f",
"path": "<XRController>{RightHand}/triggerPressed", "path": "<XRController>{LeftHand}/triggerPressed",
"interactions": "", "interactions": "",
"processors": "", "processors": "",
"groups": "Generic XR Controller", "groups": "Generic XR Controller",

View File

@ -18,7 +18,7 @@ PhysicsManager:
m_ClothInterCollisionDistance: 0 m_ClothInterCollisionDistance: 0
m_ClothInterCollisionStiffness: 0 m_ClothInterCollisionStiffness: 0
m_ContactsGeneration: 1 m_ContactsGeneration: 1
m_LayerCollisionMatrix: ffffff7fffffff7fffffffffffffffffffffff7fffffff7fffffff7f7fffff7fffffff7fffffff7fffffff7fffffff7fffffff7fffffffffffffff7fffffffffffffff7fffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0ca0faff m_LayerCollisionMatrix: ffffff7fffffff7fffffffffffffffffffffff7fffffff7fffffff7f7fffff7fffffff7fffffff7fffffff7fffffff7fffffff7fffffffffffffff7fffffffffffffff7fffffffffffffff7fffffeffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0ca0faff
m_AutoSimulation: 1 m_AutoSimulation: 1
m_AutoSyncTransforms: 0 m_AutoSyncTransforms: 0
m_ReuseCollisionCallbacks: 1 m_ReuseCollisionCallbacks: 1

View File

@ -24,8 +24,8 @@ TagManager:
- EditorOnly - EditorOnly
- -
- Lights - Lights
- - Ball
- - Ignore Ball
- -
- -
- -