Compare commits

..

49 Commits

Author SHA1 Message Date
3be8d2f6a6 Fixed PacMan speed 2026-06-23 18:18:17 +02:00
875d0ad5f0 Fixed pellet sync 2026-06-23 14:45:30 +02:00
378d6bc7a7 Refactored input 2026-06-23 13:00:48 +02:00
540cfe16ab Amend 2026-06-22 18:50:26 +02:00
b688b4739b More better sync 2026-06-22 18:44:53 +02:00
1252933ca4 Improving sync 2026-06-22 18:31:16 +02:00
d6b870de79 SoundManager sync 2026-06-22 16:03:46 +02:00
8a6f1b482b Cleanup 2026-06-22 15:51:59 +02:00
18499ab576 More sync 2026-06-22 15:51:55 +02:00
a32df1bd09 Simplified GhostManager restart more 2026-06-22 15:34:02 +02:00
d739c9d7b5 Refactored pelletCollectedCount 2026-06-22 15:21:48 +02:00
4ba203b1de Refactored starting new level 2026-06-22 15:20:43 +02:00
7f87a9779b Expanded sync 2026-06-22 15:02:22 +02:00
99556b81b1 Simplified PacMan state 2026-06-22 15:01:57 +02:00
ca116ac77f Removed clutter from log 2026-06-22 13:35:32 +02:00
e431dab042 Fixed ghost caught queue 2026-06-22 13:11:00 +02:00
cb975c24b2 Fixed desync issue for PacMan moves 2026-06-20 14:12:18 +02:00
a4733b33b8 Applied prefab 2026-06-20 12:09:36 +02:00
95bbbcc5e2 Amend 2026-06-19 21:02:51 +02:00
74e6493108 Bunch of cleaning 2026-06-19 21:01:01 +02:00
b3d6ebaf67 Updated wait for start logic 2026-06-19 15:03:15 +02:00
420bef5862 Flipped up and down in code 2026-06-19 13:35:09 +02:00
8d23d1812f Simplified ghost starting direction logic 2026-06-19 13:01:19 +02:00
0a815c7a50 Update 2026-06-19 12:55:05 +02:00
a5d3546cf0 Comment 2026-06-19 12:54:43 +02:00
77ba7ec9c6 Fixed ghost blink 2026-06-19 12:53:58 +02:00
46e1207c37 Fixed death animation 2026-06-19 12:48:04 +02:00
1a6d7875f6 Animation refactor mostly done 2026-06-18 21:58:42 +02:00
f44929c109 Cleaning 2026-06-18 11:59:21 +02:00
e4ffe97c03 Ghost look ahead 2026-06-18 11:41:23 +02:00
64e445e8a6 Renamed CollisionManager 2026-06-18 11:03:56 +02:00
a7d1adf175 Ghost - PacMan collision detection 2026-06-17 14:12:36 +02:00
e3b626f3d6 Fixed wrapping 2026-06-17 13:09:34 +02:00
97a3d90f14 Fixes 2026-06-17 12:29:46 +02:00
8684f1ecc7 Maze 32x32 2026-06-17 12:12:17 +02:00
a24f237bd5 Bonus fruit hitbox 2026-06-15 17:21:16 +02:00
c601dda10a Pellet collision 2026-06-15 14:36:07 +02:00
246718f1bd More cleanup 2026-06-15 13:04:52 +02:00
8610c6be53 Ghost turn points baked 2026-06-15 13:01:10 +02:00
77681fe0ca More Direction 2026-06-15 11:20:17 +02:00
f1281280fa More use of Direction 2026-06-15 10:58:16 +02:00
73b3194c51 Switched to Direction enum 2026-06-15 10:29:36 +02:00
2ccf77c0eb Tools for testing 2026-06-11 19:24:09 +02:00
878486c92f Small changes 2026-06-11 13:38:01 +02:00
bce6b329c2 Improved network accuracy 2026-06-11 12:25:12 +02:00
f0859d92ac Implemented event subscribers 2026-06-11 12:05:38 +02:00
e75452b145 Fixes 2026-06-11 12:05:12 +02:00
e7968a5753 NetworkManagerTester working 2026-06-10 20:09:41 +02:00
cf39fd5dd9 A lot of older work 2026-06-09 17:45:51 +02:00
78 changed files with 74793 additions and 64474 deletions

View File

@@ -8,25 +8,9 @@ BlendTree:
m_PrefabAsset: {fileID: 0}
m_Name: Caught
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: b7fa9ace8554cea4f9fb60fd49d46003, type: 2}
m_Threshold: 0
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: e78691864c89f71408d1c60387bfbb68, type: 2}
m_Threshold: 0.33333334
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 36b0773acb645d54386957b2ee95b9ae, type: 2}
m_Threshold: 0.6666667
m_Threshold: 1
m_Position: {x: 0, y: 1}
m_TimeScale: 1
m_CycleOffset: 0
@@ -34,19 +18,35 @@ BlendTree:
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: f0e74ae0e0fa68941a3801f395aae18e, type: 2}
m_Threshold: 1
m_Threshold: 2
m_Position: {x: 0, y: -1}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
m_BlendParameter: DirX
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: e78691864c89f71408d1c60387bfbb68, type: 2}
m_Threshold: 4
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: b7fa9ace8554cea4f9fb60fd49d46003, type: 2}
m_Threshold: 8
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
m_BlendParameter: Direction
m_BlendParameterY: DirY
m_MinThreshold: 0
m_MaxThreshold: 1
m_UseAutomaticThresholds: 1
m_MinThreshold: 1
m_MaxThreshold: 8
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 1
m_BlendType: 0
--- !u!206 &-8944447067464121002
BlendTree:
m_ObjectHideFlags: 1
@@ -56,24 +56,16 @@ BlendTree:
m_Name: Special
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 7285e9dfd47eeb64f8a359c3d14be984, type: 2}
m_Motion: {fileID: 7400000, guid: 2e01a9fa01711c949a6922e3ebaece0f, type: 2}
m_Threshold: 0
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: DirX
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: aaf4617f2ca36da40883d1c0fa350dbc, type: 2}
m_Threshold: 0.25
m_Position: {x: -1, y: 0}
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: DirX
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 85bb4d19537fb1d429f9b123bc9d9c00, type: 2}
m_Threshold: 0.5
m_Threshold: 1
m_Position: {x: 0, y: 1}
m_TimeScale: 1
m_CycleOffset: 0
@@ -81,27 +73,35 @@ BlendTree:
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 454d1764e1b7a1946808d4221d71c6c5, type: 2}
m_Threshold: 0.75
m_Threshold: 2
m_Position: {x: 0, y: -1}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: DirX
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 2e01a9fa01711c949a6922e3ebaece0f, type: 2}
m_Threshold: 1
m_Position: {x: 0, y: 0}
m_Motion: {fileID: 7400000, guid: aaf4617f2ca36da40883d1c0fa350dbc, type: 2}
m_Threshold: 4
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: DirX
m_Mirror: 0
m_BlendParameter: DirX
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 7285e9dfd47eeb64f8a359c3d14be984, type: 2}
m_Threshold: 8
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: DirX
m_Mirror: 0
m_BlendParameter: Direction
m_BlendParameterY: DirY
m_MinThreshold: 0
m_MaxThreshold: 1
m_UseAutomaticThresholds: 1
m_MaxThreshold: 8
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 1
m_BlendType: 0
--- !u!206 &-6725170829935541210
BlendTree:
m_ObjectHideFlags: 1
@@ -110,25 +110,9 @@ BlendTree:
m_PrefabAsset: {fileID: 0}
m_Name: Inky
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 802f1a2ffb945bd4ba7c70c31c7399e1, type: 2}
m_Threshold: 0
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: ce5667efe0f28ad4ba4ac1430a737dab, type: 2}
m_Threshold: 0.33333334
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 9894cddcecedab845ae42c087acf40a8, type: 2}
m_Threshold: 0.6666667
m_Threshold: 1
m_Position: {x: 0, y: 1}
m_TimeScale: 1
m_CycleOffset: 0
@@ -136,19 +120,35 @@ BlendTree:
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 3df116c3435334949a1acad965ecba8b, type: 2}
m_Threshold: 1
m_Threshold: 2
m_Position: {x: 0, y: -1}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
m_BlendParameter: DirX
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: ce5667efe0f28ad4ba4ac1430a737dab, type: 2}
m_Threshold: 4
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 802f1a2ffb945bd4ba7c70c31c7399e1, type: 2}
m_Threshold: 8
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
m_BlendParameter: Direction
m_BlendParameterY: DirY
m_MinThreshold: 0
m_MaxThreshold: 1
m_UseAutomaticThresholds: 1
m_MinThreshold: 1
m_MaxThreshold: 8
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 1
m_BlendType: 0
--- !u!1102 &-5396122242781941074
AnimatorState:
serializedVersion: 6
@@ -183,25 +183,9 @@ BlendTree:
m_PrefabAsset: {fileID: 0}
m_Name: Blinky
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 456e9eb70ceaf434186cbc77f60bcd68, type: 2}
m_Threshold: 0
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostState
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: de276d8cc3b87d540aaa3406ce645c2f, type: 2}
m_Threshold: 0.33333334
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostState
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 33a8bfdc4f32c8c48a25e7ced8ea7816, type: 2}
m_Threshold: 0.6666667
m_Threshold: 1
m_Position: {x: 0, y: 1}
m_TimeScale: 1
m_CycleOffset: 0
@@ -209,19 +193,35 @@ BlendTree:
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: d3a6c5069daf7f842919751122a63959, type: 2}
m_Threshold: 1
m_Threshold: 2
m_Position: {x: 0, y: -1}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostState
m_Mirror: 0
m_BlendParameter: DirX
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: de276d8cc3b87d540aaa3406ce645c2f, type: 2}
m_Threshold: 4
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostState
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 456e9eb70ceaf434186cbc77f60bcd68, type: 2}
m_Threshold: 8
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostState
m_Mirror: 0
m_BlendParameter: Direction
m_BlendParameterY: DirY
m_MinThreshold: 0
m_MaxThreshold: 1
m_UseAutomaticThresholds: 1
m_MinThreshold: 1
m_MaxThreshold: 8
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 1
m_BlendType: 0
--- !u!206 &-994243735496022530
BlendTree:
m_ObjectHideFlags: 1
@@ -230,25 +230,9 @@ BlendTree:
m_PrefabAsset: {fileID: 0}
m_Name: Clyde
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: c3139552050fc45418fb2068d756cf5b, type: 2}
m_Threshold: 0
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 2e17027ea2c6d3643aaf6a75315d1171, type: 2}
m_Threshold: 0.33333334
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: e9f01727f466f0f4983d7e48a06427a7, type: 2}
m_Threshold: 0.6666667
m_Threshold: 1
m_Position: {x: 0, y: 1}
m_TimeScale: 1
m_CycleOffset: 0
@@ -256,19 +240,35 @@ BlendTree:
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 6d653efb9a144174babda398c7b00b8c, type: 2}
m_Threshold: 1
m_Threshold: 2
m_Position: {x: 0, y: -1}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
m_BlendParameter: DirX
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 2e17027ea2c6d3643aaf6a75315d1171, type: 2}
m_Threshold: 4
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: c3139552050fc45418fb2068d756cf5b, type: 2}
m_Threshold: 8
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
m_BlendParameter: Direction
m_BlendParameterY: DirY
m_MinThreshold: 0
m_MaxThreshold: 1
m_UseAutomaticThresholds: 1
m_MinThreshold: 1
m_MaxThreshold: 8
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 1
m_BlendType: 0
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
@@ -278,24 +278,18 @@ AnimatorController:
m_Name: Ghost
serializedVersion: 5
m_AnimatorParameters:
- m_Name: DirX
- m_Name: Direction
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: DirY
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: GhostType
m_Type: 1
m_DefaultFloat: 1
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
@@ -317,25 +311,9 @@ BlendTree:
m_PrefabAsset: {fileID: 0}
m_Name: Pinky
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: c4d80fdae68078f4f999ae9bd0dbad98, type: 2}
m_Threshold: 0
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: ba690f8352f83d44db9fe20b91f9bdb8, type: 2}
m_Threshold: 0.33333334
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: ab238cd16cad7744fbb93c2da0424514, type: 2}
m_Threshold: 0.6666667
m_Threshold: 1
m_Position: {x: 0, y: 1}
m_TimeScale: 1
m_CycleOffset: 0
@@ -343,19 +321,35 @@ BlendTree:
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 0e98f733efc54a14a91d76815115d096, type: 2}
m_Threshold: 1
m_Threshold: 2
m_Position: {x: 0, y: -1}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
m_BlendParameter: DirX
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: ba690f8352f83d44db9fe20b91f9bdb8, type: 2}
m_Threshold: 4
m_Position: {x: -1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: c4d80fdae68078f4f999ae9bd0dbad98, type: 2}
m_Threshold: 8
m_Position: {x: 1, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: GhostType
m_Mirror: 0
m_BlendParameter: Direction
m_BlendParameterY: DirY
m_MinThreshold: 0
m_MaxThreshold: 1
m_UseAutomaticThresholds: 1
m_MinThreshold: 1
m_MaxThreshold: 8
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 1
m_BlendType: 0
--- !u!1107 &1877551748267460816
AnimatorStateMachine:
serializedVersion: 6

View File

@@ -1,30 +1,5 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1101 &-9221672682127973356
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Reset
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 3691335081698814266}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1102 &-6692956035035760530
AnimatorState:
serializedVersion: 6
@@ -32,11 +7,11 @@ AnimatorState:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Alive
m_Name: PacMan
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 6237702739743855209}
- {fileID: -4194104563410422136}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
@@ -52,21 +27,22 @@ AnimatorState:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &-5351155063058543854
--- !u!1102 &-6650627269168583366
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Dead
m_Name: PacManDead
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_Transitions:
- {fileID: 3269978377910821223}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
@@ -78,6 +54,31 @@ AnimatorState:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1101 &-4194104563410422136
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 3
m_ConditionEvent: State
m_EventTreshold: 3
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -6650627269168583366}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0
m_TransitionOffset: 0
m_ExitTime: 0.21924293
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!206 &-2066582439274221996
BlendTree:
m_ObjectHideFlags: 1
@@ -92,52 +93,91 @@ BlendTree:
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: Direction
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 946abf85568070046b684c122ab8c4d3, type: 2}
m_Threshold: 0.25
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: Blend
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 73786a7794bff2a4cab6595789479a9a, type: 2}
m_Threshold: 0.5
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: Blend
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 13e7b0ee5b399f6469049de82d79df18, type: 2}
m_Threshold: 0.75
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: Blend
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: d21f099d8860b8541960bb36f8ec4eac, type: 2}
m_Motion: {fileID: 6902226148018916867}
m_Threshold: 1
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: Blend
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: a28e7bee3098d0a4996a108a60ccf4c0, type: 2}
m_Threshold: 1.25
m_Motion: {fileID: -363858950277856849}
m_Threshold: 2
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: Direction
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: a28e7bee3098d0a4996a108a60ccf4c0, type: 2}
m_Threshold: 3
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 60532b76a26184441b2940a09b1bc07e, type: 2}
m_Threshold: 4
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
m_BlendParameter: State
m_BlendParameterY: Blend
m_MinThreshold: 0
m_MaxThreshold: 4
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 0
--- !u!206 &-363858950277856849
BlendTree:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Stopped
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: c3664638441f28a43ae34a14711f1bb8, type: 2}
m_Threshold: 1
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: bfa17ff437ea1c54cb39e122f0b21896, type: 2}
m_Threshold: 2
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 8f4fe9b8c3a3716418e0d6666757e956, type: 2}
m_Threshold: 4
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 014d5ceffb960844099b49fc63651f78, type: 2}
m_Threshold: 8
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
m_BlendParameter: Direction
m_BlendParameterY: Blend
m_MinThreshold: 0
m_MaxThreshold: 1.25
m_MinThreshold: 1
m_MaxThreshold: 8
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 0
@@ -150,14 +190,8 @@ AnimatorController:
m_Name: PacMan
serializedVersion: 5
m_AnimatorParameters:
- m_Name: Dead
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: Eating
m_Type: 4
- m_Name: State
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
@@ -168,12 +202,6 @@ AnimatorController:
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: Reset
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
@@ -187,56 +215,7 @@ AnimatorController:
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
--- !u!1101 &1948315071244049044
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -6692956035035760530}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.01
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1102 &3691335081698814266
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PacManInitial
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 1948315071244049044}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: 66f7552143c8ca6458831daadd2eafc0, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1101 &6237702739743855209
--- !u!1101 &3269978377910821223
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
@@ -244,23 +223,70 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Dead
m_EventTreshold: 0
- m_ConditionMode: 4
m_ConditionEvent: State
m_EventTreshold: 4
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -5351155063058543854}
m_DstState: {fileID: -6692956035035760530}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0
m_TransitionOffset: 0
m_ExitTime: 0.16666669
m_ExitTime: 0.8611111
m_HasExitTime: 0
m_HasFixedDuration: 1
m_HasFixedDuration: 0
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!206 &6902226148018916867
BlendTree:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Moving
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 13e7b0ee5b399f6469049de82d79df18, type: 2}
m_Threshold: 1
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: d21f099d8860b8541960bb36f8ec4eac, type: 2}
m_Threshold: 2
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 73786a7794bff2a4cab6595789479a9a, type: 2}
m_Threshold: 4
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 946abf85568070046b684c122ab8c4d3, type: 2}
m_Threshold: 8
m_Position: {x: 0, y: 0}
m_TimeScale: 1
m_CycleOffset: 0
m_DirectBlendParameter: State
m_Mirror: 0
m_BlendParameter: Direction
m_BlendParameterY: State
m_MinThreshold: 1
m_MaxThreshold: 8
m_UseAutomaticThresholds: 0
m_NormalizedBlendValues: 0
m_BlendType: 0
--- !u!1107 &7006696717309671173
AnimatorStateMachine:
serializedVersion: 6
@@ -270,18 +296,14 @@ AnimatorStateMachine:
m_PrefabAsset: {fileID: 0}
m_Name: Base Layer
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: -5351155063058543854}
m_Position: {x: 380, y: 230, z: 0}
- serializedVersion: 1
m_State: {fileID: -6692956035035760530}
m_Position: {x: 470, y: 100, z: 0}
m_Position: {x: 420, y: 70, z: 0}
- serializedVersion: 1
m_State: {fileID: 3691335081698814266}
m_Position: {x: 250, y: -10, z: 0}
m_State: {fileID: -6650627269168583366}
m_Position: {x: 441.02686, y: 229.12329, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions:
- {fileID: -9221672682127973356}
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
@@ -289,4 +311,4 @@ AnimatorStateMachine:
m_EntryPosition: {x: 70, y: 100, z: 0}
m_ExitPosition: {x: 800, y: 120, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 3691335081698814266}
m_DefaultState: {fileID: -6692956035035760530}

View File

@@ -0,0 +1,72 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!74 &7400000
AnimationClip:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PacManStoppedDown
serializedVersion: 7
m_Legacy: 0
m_Compressed: 0
m_UseHighQualityCurve: 1
m_RotationCurves: []
m_CompressedRotationCurves: []
m_EulerCurves: []
m_PositionCurves: []
m_ScaleCurves: []
m_FloatCurves: []
m_PPtrCurves:
- serializedVersion: 2
curve:
- time: 0
value: {fileID: -1291921845, guid: 7c9882097c3869842a9cfc7730a9a2dc, type: 3}
attribute: m_Sprite
path:
classID: 212
script: {fileID: 0}
flags: 2
m_SampleRate: 40
m_WrapMode: 0
m_Bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
m_ClipBindingConstant:
genericBindings:
- serializedVersion: 2
path: 0
attribute: 0
script: {fileID: 0}
typeID: 212
customType: 23
isPPtrCurve: 1
isIntCurve: 0
isSerializeReferenceCurve: 0
pptrCurveMapping:
- {fileID: -1291921845, guid: 7c9882097c3869842a9cfc7730a9a2dc, type: 3}
m_AnimationClipSettings:
serializedVersion: 2
m_AdditiveReferencePoseClip: {fileID: 0}
m_AdditiveReferencePoseTime: 0
m_StartTime: 0
m_StopTime: 0.025
m_OrientationOffsetY: 0
m_Level: 0
m_CycleOffset: 0
m_HasAdditiveReferencePose: 0
m_LoopTime: 0
m_LoopBlend: 0
m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0
m_LoopBlendPositionXZ: 0
m_KeepOriginalOrientation: 0
m_KeepOriginalPositionY: 1
m_KeepOriginalPositionXZ: 0
m_HeightFromFeet: 0
m_Mirror: 0
m_EditorCurves: []
m_EulerEditorCurves: []
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bfa17ff437ea1c54cb39e122f0b21896
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 7400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!74 &7400000
AnimationClip:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PacManStoppedLeft
serializedVersion: 7
m_Legacy: 0
m_Compressed: 0
m_UseHighQualityCurve: 1
m_RotationCurves: []
m_CompressedRotationCurves: []
m_EulerCurves: []
m_PositionCurves: []
m_ScaleCurves: []
m_FloatCurves: []
m_PPtrCurves:
- serializedVersion: 2
curve:
- time: 0
value: {fileID: -154195759, guid: 7c9882097c3869842a9cfc7730a9a2dc, type: 3}
attribute: m_Sprite
path:
classID: 212
script: {fileID: 0}
flags: 2
m_SampleRate: 40
m_WrapMode: 0
m_Bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
m_ClipBindingConstant:
genericBindings:
- serializedVersion: 2
path: 0
attribute: 0
script: {fileID: 0}
typeID: 212
customType: 23
isPPtrCurve: 1
isIntCurve: 0
isSerializeReferenceCurve: 0
pptrCurveMapping:
- {fileID: -154195759, guid: 7c9882097c3869842a9cfc7730a9a2dc, type: 3}
m_AnimationClipSettings:
serializedVersion: 2
m_AdditiveReferencePoseClip: {fileID: 0}
m_AdditiveReferencePoseTime: 0
m_StartTime: 0
m_StopTime: 0.025
m_OrientationOffsetY: 0
m_Level: 0
m_CycleOffset: 0
m_HasAdditiveReferencePose: 0
m_LoopTime: 0
m_LoopBlend: 0
m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0
m_LoopBlendPositionXZ: 0
m_KeepOriginalOrientation: 0
m_KeepOriginalPositionY: 1
m_KeepOriginalPositionXZ: 0
m_HeightFromFeet: 0
m_Mirror: 0
m_EditorCurves: []
m_EulerEditorCurves: []
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8f4fe9b8c3a3716418e0d6666757e956
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 7400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!74 &7400000
AnimationClip:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PacManStoppedRight
serializedVersion: 7
m_Legacy: 0
m_Compressed: 0
m_UseHighQualityCurve: 1
m_RotationCurves: []
m_CompressedRotationCurves: []
m_EulerCurves: []
m_PositionCurves: []
m_ScaleCurves: []
m_FloatCurves: []
m_PPtrCurves:
- serializedVersion: 2
curve:
- time: 0
value: {fileID: -1273145802, guid: 7c9882097c3869842a9cfc7730a9a2dc, type: 3}
attribute: m_Sprite
path:
classID: 212
script: {fileID: 0}
flags: 2
m_SampleRate: 40
m_WrapMode: 0
m_Bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
m_ClipBindingConstant:
genericBindings:
- serializedVersion: 2
path: 0
attribute: 0
script: {fileID: 0}
typeID: 212
customType: 23
isPPtrCurve: 1
isIntCurve: 0
isSerializeReferenceCurve: 0
pptrCurveMapping:
- {fileID: -1273145802, guid: 7c9882097c3869842a9cfc7730a9a2dc, type: 3}
m_AnimationClipSettings:
serializedVersion: 2
m_AdditiveReferencePoseClip: {fileID: 0}
m_AdditiveReferencePoseTime: 0
m_StartTime: 0
m_StopTime: 0.025
m_OrientationOffsetY: 0
m_Level: 0
m_CycleOffset: 0
m_HasAdditiveReferencePose: 0
m_LoopTime: 0
m_LoopBlend: 0
m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0
m_LoopBlendPositionXZ: 0
m_KeepOriginalOrientation: 0
m_KeepOriginalPositionY: 1
m_KeepOriginalPositionXZ: 0
m_HeightFromFeet: 0
m_Mirror: 0
m_EditorCurves: []
m_EulerEditorCurves: []
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 014d5ceffb960844099b49fc63651f78
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 7400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!74 &7400000
AnimationClip:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PacManStoppedUp
serializedVersion: 7
m_Legacy: 0
m_Compressed: 0
m_UseHighQualityCurve: 1
m_RotationCurves: []
m_CompressedRotationCurves: []
m_EulerCurves: []
m_PositionCurves: []
m_ScaleCurves: []
m_FloatCurves: []
m_PPtrCurves:
- serializedVersion: 2
curve:
- time: 0
value: {fileID: -388737089, guid: 7c9882097c3869842a9cfc7730a9a2dc, type: 3}
attribute: m_Sprite
path:
classID: 212
script: {fileID: 0}
flags: 2
m_SampleRate: 40
m_WrapMode: 0
m_Bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
m_ClipBindingConstant:
genericBindings:
- serializedVersion: 2
path: 0
attribute: 0
script: {fileID: 0}
typeID: 212
customType: 23
isPPtrCurve: 1
isIntCurve: 0
isSerializeReferenceCurve: 0
pptrCurveMapping:
- {fileID: -388737089, guid: 7c9882097c3869842a9cfc7730a9a2dc, type: 3}
m_AnimationClipSettings:
serializedVersion: 2
m_AdditiveReferencePoseClip: {fileID: 0}
m_AdditiveReferencePoseTime: 0
m_StartTime: 0
m_StopTime: 0.025
m_OrientationOffsetY: 0
m_Level: 0
m_CycleOffset: 0
m_HasAdditiveReferencePose: 0
m_LoopTime: 0
m_LoopBlend: 0
m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0
m_LoopBlendPositionXZ: 0
m_KeepOriginalOrientation: 0
m_KeepOriginalPositionY: 1
m_KeepOriginalPositionXZ: 0
m_HeightFromFeet: 0
m_Mirror: 0
m_EditorCurves: []
m_EulerEditorCurves: []
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c3664638441f28a43ae34a14711f1bb8
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 7400000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

View File

@@ -0,0 +1,114 @@
fileFormatVersion: 2
guid: 433bc126202e0994fa11758168105efa
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

60125
Assets/PacManGame.prefab Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 15ac0ed4c56c7784ea3ae9000fc2af1f
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -12,8 +12,6 @@ GameObject:
- component: {fileID: 7954158839068841090}
- component: {fileID: 4205939556154507887}
- component: {fileID: 3684828990246450362}
- component: {fileID: 4887324676098472752}
- component: {fileID: 620240520301056681}
- component: {fileID: 2436955608773050784}
m_Layer: 0
m_Name: Ghost
@@ -36,7 +34,6 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 4191597391212281593}
- {fileID: 4930314721506563510}
- {fileID: 3602007015285256100}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -60,10 +57,216 @@ MonoBehaviour:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes: []
SerializationNodes:
- Name: directionVectors
Entry: 7
Data: 0|UnityEngine.Vector2[], UnityEngine.CoreModule
- Name:
Entry: 12
Data: 16
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 0
- Name:
Entry: 4
Data: 0
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 0
- Name:
Entry: 4
Data: -1
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 0
- Name:
Entry: 4
Data: 1
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 0
- Name:
Entry: 4
Data: 0
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: -1
- Name:
Entry: 4
Data: 0
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: -1
- Name:
Entry: 4
Data: -1
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: -1
- Name:
Entry: 4
Data: 1
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: -1
- Name:
Entry: 4
Data: 0
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 1
- Name:
Entry: 4
Data: 0
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 1
- Name:
Entry: 4
Data: -1
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 1
- Name:
Entry: 4
Data: 1
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 1
- Name:
Entry: 4
Data: 0
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 0
- Name:
Entry: 4
Data: 0
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 0
- Name:
Entry: 4
Data: -1
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 0
- Name:
Entry: 4
Data: 1
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 4
Data: 0
- Name:
Entry: 4
Data: 0
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
_udonSharpBackingUdonBehaviour: {fileID: 2436955608773050784}
networkManager: {fileID: 0}
ghostType: 3
startState: 0
targetIndicator: {fileID: 5838653651634851978}
--- !u!212 &4205939556154507887
SpriteRenderer:
m_ObjectHideFlags: 0
@@ -137,54 +340,6 @@ Animator:
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!54 &4887324676098472752
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 363162966199215175}
serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_ImplicitCom: 1
m_ImplicitTensor: 1
m_UseGravity: 1
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!65 &620240520301056681
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 363162966199215175}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 0.5, y: 0.5, z: 2}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &2436955608773050784
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -210,61 +365,6 @@ MonoBehaviour:
serializedPublicVariablesBytesString: Ai8AAAAAATIAAABWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgAuAFUAZABvAG4AVgBhAHIAaQBhAGIAbABlAFQAYQBiAGwAZQAsACAAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4AAAAAAAYBAAAAAAAAACcBBAAAAHQAeQBwAGUAAWgAAABTAHkAcwB0AGUAbQAuAEMAbwBsAGwAZQBjAHQAaQBvAG4AcwAuAEcAZQBuAGUAcgBpAGMALgBMAGkAcwB0AGAAMQBbAFsAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4ALgBJAG4AdABlAHIAZgBhAGMAZQBzAC4ASQBVAGQAbwBuAFYAYQByAGkAYQBiAGwAZQAsACAAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4AXQBdACwAIABtAHMAYwBvAHIAbABpAGIAAQEJAAAAVgBhAHIAaQBhAGIAbABlAHMALwEAAAABaAAAAFMAeQBzAHQAZQBtAC4AQwBvAGwAbABlAGMAdABpAG8AbgBzAC4ARwBlAG4AZQByAGkAYwAuAEwAaQBzAHQAYAAxAFsAWwBWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgAuAEkAbgB0AGUAcgBmAGEAYwBlAHMALgBJAFUAZABvAG4AVgBhAHIAaQBhAGIAbABlACwAIABWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgBdAF0ALAAgAG0AcwBjAG8AcgBsAGkAYgABAAAABgEAAAAAAAAAAi8CAAAAAUkAAABWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgAuAFUAZABvAG4AVgBhAHIAaQBhAGIAbABlAGAAMQBbAFsAUwB5AHMAdABlAG0ALgBJAG4AdAAzADIALAAgAG0AcwBjAG8AcgBsAGkAYgBdAF0ALAAgAFYAUgBDAC4AVQBkAG8AbgAuAEMAbwBtAG0AbwBuAAIAAAAGAgAAAAAAAAAnAQQAAAB0AHkAcABlAAEXAAAAUwB5AHMAdABlAG0ALgBTAHQAcgBpAG4AZwAsACAAbQBzAGMAbwByAGwAaQBiACcBCgAAAFMAeQBtAGIAbwBsAE4AYQBtAGUAAR8AAABfAF8AXwBVAGQAbwBuAFMAaABhAHIAcABCAGUAaABhAHYAaQBvAHUAcgBWAGUAcgBzAGkAbwBuAF8AXwBfACcBBAAAAHQAeQBwAGUAARYAAABTAHkAcwB0AGUAbQAuAEkAbgB0ADMAMgAsACAAbQBzAGMAbwByAGwAaQBiABcBBQAAAFYAYQBsAHUAZQACAAAABwUHBQcF
publicVariablesUnityEngineObjects: []
publicVariablesSerializationDataFormat: 0
--- !u!1 &1283232227864845355
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4930314721506563510}
- component: {fileID: 7503794487432367459}
m_Layer: 0
m_Name: PacManCollider
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4930314721506563510
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1283232227864845355}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 140452431933686981}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!136 &7503794487432367459
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1283232227864845355}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.25
m_Height: 2
m_Direction: 2
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &5838653651634851978
GameObject:
m_ObjectHideFlags: 0
@@ -276,7 +376,6 @@ GameObject:
- component: {fileID: 4191597391212281593}
- component: {fileID: 7008590632023811945}
- component: {fileID: 1439451148072521473}
- component: {fileID: 3313165921880363939}
m_Layer: 0
m_Name: Target Indicator
m_TagString: Untagged
@@ -349,27 +448,6 @@ MeshRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!65 &3313165921880363939
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5838653651634851978}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1001 &6726417638088798178
PrefabInstance:
m_ObjectHideFlags: 0

View File

@@ -11,8 +11,6 @@ GameObject:
- component: {fileID: 1315692994360949719}
- component: {fileID: 967117457436250906}
- component: {fileID: 7512162431685415002}
- component: {fileID: 2135601224056198654}
- component: {fileID: 3963523032509914404}
- component: {fileID: 9117212235706742114}
m_Layer: 0
m_Name: Pellet
@@ -111,54 +109,7 @@ MonoBehaviour:
SerializationNodes: []
_udonSharpBackingUdonBehaviour: {fileID: 9117212235706742114}
isPowerPellet: 0
--- !u!65 &2135601224056198654
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4099390335584803315}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 0.5, y: 0.5, z: 0.5}
m_Center: {x: 0, y: 0, z: 0}
--- !u!54 &3963523032509914404
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4099390335584803315}
serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_ImplicitCom: 1
m_ImplicitTensor: 1
m_UseGravity: 1
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
pelletRenderer: {fileID: 0}
--- !u!114 &9117212235706742114
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@@ -9,7 +9,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 8163531541416620119}
- component: {fileID: 1316532931576341977}
- component: {fileID: 7952758579179122936}
- component: {fileID: 7532756116111475170}
- component: {fileID: 4063084300691044555}
@@ -36,27 +35,6 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1316532931576341977
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6582247089451643248}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 0.5, y: 0.5, z: 0.5}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &7952758579179122936
MonoBehaviour:
m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

View File

@@ -6,26 +6,24 @@ namespace Marro.PacManUdon
{
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(Renderer))]
[RequireComponent(typeof(Collider))]
public class BonusFruit : SyncedObject
{
PacManFruitType fruitType;
private PacManFruitType fruitType;
Animator animator;
new Renderer renderer;
new Collider collider;
ScoreBonusDisplay scoreBonusDisplay;
private Animator animator;
private new Renderer renderer;
private ScoreBonusDisplay scoreBonusDisplay;
[UdonSynced] bool active;
private int value;
private bool active;
private float activeCountdown;
private int value;
private bool frozen;
public void Initialize()
{
animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>();
collider = GetComponent<Collider>();
scoreBonusDisplay = transform.Find("ScoreBonusDisplay").gameObject.GetComponent<ScoreBonusDisplay>();
scoreBonusDisplay.Initialize();
SetActive(false);
@@ -33,13 +31,15 @@ namespace Marro.PacManUdon
public override void SyncedUpdate()
{
if (active && !frozen)
if (!active || frozen)
{
activeCountdown -= networkManager.SyncedDeltaTime;
if (activeCountdown <= 0)
{
SetActive(false);
}
return;
}
activeCountdown -= networkManager.SyncedDeltaTime;
if (activeCountdown <= 0)
{
SetActive(false);
}
}
@@ -65,7 +65,6 @@ namespace Marro.PacManUdon
public void SetFruitType(PacManFruitType fruitType)
{
this.fruitType = fruitType;
value = (int)fruitScoreValue[PacManConstants.FruitTypeToValue(fruitType)];
animator.SetFloat("FruitType", PacManConstants.FruitTypeToValue(fruitType));
}
@@ -78,37 +77,38 @@ namespace Marro.PacManUdon
void SetActive(bool active)
{ // This replaces GameObject.active, as attempting to update an animator while a gameobject is inactive seems to result in a silent failure
renderer.enabled = active;
collider.enabled = active;
this.active = active;
}
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
data.Append(active, ref index);
if (!active)
{
return;
}
data.Append(activeCountdown, ref index);
data.Append(frozen, ref index);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
SetActive(data.ReadBool(ref index));
if (!active)
{
return true;
}
activeCountdown = data.ReadFloat(ref index);
frozen = data.ReadBool(ref index);
return true;
}
public PacManFruitType FruitType
{
set
{
SetFruitType(value);
}
get => fruitType;
}
public bool Active
{
set
{
SetActive(value);
}
get => active;
}
public bool Active => active;
private readonly DataDictionary fruitScoreValue = new DataDictionary()
{

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,287 @@
using System;
using UnityEngine;
namespace Marro.PacManUdon
{
enum EatResult
{
None,
Pellet,
PowerPellet
}
public class CollisionManager : SyncedObject
{
public int PelletCount => pellets.Length;
private GameManager gameManager;
private BonusFruit bonusFruit;
private Pellet[] pellets;
private Animator[] powerPellets;
private Ghost[] ghosts;
private byte[] collisionMap;
private int[] pelletIndices;
private const int mazeWidth = 32;
private const int mazeHeight = 32;
private bool powerPelletBlinkEnabled;
private float powerPelletBlinkToggleInterval;
private float powerPelletBlinkProgress;
private bool powerPelletBlinkCurrentlyVisible;
private byte[] pelletMap;
private byte[] syncedPelletsCollected;
private byte pelletCollectedCount;
private int[] ghostPositions = new int[4];
private int pacManPosition;
private bool frozen;
public void Initialize(GameManager gameManager, BonusFruit bonusFruit, Ghost[] ghosts)
{
this.gameManager = gameManager;
this.bonusFruit = bonusFruit;
this.ghosts = ghosts;
gameObject.SetActive(true);
pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
powerPellets = GetComponentsInChildren<Animator>(true);
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
collisionMap = PacManConstants.GetMazeCollisionInfo();
pelletIndices = PacManConstants.GetMazePelletIndices();
Reset();
}
public void Reset()
{
SetPowerPelletsBlink(false);
RestoreAllPellets();
}
internal void SetFrozen(bool frozen)
{
this.frozen = frozen;
if (!frozen)
{
SetPowerPelletsBlink(true);
}
}
#region Collision
public bool IsWallUpcoming(Vector2 position, Vector2 directionVector)
{
var index = GetTilemapIndex(position + directionVector);
var tile = collisionMap[index];
var result = (tile & (int)PacManCollisionInfoType.Wall) != 0;
//Debug.Log($"IsWallUpcoming {position}, {directionVector}. index {index}, tile {tile}, result {result}, collisionMap.Length {collisionMap.Length}");
return result;
}
public bool GhostMoveToTile(Vector2 position, int ghostIndex)
{
var tile = GetTilemapIndex(position);
ghostPositions[ghostIndex] = tile;
if (!frozen && tile == pacManPosition)
{
//Debug.Log("Ghost hit PacMan!");
ghosts[ghostIndex].HitPacMan();
}
return (collisionMap[tile] & (int)PacManCollisionInfoType.Tunnel) != 0;
}
internal EatResult PacManMoveToTile(Vector2 position, Vector2 nextPosition)
{
var tilemapIndex = GetTilemapIndex(nextPosition);
var tile = pelletMap[tilemapIndex];
pacManPosition = tilemapIndex;
if (!frozen)
{
PacManTryEatGhost();
}
TryCollectFruit(tile, position);
return TryCollectPellet(tile, tilemapIndex);
}
internal void PacManTryEatGhost()
{
for (int i = 0; i < ghosts.Length; i++)
{
if (ghostPositions[i] != pacManPosition)
{
continue;
}
if (ghosts[i].HitPacMan()) // Only one collision may happen at a time
{
//Debug.Log("PacMan hit ghost!");
return;
}
}
}
private void TryCollectFruit(int tile, Vector2 position)
{
if (tile != (int)PacManConsumableType.FruitLeft && tile != (int)PacManConsumableType.FruitRight
|| !bonusFruit.Active)
{
return;
}
var previousTile = pelletMap[GetTilemapIndex(position)];
//Debug.Log($"On fruit tile {tile}, previous tile was {previousTile}. Position {position}, nextPosition {nextPosition}");
if (tile == (int)PacManConsumableType.FruitLeft && previousTile == (int)PacManConsumableType.FruitRight
|| tile == (int)PacManConsumableType.FruitRight && previousTile == (int)PacManConsumableType.FruitLeft)
{
//Debug.Log("Collecting fruit");
gameManager.GotFruit();
}
}
public int GetAvailableDirections(Vector2 position)
{
var directions = collisionMap[GetTilemapIndex(position)];
return directions;
}
internal static int GetTilemapIndex(Vector2 position)
{
// (int)position.x %% mazeWidth + (int)position.y %% mazeHeight * mazeWidth, where %% is an absolute modulo
// Absoliute modulo in this case is implemented by just adding the divisor, works good enough and is performant.
var index = ((int)position.x + mazeWidth) % mazeWidth + ((int)position.y + mazeHeight) % mazeHeight * mazeWidth;
return index;
}
#endregion
#region Pellet collecting
private EatResult TryCollectPellet(int tile, int tilemapIndex)
{
if (tile < 0 || tile >= pellets.Length)
{
return EatResult.None;
}
pelletMap[tilemapIndex] = (byte)PacManConsumableType.None;
var pellet = pellets[tile];
pellet.gameObject.SetActive(false);
var index = pellet.transform.GetSiblingIndex();
syncedPelletsCollected[index / 8] |= (byte)(1 << index % 8);
pelletCollectedCount++;
var pelletType = pellet.isPowerPellet ? EatResult.PowerPellet : EatResult.Pellet;
gameManager.GotPellet(pellet, pellet.isPowerPellet, pelletCollectedCount, PelletCount - pelletCollectedCount);
return pelletType;
}
public int RestoreAllPellets()
{
foreach (var pellet in pellets)
{
pellet.gameObject.SetActive(true);
}
syncedPelletsCollected = new byte[pellets.Length/8 + 1];
pelletCollectedCount = 0;
pelletMap = PacManConstants.GetMazePelletMap();
return PelletCount;
}
private void SetPelletsCollectedFromSync()
{
for (byte i = 0; i < pellets.Length; i++)
{
var active = (syncedPelletsCollected[i/8] & (byte)(1 << i%8)) == 0;
pellets[i].gameObject.SetActive(active);
pelletMap[pelletIndices[i]] = active ? i : (byte)PacManConsumableType.None;
}
}
#endregion
#region Power pellet blink
public override void SyncedUpdate()
{
if (!powerPelletBlinkEnabled)
{
return;
}
powerPelletBlinkProgress += networkManager.SyncedDeltaTime;
if (powerPelletBlinkProgress >= powerPelletBlinkToggleInterval)
{
// Debug.Log($"{gameObject} PowerPelletBlink toggle");
powerPelletBlinkProgress -= powerPelletBlinkToggleInterval;
powerPelletBlinkCurrentlyVisible = !powerPelletBlinkCurrentlyVisible;
SetPowerPelletsVisible(powerPelletBlinkCurrentlyVisible);
}
}
void SetPowerPelletsVisible(bool visible)
{
// Debug.Log($"{gameObject} SetPowerPelletVisible {visible}, powerPellets.Length: {powerPellets.Length}");
foreach (Animator powerPellet in powerPellets)
{
powerPellet.SetBool("Visible", visible);
}
}
public void SetPowerPelletsBlink(bool enabled)
{
// Debug.Log($"{gameObject} SetPowerPelletBlink {enabled}");
powerPelletBlinkEnabled = enabled;
powerPelletBlinkCurrentlyVisible = true;
powerPelletBlinkProgress = 0;
SetPowerPelletsVisible(true);
}
public void FreezePowerPelletsBlink(bool frozen)
{
powerPelletBlinkEnabled = !frozen;
}
#endregion
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
data.Append(pelletCollectedCount, ref index);
data.Append(syncedPelletsCollected, ref index);
data.Append(frozen, ref index);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
pelletCollectedCount = data.ReadByte(ref index);
Array.Copy(data, index, syncedPelletsCollected, 0, syncedPelletsCollected.Length);
index += syncedPelletsCollected.Length;
SetPelletsCollectedFromSync();
frozen = data.ReadBool(ref index);
return true;
}
}
}

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 11
Data: 10
- Name:
Entry: 7
Data:
@@ -277,25 +277,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: collider
Data: scoreBonusDisplay
- Name: $v
Entry: 7
Data: 16|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: collider
Data: scoreBonusDisplay
- Name: <UserType>k__BackingField
Entry: 7
Data: 17|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Collider, UnityEngine.PhysicsModule
Data: Marro.PacManUdon.ScoreBonusDisplay, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 17
Data: 4
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -331,25 +331,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: scoreBonusDisplay
Data: active
- Name: $v
Entry: 7
Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: scoreBonusDisplay
Data: active
- Name: <UserType>k__BackingField
Entry: 7
Data: 20|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.ScoreBonusDisplay, Assembly-CSharp
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 4
Data: 20
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -385,19 +385,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: active
Data: activeCountdown
- Name: $v
Entry: 7
Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: active
Data: activeCountdown
- Name: <UserType>k__BackingField
Entry: 7
Data: 23|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
@@ -408,8 +408,8 @@ MonoBehaviour:
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
Entry: 6
Data:
- Name:
Entry: 8
Data:
@@ -421,13 +421,7 @@ MonoBehaviour:
Data: 24|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 25|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
Data: 0
- Name:
Entry: 13
Data:
@@ -448,7 +442,7 @@ MonoBehaviour:
Data: value
- Name: $v
Entry: 7
Data: 26|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: value
@@ -472,61 +466,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 27|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: activeCountdown
- Name: $v
Entry: 7
Data: 28|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: activeCountdown
- Name: <UserType>k__BackingField
Entry: 7
Data: 29|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 29
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 30|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 26|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -550,16 +490,16 @@ MonoBehaviour:
Data: frozen
- Name: $v
Entry: 7
Data: 31|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 27|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: frozen
- Name: <UserType>k__BackingField
Entry: 9
Data: 23
Data: 20
- Name: <SystemType>k__BackingField
Entry: 9
Data: 23
Data: 20
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -574,7 +514,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 32|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 28|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -598,13 +538,13 @@ MonoBehaviour:
Data: fruitScoreValue
- Name: $v
Entry: 7
Data: 33|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: fruitScoreValue
- Name: <UserType>k__BackingField
Entry: 7
Data: 34|System.RuntimeType, mscorlib
Data: 30|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.SDK3.Data.DataDictionary, VRCSDK3
@@ -613,7 +553,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 34
Data: 30
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -628,7 +568,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 35|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 31|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 34
Data: 33
- Name:
Entry: 7
Data:
@@ -730,19 +730,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: $v
Entry: 7
Data: 43|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 44|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PelletManager, Assembly-CSharp
Data: Marro.PacManUdon.CollisionManager, Assembly-CSharp
- Name:
Entry: 8
Data:
@@ -1078,25 +1078,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: demo
Data: soundManager
- Name: $v
Entry: 7
Data: 65|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: demo
Data: soundManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 66|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Animator, UnityEngine.AnimationModule
Data: SoundManager, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 66
Data: 4
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1136,72 +1136,12 @@ MonoBehaviour:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: soundManager
- Name: $v
Entry: 7
Data: 69|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: soundManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 70|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: SoundManager, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 4
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 71|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 72|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: networkManagerSetup
- Name: $v
Entry: 7
Data: 73|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 69|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: networkManagerSetup
@@ -1225,13 +1165,13 @@ MonoBehaviour:
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 74|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 70|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 75|UnityEngine.SerializeField, UnityEngine.CoreModule
Data: 71|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
@@ -1255,7 +1195,7 @@ MonoBehaviour:
Data: recorder
- Name: $v
Entry: 7
Data: 76|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 72|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: recorder
@@ -1279,10 +1219,73 @@ MonoBehaviour:
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 77|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 73|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 74|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: startingExtraLives
- Name: $v
Entry: 7
Data: 75|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: startingExtraLives
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 76|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 77|UnityEngine.HeaderAttribute, UnityEngine.CoreModule
- Name: header
Entry: 1
Data: Game settings
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 78|UnityEngine.SerializeField, UnityEngine.CoreModule
@@ -1306,13 +1309,13 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: startingExtraLives
Data: scoreToExtraLife
- Name: $v
Entry: 7
Data: 79|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: startingExtraLives
Data: scoreToExtraLife
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
@@ -1334,75 +1337,12 @@ MonoBehaviour:
- Name: _fieldAttributes
Entry: 7
Data: 80|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 81|UnityEngine.HeaderAttribute, UnityEngine.CoreModule
- Name: header
Entry: 1
Data: Game settings
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 82|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: scoreToExtraLife
- Name: $v
Entry: 7
Data: 83|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: scoreToExtraLife
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 84|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 85|UnityEngine.SerializeField, UnityEngine.CoreModule
Data: 81|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
@@ -1426,13 +1366,13 @@ MonoBehaviour:
Data: maze
- Name: $v
Entry: 7
Data: 86|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 82|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: maze
- Name: <UserType>k__BackingField
Entry: 7
Data: 87|System.RuntimeType, mscorlib
Data: 83|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Maze, Assembly-CSharp
@@ -1456,7 +1396,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 88|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 84|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1480,13 +1420,13 @@ MonoBehaviour:
Data: intermission2Pole
- Name: $v
Entry: 7
Data: 89|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 85|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: intermission2Pole
- Name: <UserType>k__BackingField
Entry: 7
Data: 90|System.RuntimeType, mscorlib
Data: 86|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Intermission2Pole, Assembly-CSharp
@@ -1510,7 +1450,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 91|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 87|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1534,16 +1474,76 @@ MonoBehaviour:
Data: mazeSpriteAnimator
- Name: $v
Entry: 7
Data: 92|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 88|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: mazeSpriteAnimator
- Name: <UserType>k__BackingField
Entry: 9
Data: 66
Entry: 7
Data: 89|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Animator, UnityEngine.AnimationModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 66
Data: 89
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 90|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: attractScreenElements
- Name: $v
Entry: 7
Data: 91|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: attractScreenElements
- Name: <UserType>k__BackingField
Entry: 7
Data: 92|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.GameObject[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 92
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1579,25 +1579,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: attractScreenElements
Data: intermissionScreenElements
- Name: $v
Entry: 7
Data: 94|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: attractScreenElements
Data: intermissionScreenElements
- Name: <UserType>k__BackingField
Entry: 7
Data: 95|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.GameObject[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
Entry: 9
Data: 92
- Name: <SystemType>k__BackingField
Entry: 9
Data: 95
Data: 92
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1612,7 +1606,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 96|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 95|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1633,19 +1627,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: intermissionScreenElements
Data: gameState
- Name: $v
Entry: 7
Data: 97|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 96|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: intermissionScreenElements
Data: gameState
- Name: <UserType>k__BackingField
Entry: 9
Data: 95
Entry: 7
Data: 97|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PacManGameState, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 95
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1681,65 +1681,10 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: gameState
Data: score
- Name: $v
Entry: 7
Data: 99|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: gameState
- Name: <UserType>k__BackingField
Entry: 7
Data: 100|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PacManGameState, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 101|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: score
- Name: $v
Entry: 7
Data: 102|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: score
@@ -1763,7 +1708,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 103|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
Data: 100|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
@@ -1788,7 +1733,7 @@ MonoBehaviour:
Data: level
- Name: $v
Entry: 7
Data: 104|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 101|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: level
@@ -1812,7 +1757,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 105|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
Data: 102|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
@@ -1837,7 +1782,7 @@ MonoBehaviour:
Data: highScore
- Name: $v
Entry: 7
Data: 106|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 103|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: highScore
@@ -1861,7 +1806,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 107|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
Data: 104|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
@@ -1886,7 +1831,7 @@ MonoBehaviour:
Data: extraLives
- Name: $v
Entry: 7
Data: 108|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 105|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: extraLives
@@ -1910,7 +1855,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 109|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
Data: 106|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12

View File

@@ -10,13 +10,12 @@ namespace Marro.PacManUdon
[SerializeField] private PacMan pacMan;
[SerializeField] private GhostManager ghostManager;
[SerializeField] private BonusFruit bonusFruit;
[SerializeField] private PelletManager pelletManager;
[SerializeField] private CollisionManager collisionManager;
[SerializeField] private StatusDisplay statusDisplay;
[SerializeField] private PelletManager attractScreen;
[SerializeField] private CollisionManager attractScreen;
[SerializeField] private GameObject intermissionScreen;
[SerializeField] private GameObject pressStartButtonScreen;
[SerializeField] private PlayerInput playerInput;
[SerializeField] private Animator demo;
[SerializeField] private SoundManager soundManager;
[SerializeField] private NetworkManager networkManagerSetup;
@@ -58,15 +57,18 @@ namespace Marro.PacManUdon
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
networkManager.Initialize();
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this);
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, collisionManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this, collisionManager);
bonusFruit.Initialize();
pelletManager.Initialize();
collisionManager.Initialize(this, bonusFruit, ghostManager.Ghosts);
statusDisplay.Initialize();
playerInput.Initialize(this);
soundManager.Initialize();
intermission2Pole.Initialize(this, ghostManager.Ghosts[0]);
SubscribeToEvent(NetworkEventType.StartGameButtonPressed);
SubscribeToEvent(NetworkEventType.FullSync);
HideEverything();
SetScore(0);
@@ -104,7 +106,7 @@ namespace Marro.PacManUdon
Debug.Log($"{gameObject} Start Game Button was pressed!");
if (networkManager.IsOwner)
{
networkManager.SendEventNow(NetworkEventType.StartGameButtonPressed);
networkManager.SendEventSoon(NetworkEventType.StartGameButtonPressed, false);
}
StartTimeSequence(PacManTimeSequence.StartNewGame);
}
@@ -123,34 +125,24 @@ namespace Marro.PacManUdon
private void InitializeNewGame()
{
Debug.Log($"{gameObject} Started new game!");
//Debug.Log($"{gameObject} Started new game!");
SetScore(0);
SetExtraLives(startingExtraLives);
SetLevel(1);
}
private void InitializeLevel()
{
Debug.Log($"{gameObject} New level started!");
pelletManager.RestoreAllPellets();
ghostManager.NewLevel();
mazeSpriteAnimator.SetBool("Blinking", false);
}
private void RestartLevel(bool afterLifeLost = false)
{
Debug.Log($"{gameObject} (Re)started level!");
//Debug.Log($"{gameObject} (Re)started level!");
// SetInGameComponentVisibility(true);
mazeSpriteAnimator.SetBool("Blinking", false);
ghostManager.RestartLevel(afterLifeLost);
pacMan.Reset();
bonusFruit.Despawn();
soundManager.Reset();
pelletManager.SetPowerPelletsBlink(false);
collisionManager.Reset();
statusDisplay.Reset();
}
private void PrepareForCutscene()
@@ -160,25 +152,35 @@ namespace Marro.PacManUdon
SetFrozen(true);
}
public void GotPellet(Pellet pellet, bool addScore = true)
internal void GotPellet(Pellet pellet, bool isPowerPellet, int pelletsCollectedCount, int pelletsRemainingCount)
{
var pelletCollectedCount = pelletManager.PelletCollected(pellet);
AddScore(isPowerPellet ? 50 : 10);
if (addScore) AddScore(10);
ghostManager.PelletConsumed();
ghostManager.PelletConsumed(pelletsRemainingCount);
soundManager.PlayPelletSound();
soundManager.UpdatePelletCount(pelletsRemainingCount);
var pelletCountRemaining = pelletManager.PelletCount - pelletCollectedCount;
soundManager.UpdatePelletCount(pelletCountRemaining);
if (pelletCountRemaining <= 0)
if (pelletsRemainingCount <= 0)
{
StartTimeSequence(PacManTimeSequence.BoardClear);
return;
}
else if (pelletCollectedCount == 70 || pelletCollectedCount == 170)
if (isPowerPellet)
{
if (gameState == PacManGameState.AttractMode)
{
TimeSequenceSkipToNextStep();
return;
}
ghostManager.SetPowerPellet(true);
pacMan.SetPowerPellet(true);
soundManager.SetGhostBlue(true);
}
if (pelletsCollectedCount == 70 || pelletsCollectedCount == 170)
{
bonusFruit.Spawn();
}
@@ -186,18 +188,9 @@ namespace Marro.PacManUdon
public void GotPowerPellet(Pellet pellet)
{
Debug.Log($"{gameObject} GotPowerPellet");
//Debug.Log($"{gameObject} GotPowerPellet");
if (gameState == PacManGameState.AttractMode)
{
TimeSequenceSkipToNextStep();
return;
}
GotPellet(pellet, addScore: false);
AddScore(50);
ghostManager.SetPowerPellet(true);
pacMan.SetPowerPellet(true);
soundManager.SetGhostBlue(true);
}
public void EndPowerPellet()
@@ -215,7 +208,7 @@ namespace Marro.PacManUdon
public void GhostCaught(int scoreBonus)
{
Debug.Log($"{gameObject} GhostCaught");
//Debug.Log($"{gameObject} GhostCaught");
if (gameState == PacManGameState.AttractMode)
{
@@ -225,7 +218,6 @@ namespace Marro.PacManUdon
AddScore(scoreBonus);
StartTimeSequence(PacManTimeSequence.GhostCaught);
pacMan.HideUntilUnfrozen();
}
public void PacManCaught()
@@ -246,7 +238,7 @@ namespace Marro.PacManUdon
public void Intermission2PoleUpdate()
{
Debug.Log($"{gameObject} Intermission2PoleUpdate");
//Debug.Log($"{gameObject} Intermission2PoleUpdate");
TimeSequenceSkipToNextStep();
}
@@ -271,12 +263,11 @@ namespace Marro.PacManUdon
statusDisplay.SetLevelDisplayVisible(false);
statusDisplay.SetPlayer1TextVisible(false);
statusDisplay.SetReadyTextVisible(false);
demo.gameObject.SetActive(false);
}
void SetPelletsActive(bool active)
{
pelletManager.gameObject.SetActive(active);
collisionManager.gameObject.SetActive(active);
}
void SetMazeVisible(bool visible)
@@ -381,41 +372,115 @@ namespace Marro.PacManUdon
soundManager.PlayExtraLifeSound();
}
private void SetupInGameState()
{
gameState = PacManGameState.InGame;
attractScreen.gameObject.SetActive(false);
SetPelletsActive(true);
SetMazeVisible(true);
SetGhostsActive(true);
SetPacManActive(true);
statusDisplay.SetExtraLivesDisplayVisible(true);
statusDisplay.SetLevelDisplayVisible(true);
statusDisplay.SetLabel1UPTextBlinking(true);
soundManager.SuppressSound(false);
soundManager.StartGhostSound();
SetFrozen(false);
}
public void SetFrozen(bool frozen, bool ghostIgnoreIfCaught = false, bool ghostKeepAnimating = false)
{
// Debug.Log($"{gameObject} Set Frozen: {frozen}");
pacMan.SetFrozen(frozen);
bonusFruit.SetFrozen(frozen);
ghostManager.SetFrozen(frozen, ignoreIfCaught: ghostIgnoreIfCaught);
if (!frozen)
{
pelletManager.SetPowerPelletsBlink(true);
}
collisionManager.SetFrozen(frozen);
}
public override void CollectSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
//data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) };
//data[offset++] = BitConverter.GetBytes(currentlyInTimeSequence);
//data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)currentTimeSequence) };
//data[offset++] = BitConverter.GetBytes(timeSequenceSecondsPassed);
if (eventType != NetworkEventType.FullSync)
{
return;
}
data.Append(gameState == PacManGameState.InGame, ref index);
data.AppendAsByte(level, ref index);
data.Append(score, ref index);
data.AppendAsByte(extraLives, ref index);
data.Append(currentlyInTimeSequence, ref index);
if (currentlyInTimeSequence)
{
data.AppendAsByte((int)currentTimeSequence, ref index);
data.Append(timeSequenceSecondsPassed, ref index);
}
bonusFruit.CollectSyncedData(data, ref index, eventType);
collisionManager.CollectSyncedData(data, ref index, eventType);
ghostManager.CollectSyncedData(data, ref index, eventType);
pacMan.CollectSyncedData(data, ref index, eventType);
soundManager.CollectSyncedData(data, ref index, eventType);
}
public override bool WriteSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType == NetworkEventType.StartGameButtonPressed)
{
StartGameButtonPressed();
return true;
}
//SetGameState((PacManGameState)data[offset++]);
if (eventType != NetworkEventType.FullSync)
{
return true;
}
//var currentlyInTimeSequence = BitConverter.ToBoolean(data, offset++);
//var currentTimeSequence = (PacManTimeSequence)data[offset++];
//var timeSequenceSecondsPassed = BitConverter.ToSingle(data, offset);
//offset += 4;
//TimeSequenceSyncWithRemote(currentlyInTimeSequence, currentTimeSequence, timeSequenceSecondsPassed);
// If we're currently in-game, we'll need to make sure the state is setup correctly
var remoteCurrentlyInGame = data.ReadBool(ref index);
if (remoteCurrentlyInGame)
{
currentlyInTimeSequence = false; // Kill the current time sequence, otherwise it might interfere
// No need to run it to completion since we're overriding all state
SetupInGameState();
}
SetLevel(data.ReadByte(ref index));
SetScore(data.ReadInt(ref index));
SetExtraLives(data.ReadByte(ref index));
// Sync up with the remote's time sequence
var remoteCurrentlyInTimeSequence = data.ReadBool(ref index);
if (remoteCurrentlyInTimeSequence)
{
var currentTimeSequence = (PacManTimeSequence)data.ReadByte(ref index);
var timeSequenceSecondsPassed = data.ReadFloat(ref index);
TimeSequenceSyncWithRemote(currentTimeSequence, timeSequenceSecondsPassed);
}
// Note that we don't have any logic for if the remote is not in-game and not in a time sequence.
// Such a state should be impossible.
bonusFruit.WriteSyncedData(data, ref index, eventType);
collisionManager.WriteSyncedData(data, ref index, eventType);
ghostManager.WriteSyncedData(data, ref index, eventType);
pacMan.WriteSyncedData(data, ref index, eventType);
soundManager.WriteSyncedData(data, ref index, eventType);
return true;
}
@@ -424,4 +489,4 @@ namespace Marro.PacManUdon
public int Level => level;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -15,6 +15,15 @@ namespace Marro.PacManUdon
Special,
}
enum PacManGhostAnimatorState
{
Normal,
Caught,
Scared,
ScaredWhite,
Special
}
public enum PacManGhostState
{
Normal,
@@ -22,7 +31,8 @@ namespace Marro.PacManUdon
Returning,
Entering,
Home,
Exiting
Exiting,
WaitingForStart,
}
public enum PacManGhostStartState
@@ -38,18 +48,18 @@ namespace Marro.PacManUdon
{
[SerializeField] private PacManGhostType ghostType;
[SerializeField] private PacManGhostStartState startState;
[SerializeField] private GameObject targetIndicator;
// External references
private GhostManager ghostManager;
private CollisionManager collisionManager;
private Animator animator;
private new Renderer renderer;
private PacMan pacMan;
private Ghost blinky;
private ScoreBonusDisplay scoreBonusDisplay;
private Vector3 startPosition;
private Quaternion startRotation;
private Vector2 startPosition;
private Vector2 homePosition;
private Vector2 idlePosition1;
private Vector2 idlePosition2;
@@ -67,6 +77,7 @@ namespace Marro.PacManUdon
// State
private PacManGhostState ghostState;
private bool isScared;
private bool whiteScared;
private bool scattering;
private PacManGhostFrozenState frozenState;
@@ -75,25 +86,28 @@ namespace Marro.PacManUdon
private int housePelletCounter;
private bool housePelletCounterActive;
private int housePelletCounterLimit;
private bool faceInStartingDirectionUntilUnfrozen;
// Cutscene
private bool kinematic;
private bool specialLook;
private bool followingPredefinedPath;
private Vector2[] predefinedPath;
private Direction[] predefinedPath;
private int predefinedPathIndex;
public bool IsScared => isScared;
public int Index { get; private set; }
public void Initialize(PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index)
private readonly int animatorKeyDirection = Animator.StringToHash("Direction");
private readonly int animatorKeyGhostType = Animator.StringToHash("GhostType");
public void Initialize(CollisionManager collisionManager, PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index)
{
ghostManager = transform.parent.GetComponent<GhostManager>();
animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>();
this.collisionManager = collisionManager;
this.pacMan = pacMan;
this.blinky = blinky;
this.homePosition = homePosition;
@@ -104,45 +118,44 @@ namespace Marro.PacManUdon
scoreBonusDisplay = transform.Find("ScoreBonusDisplay").gameObject.GetComponent<ScoreBonusDisplay>();
scoreBonusDisplay.Initialize();
startPosition = startTransform.localPosition;
startRotation = startTransform.localRotation;
frozenState = PacManGhostFrozenState.Frozen;
Index = index;
targetIndicator.transform.parent = transform.parent;
}
public void Reset()
{
// Debug.Log($"{gameObject} Reset!");
transform.SetLocalPositionAndRotation(startPosition, startRotation);
if (startState == PacManGhostStartState.Outside)
{
ghostState = PacManGhostState.Exiting;
OffGridTargetReached();
}
else
{
if (startState == PacManGhostStartState.TargetingIdlePosition1)
{
SetOffGridTarget(idlePosition1, false);
}
ghostState = PacManGhostState.Entering;
OffGridTargetReached();
}
SetPosition(startPosition);
offGrid = true;
isScared = false;
inTunnel = false;
kinematic = false;
followingPredefinedPath = false;
turnAroundSoon = false;
specialLook = false;
rngState = 1;
UpdateSpeed();
faceInStartingDirectionUntilUnfrozen = true;
UpdateAnimator();
ghostState = PacManGhostState.WaitingForStart;
switch (startState)
{
case PacManGhostStartState.TargetingIdlePosition1:
SetTargetDirection(Direction.Up);
break;
case PacManGhostStartState.TargetingIdlePosition2:
SetTargetDirection(Direction.Down);
break;
default:
SetTargetDirection(Direction.Left);
break;
}
UpdateSpeed();
// Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}");
}
@@ -150,26 +163,26 @@ namespace Marro.PacManUdon
public override void SyncedUpdate()
{
if (frozenState == PacManGhostFrozenState.Frozen ||
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering))
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering))
{
return;
}
Vector2 position = GetPosition();
Vector2 nextPosition = GridMoverTools.GetNextPosition(position, direction, speed, networkManager.SyncedDeltaTime);
Vector2 nextPosition = GetNextPosition(position, directionVectors[(int)direction], speed, networkManager.SyncedDeltaTime);
nextPosition = ProcessNextPosition(position, nextPosition);
SetPosition(nextPosition);
}
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
{
if (turnAroundSoon && ghostState == PacManGhostState.Normal
&& GridMoverTools.CrossesTileBorder(position, nextPosition, direction.x != 0, direction.y != 0))
&& CrossesTileCenter(position, nextPosition, direction))
{
SetDirection(direction * -1);
Debug.Log($"{gameObject} turned around to direction {GetDirection()}");
var newDirection = GetInverseDirection(direction);
SetDirectionAndTargetDirection(newDirection);
turnAroundSoon = false;
return nextPosition;
}
@@ -179,86 +192,170 @@ namespace Marro.PacManUdon
return nextPosition;
}
if (offGrid || ghostState == PacManGhostState.Returning)
if (ghostState == PacManGhostState.WaitingForStart)
{
bool XAxisAlligned = CheckAndAllignToTargetX(position, nextPosition, target);
bool YAxisAlligned = CheckAndAllignToTargetY(position, nextPosition, target);
if (offGrid)
switch (startState)
{
if (XAxisAlligned)
{
nextPosition.x = target.x;
}
if (YAxisAlligned)
{
nextPosition.y = target.y;
}
case PacManGhostStartState.TargetingIdlePosition1:
SetOffGridTarget(idlePosition1, false);
ghostState = PacManGhostState.Entering;
break;
case PacManGhostStartState.TargetingIdlePosition2:
SetOffGridTarget(idlePosition2, false);
ghostState = PacManGhostState.Entering;
break;
default:
ghostState = PacManGhostState.Exiting;
break;
}
if (XAxisAlligned && YAxisAlligned)
{
if (!offGrid)
{
nextPosition = target;
}
OffGridTargetReached();
// Debug.Log($"{gameObject} reached offGridTarget {target} at position {position}, new state {state}, offGrid is now {offGrid}, new direction: {direction}");
}
if ((XAxisAlligned || YAxisAlligned) && offGrid)
{
SetDirection(GetOffGridDirectionToTarget(nextPosition, target, direction));
// Debug.Log($"{gameObject} Alligned X Axis: {XAxisAlligned}, Y Axis: {YAxisAlligned} with position: {position}, new nextPosition: {nextPosition}, new target: {target}, now moving in direction {direction}");
// nextPosition = GridMover.GetNextPosition(position, direction, speed);
}
}
if (!offGrid && followingPredefinedPath)
{
nextPosition = ProcessPredefinedPath(position, nextPosition);
}
else if (!offGrid && GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, direction.y != 0))
{
Vector2 gridPosition = GridMoverTools.PositionToGrid(position);
Vector2[] availableDirections = GetAvailableDirections(gridPosition, direction * -1);
if (availableDirections.Length > 1)
{
target = GetGridTarget(gridPosition);
SetDirection(GetGridDirectionToTargetGreedy(availableDirections, gridPosition, target));
nextPosition = GridMoverTools.GetNextPosition(gridPosition, direction, speed, networkManager.SyncedDeltaTime);
// Debug.Log($"GetNextPosition at gridPosition {gridPosition} with direction {direction} and speed {speed} gives nextPosition {nextPosition}");
}
else if (availableDirections.Length == 1 && availableDirections[0] != direction)
{
SetDirection(availableDirections[0]);
nextPosition = GridMoverTools.GetNextPosition(gridPosition, direction, speed, networkManager.SyncedDeltaTime);
}
// Debug.Log($"{gameObject} crossed tile center {gridPosition}, new target: {target}, new direction: {direction}");
OffGridTargetReached();
}
var distance = Vector2.Distance(position, nextPosition);
if (distance > 0.5f)
if (offGrid || ghostState == PacManGhostState.Returning)
{
Debug.LogError($"{gameObject} Just jumped by distance {distance}! position: {position}, nextPosition: {nextPosition}, direction: {direction}, offGrid: {offGrid}, ghostState: {ghostState}");
PerformOffgridRelatedMovement(position, ref nextPosition);
}
if (!offGrid)
{
if (followingPredefinedPath)
{
ProcessPredefinedPath(position, ref nextPosition);
}
else if (CrossesTileCenter(position, nextPosition, direction))
{
if (targetDirection != direction)
{
ApplyTargetDirection(position, out nextPosition);
}
else
{
TryToQueueTurn(position);
}
}
}
if (CrossesTileBorder(position, nextPosition, direction))
{
var inTunnel = collisionManager.GhostMoveToTile(nextPosition, Index);
if (inTunnel != this.inTunnel)
{
this.inTunnel = inTunnel;
UpdateSpeed();
}
}
return nextPosition;
}
private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition)
private Vector2 PerformOffgridRelatedMovement(Vector2 position, ref Vector2 nextPosition)
{
if (GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, direction.y != 0))
bool XAxisAlligned = CheckAndAllignToTargetX(position, nextPosition, target);
bool YAxisAlligned = CheckAndAllignToTargetY(position, nextPosition, target);
if (offGrid)
{
if (XAxisAlligned)
{
nextPosition.x = target.x;
}
if (YAxisAlligned)
{
nextPosition.y = target.y;
}
}
if (XAxisAlligned && YAxisAlligned)
{
if (!offGrid)
{
nextPosition = target;
}
OffGridTargetReached();
// Debug.Log($"{gameObject} reached offGridTarget {target} at position {position}, new state {state}, offGrid is now {offGrid}, new direction: {direction}");
}
if ((XAxisAlligned || YAxisAlligned) && offGrid)
{
SetDirectionAndTargetDirection(GetOffGridDirectionToTarget(nextPosition, target, direction));
// Debug.Log($"{gameObject} Alligned X Axis: {XAxisAlligned}, Y Axis: {YAxisAlligned} with position: {position}, new nextPosition: {nextPosition}, new target: {target}, now moving in direction {direction}");
// nextPosition = GridMover.GetNextPosition(position, direction, speed);
}
return nextPosition;
}
private void TryToQueueTurn(Vector2 position)
{
var upcomingGridPosition = PositionToGrid(position + directionVectors[(int)direction]);
var availableDirections = collisionManager.GetAvailableDirections(upcomingGridPosition);
if ((availableDirections & (int)PacManCollisionInfoType.NoTurn) != 0)
{
return;
}
if (!isScared && (availableDirections & (int)PacManCollisionInfoType.HorizontalOnly) != 0)
{
availableDirections &= 0b1100;
}
availableDirections &= ~(int)GetInverseDirection(direction) & 0b1111; // Not allowed to turn around, also filter flags other than direction
if (availableDirections == 0)
{
return;
}
Direction newDirection;
if (isSingleBitSet[availableDirections])
{
newDirection = (Direction)availableDirections;
}
else
{
target = GetGridTarget(upcomingGridPosition);
targetIndicator.transform.localPosition = target;
newDirection = GetGridDirectionToTargetGreedy(availableDirections, upcomingGridPosition, target);
}
if (newDirection == direction)
{
return;
}
SetTargetDirection(newDirection);
}
// Static fields are not yet supported on user-defined types
private readonly bool[] isSingleBitSet = new bool[]
{
//0000,0001, 0010, 0011 , 0100, 0101 , 0110 , 0111 , 1000, 1001 , 1010 , 1011 , 1100 , 1101 , 1110 , 1111
false, true, true, false, true, false, false, false, true, false, false, false, false, false, false, false
};
private void ApplyTargetDirection(Vector2 position, out Vector2 nextPosition)
{
var gridPosition = PositionToGrid(position);
nextPosition = GetNextPosition(gridPosition, directionVectors[(int)targetDirection], speed, networkManager.SyncedDeltaTime);
SetDirection(targetDirection);
}
private void ProcessPredefinedPath(Vector2 position, ref Vector2 nextPosition)
{
if (CrossesTileCenter(position, nextPosition, direction))
{
// Find the next valid direction which isn't Vector2.zero
int nextValidDirectionIndex = predefinedPathIndex;
while (predefinedPath[nextValidDirectionIndex] == Vector2.zero)
while (predefinedPath[nextValidDirectionIndex] == Direction.Zero)
{
nextValidDirectionIndex += 1;
}
if (!GridMoverTools.CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex]))
if (!collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)predefinedPath[nextValidDirectionIndex]]))
{
// If we're at a Vector2.zero, we skip applying the direction and only increment.
if (nextValidDirectionIndex == predefinedPathIndex)
{
SetDirection(predefinedPath[nextValidDirectionIndex]);
nextPosition = GridMoverTools.PositionToGrid(nextPosition) + direction.normalized * 0.01f;
SetDirectionAndTargetDirection(predefinedPath[nextValidDirectionIndex]);
nextPosition = PositionToGrid(nextPosition) + directionVectors[(int)direction] * 0.01f;
// Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero
do
@@ -269,7 +366,7 @@ namespace Marro.PacManUdon
followingPredefinedPath = false;
break;
}
} while (predefinedPath[nextValidDirectionIndex] == Vector2.zero);
} while (predefinedPath[nextValidDirectionIndex] == Direction.Zero);
}
// ghostManager.gameStateManager.statusDisplay.SetDebugText(1, predefinedPathIndex.ToString());
@@ -277,71 +374,59 @@ namespace Marro.PacManUdon
predefinedPathIndex++;
}
}
return nextPosition;
}
Vector2 GetGridTarget(Vector2 gridPosition)
private Vector2 GetGridTarget(Vector2 gridPosition)
{
// if (followingPredefinedPath)
// {
// predefinedPathIndex++;
// if (predefinedPathIndex >= predefinedPath.Length)
// {
// followingPredefinedPath = false;
// }
// return gridPosition + predefinedPath[predefinedPathIndex];
// }
if (isScared)
{
switch (PseudoRNG() % 4)
{
default:
return gridPosition;
case 0:
return gridPosition + Vector2.up;
case 1:
return gridPosition + Vector2.left;
case 2:
return gridPosition + Vector2.down;
case 3:
return gridPosition + Vector2.right;
}
return gridPosition + directionVectors[(int)cardinalDirections[PseudoRNG() % 4]];
}
switch (ghostState)
if (ghostState == PacManGhostState.Returning)
{
return homePosition;
}
if (scattering)
{
return cornerPosition;
}
switch (ghostType)
{
default:
return gridPosition;
case PacManGhostState.Normal:
if (scattering)
case PacManGhostType.Blinky: // Chase PacMan directly
return PositionToGrid(pacMan.GetPosition());
case PacManGhostType.Pinky: // Try to get ahead of PacMan
return GetTargetAheadOfPacMan(4);
case PacManGhostType.Inky: // Try to attack from the opposite side of Blinky
var blinkyPosition = PositionToGrid(blinky.GetPosition());
return ((GetTargetAheadOfPacMan(2) - blinkyPosition) * 2) + blinkyPosition;
case PacManGhostType.Clyde: // Chase PacMan, but retreat to corner if PacMan gets to close
var pacManPosition = PositionToGrid(pacMan.GetPosition());
if (Vector2.Distance(gridPosition, pacManPosition) < 8)
{
return cornerPosition;
}
switch (ghostType)
{
default:
return gridPosition;
case PacManGhostType.Blinky:
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition);
case PacManGhostType.Pinky:
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition) + pacMan.GetDirection() * 4;
case PacManGhostType.Inky:
return 2 * GridMoverTools.PositionToGrid(pacMan.transform.localPosition) + 4 * pacMan.GetDirection() - GridMoverTools.PositionToGrid(blinky.transform.localPosition);
case PacManGhostType.Clyde:
if (Vector2.Distance(gridPosition, GridMoverTools.PositionToGrid(pacMan.transform.localPosition)) >= 8)
{
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition);
}
else
{
// Debug.Log($"{gameObject} goes to cornerPosition {cornerPosition}");
return cornerPosition;
}
}
case PacManGhostState.Returning:
return homePosition;
return pacManPosition;
}
}
private Vector2 GetTargetAheadOfPacMan(int tilesInFront)
{
var direction = pacMan.GetTargetDirection();
var result = PositionToGrid(pacMan.GetPosition()) + directionVectors[(int)direction] * tilesInFront;
if (direction == Direction.Up) // Reproducing a bug in the original game
{
result.x -= tilesInFront;
}
return result;
}
bool CheckAndAllignToTargetX(Vector2 currentPosition, Vector2 nextPosition, Vector2 target)
{
return (currentPosition.x - target.x) * (nextPosition.x - target.x) <= 0.01;
@@ -384,7 +469,7 @@ namespace Marro.PacManUdon
case PacManGhostState.Exiting:
offGrid = false;
SetState(PacManGhostState.Normal);
SetDirection(Vector2.left);
SetDirectionAndTargetDirection(Direction.Left);
break;
}
}
@@ -393,11 +478,11 @@ namespace Marro.PacManUdon
{
if (startHorizontal)
{
SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Vector2.right));
SetDirectionAndTargetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Direction.Right));
}
else
{
SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Vector2.down));
SetDirectionAndTargetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Direction.Down));
}
// Debug.Log($"{gameObject} SetOffGridTarget with position {GetPosition()}, newTarget {newTarget}, startHorizontal {startHorizontal} resulted in direction {direction}");
target = newTarget;
@@ -408,72 +493,45 @@ namespace Marro.PacManUdon
rngState ^= rngState << 13;
rngState ^= rngState >> 17;
rngState ^= rngState << 5;
return rngState;
return Math.Abs(rngState);
}
Vector2[] GetAvailableDirections(Vector2 gridPosition, Vector2 discardDirection)
private readonly Direction[] cardinalDirections = new Direction[] { Direction.Up, Direction.Left, Direction.Down, Direction.Right };
Direction GetGridDirectionToTargetGreedy(int availableDirections, Vector2 gridPosition, Vector2 targetGridPosition)
{
Vector2[] directions;
Vector2[] availableDirections;
if (horizontalOnly && ghostState == PacManGhostState.Normal)
{
directions = new Vector2[] { new Vector2(1, 0), new Vector2(-1, 0) };
availableDirections = new Vector2[2];
}
else
{
directions = new Vector2[] { new Vector2(0, 1), new Vector2(1, 0), new Vector2(0, -1), new Vector2(-1, 0) };
availableDirections = new Vector2[4];
}
Direction bestDirection = Direction.Zero;
float bestDistance = float.MaxValue;
int availableDirectionsNum = 0;
for (int i = 0; i < directions.Length; i++)
foreach (var direction in cardinalDirections)
{
if (directions[i].Equals(discardDirection) || GridMoverTools.CheckCollisionInDirection(transform, gridPosition, directions[i]))
if (((int)direction & availableDirections) == 0)
{
continue;
}
availableDirections[availableDirectionsNum] = directions[i];
availableDirectionsNum++;
}
Vector2[] availableDirectionsTrimmed = new Vector2[availableDirectionsNum];
// Debug.Log($"{gameObject} Number of available directions: {availableDirectionsTrimmed.Length}");
Array.Copy(availableDirections, 0, availableDirectionsTrimmed, 0, availableDirectionsNum);
return availableDirectionsTrimmed;
}
Vector2 GetGridDirectionToTargetGreedy(Vector2[] availableDirections, Vector2 gridPosition, Vector2 targetGridPosition)
{
Vector2 bestDirection = Vector2.zero;
float bestDistance = float.MaxValue;
for (int i = 0; i < availableDirections.Length; i++)
{
Vector2 direction = availableDirections[i];
// Debug.Log("Evaluating direction " + direction);
float distance = Vector2.Distance(gridPosition + direction, targetGridPosition);
float distance = Vector2.Distance(gridPosition + directionVectors[(int)direction], targetGridPosition);
if (distance < bestDistance)
{
bestDistance = distance;
bestDirection = direction;
}
}
// Debug.Log("Closest next tile is in direction " + bestDirection);
//Debug.Log($"{gameObject.name} Closest next tile is in direction {bestDirection}");
return bestDirection;
}
Vector2 GetOffGridDirectionToTarget(Vector2 position, Vector2 target, Vector2 direction)
private Direction GetOffGridDirectionToTarget(Vector2 position, Vector2 target, Direction direction)
{
if ((direction.x != 0 && position.x != target.x) || position.y == target.y)
if ((IsHorizontal(direction) && position.x != target.x) || position.y == target.y)
{
// Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the X axis in direction {new Vector2(target.x-position.x, 0).normalized}");
return new Vector2(target.x - position.x, 0).normalized;
return HorizontalToDirection(target.x - position.x);
}
else
{
// Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the Y axis in direction {new Vector2(0, target.y-position.y).normalized}");
return new Vector2(0, target.y - position.y).normalized;
return VerticalToDirection(target.y - position.y);
}
}
@@ -482,80 +540,40 @@ namespace Marro.PacManUdon
if (!gameObject.activeInHierarchy)
return;
// Debug.Log($"{gameObject} UpdateAnimator with state: {ghostState}, isScared: {isScared}, direction: {direction}");
if (specialLook)
if (frozenState == PacManGhostFrozenState.FrozenIfNotCaught) // Looks like a bug but matches the original game
{
animator.SetFloat("GhostType", GhostTypeToAnimationValue(PacManGhostType.Special));
}
else if (isScared)
{
float currentGhostType = animator.GetFloat("GhostType");
if (currentGhostType > 0.5f && currentGhostType < 2.5f)
{
return;
}
animator.SetFloat("GhostType", GhostTypeToAnimationValue(PacManGhostType.Scared));
}
else
{
switch (ghostState)
{
default:
case PacManGhostState.Normal:
case PacManGhostState.Home:
case PacManGhostState.Exiting:
// Debug.Log($"{gameObject} Set GhostType in animator to: {GhostTypeToAnimationValue(ghostType)}");
animator.SetFloat("GhostType", GhostTypeToAnimationValue(ghostType));
break;
case PacManGhostState.Returning:
case PacManGhostState.Entering:
animator.SetFloat("GhostType", GhostTypeToAnimationValue(PacManGhostType.Caught));
break;
}
return;
}
if (faceInStartingDirectionUntilUnfrozen && startState == PacManGhostStartState.TargetingIdlePosition1)
if (specialLook || targetDirection != Direction.Zero)
{
animator.SetFloat("DirX", 0);
animator.SetFloat("DirY", 1);
SetAnimatorDirection((int)targetDirection);
}
else if (faceInStartingDirectionUntilUnfrozen && startState == PacManGhostStartState.TargetingIdlePosition2)
PacManGhostType ghostType = this.ghostType;
if (isScared)
{
animator.SetFloat("DirX", 0);
animator.SetFloat("DirY", -1);
ghostType = whiteScared ? PacManGhostType.ScaredWhite : PacManGhostType.Scared;
}
else if (specialLook || !direction.Equals(Vector2.zero))
else if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering)
{
animator.SetFloat("DirX", direction.x);
animator.SetFloat("DirY", direction.y);
ghostType = PacManGhostType.Caught;
}
else if (specialLook)
{
ghostType = PacManGhostType.Special;
}
SetAnimatorGhostType((int)ghostType);
}
private float GhostTypeToAnimationValue(PacManGhostType ghostType)
{
switch (ghostType)
{
default:
Debug.LogError("Invalid ghost animation value!");
return 0;
case PacManGhostType.Caught:
return 0;
case PacManGhostType.Scared:
return 1;
case PacManGhostType.ScaredWhite:
return 2;
case PacManGhostType.Blinky:
return 3;
case PacManGhostType.Pinky:
return 4;
case PacManGhostType.Inky:
return 5;
case PacManGhostType.Clyde:
return 6;
case PacManGhostType.Special:
return 7;
}
}
// A Udon bug means converting an enum to a float causes an exception unless the conversion from int to float is in a separate method
private void SetAnimatorDirection(int value) =>
animator.SetFloat(animatorKeyDirection, value);
private void SetAnimatorGhostType(int value) =>
animator.SetFloat(animatorKeyGhostType, value);
public void UpdateSpeed()
{
@@ -582,6 +600,25 @@ namespace Marro.PacManUdon
}
}
internal bool HitPacMan()
{
if (ghostState != PacManGhostState.Normal)
{
return false;
}
if (isScared)
{
//Debug.Log($"{gameObject} was cought!");
ghostManager.GhostCaught(this);
return true;
}
//Debug.Log($"{gameObject} cought PacMan!");
ghostManager.CapturedPacMan();
return true;
}
public void Caught(int scoreBonus)
{
isScared = false;
@@ -643,13 +680,8 @@ namespace Marro.PacManUdon
private void SetScared(bool scared)
{
isScared = scared;
UpdateAnimator();
SetWhite(false);
UpdateSpeed();
if (isScared)
{
SetWhite(false);
}
}
public void SetScattering(bool scattering, bool reverseDirection = true)
@@ -670,25 +702,32 @@ namespace Marro.PacManUdon
public void SetFrozen(bool frozen, bool ignoreIfCaught = false, bool keepAnimating = false)
{
animator.speed = frozen && !keepAnimating ? 0 : 1; // This would cause issues if the returning sprite was animated, luckily it isn't :)
if (frozen && !ignoreIfCaught)
{
frozenState = PacManGhostFrozenState.Frozen;
return;
}
else if (frozen && ignoreIfCaught)
if (frozen && ignoreIfCaught)
{
frozenState = PacManGhostFrozenState.FrozenIfNotCaught;
return;
}
else
{
frozenState = PacManGhostFrozenState.NotFrozen;
}
animator.speed = frozen && !keepAnimating ? 0 : 1; // This would cause issues if the returning sprite was animated, luckily it isn't :)
if (frozen == false && faceInStartingDirectionUntilUnfrozen)
var oldFrozenState = frozenState;
frozenState = PacManGhostFrozenState.NotFrozen;
if (oldFrozenState == PacManGhostFrozenState.FrozenIfNotCaught) // Catch animator up after not updating during FrozenIfNotCaught
{
faceInStartingDirectionUntilUnfrozen = false;
UpdateAnimator();
}
if (ghostState == PacManGhostState.CaughtScore)
{
ReturnHome(); // Return home when unfreezing after being caught
}
}
public void SetHousePelletCounterActive(bool active)
@@ -703,17 +742,8 @@ namespace Marro.PacManUdon
public void SetWhite(bool white)
{
if (!isScared || !gameObject.activeInHierarchy)
return;
if (white)
{
animator.SetFloat("GhostType", 2);
}
else
{
animator.SetFloat("GhostType", 1);
}
whiteScared = white;
UpdateAnimator();
}
public void SetElroy(int elroyLevel)
@@ -741,7 +771,7 @@ namespace Marro.PacManUdon
this.kinematic = kinematic;
}
public void SetPredefinedPath(Vector2[] predefinedPath)
public void SetPredefinedPath(Direction[] predefinedPath)
{
this.predefinedPath = predefinedPath;
followingPredefinedPath = true;
@@ -778,7 +808,7 @@ namespace Marro.PacManUdon
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.GhostUpdate)
if (eventType != NetworkEventType.FullSync)
{
return;
}
@@ -792,21 +822,22 @@ namespace Marro.PacManUdon
data.AppendAsByte((int)ghostState, ref index);
data.Append(isScared, ref index);
data.Append(whiteScared, ref index);
data.Append(scattering, ref index);
data.AppendAsByte((int)frozenState, ref index);
data.Append(offGrid, ref index);
data.AppendAsByte(housePelletCounter, ref index);
data.Append(housePelletCounterActive, ref index);
data.AppendAsByte(housePelletCounterLimit, ref index);
data.Append(faceInStartingDirectionUntilUnfrozen, ref index);
base.CollectSyncedData(data, ref index, eventType);
data.AppendAsByte((int)frozenState, ref index);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.GhostUpdate)
if (eventType != NetworkEventType.FullSync)
{
return true;
}
@@ -816,58 +847,27 @@ namespace Marro.PacManUdon
inTunnel = data.ReadBool(ref index);
rngState = data.ReadInt(ref index);
turnAroundSoon = data.ReadBool(ref index);
Debug.Log($"{gameObject} turnAroundSoon = {turnAroundSoon}");
speed = data.ReadFloat(ref index);
ghostState = (PacManGhostState)data.ReadByte(ref index);
isScared = data.ReadBool(ref index);
whiteScared = data.ReadBool(ref index);
scattering = data.ReadBool(ref index);
frozenState = (PacManGhostFrozenState)data.ReadByte(ref index);
offGrid = data.ReadBool(ref index);
housePelletCounter = data.ReadByte(ref index);
housePelletCounterActive = data.ReadBool(ref index);
housePelletCounterLimit = data.ReadByte(ref index);
faceInStartingDirectionUntilUnfrozen = data.ReadBool(ref index);
return base.WriteSyncedData(data, ref index, eventType);
}
UpdateSpeed();
void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<PacManGhostCollider>())
{
if (isScared)
{
// Debug.Log($"{gameObject} was cought!");
ghostManager.GhostCaughtQueue(this);
}
else if (ghostState == PacManGhostState.Normal)
{
// Debug.Log($"{gameObject} cought PacMan!");
ghostManager.CapturedPacMan();
}
}
else if (other.gameObject.GetComponent<GhostHorizontalOnlyIndicator>())
{
horizontalOnly = true;
}
else if (other.gameObject.GetComponent<GhostTunnelIndicator>())
{
SetInTunnel(true);
}
}
frozenState = PacManGhostFrozenState.NotFrozen; // Ensure UpdateAnimator runs fully
void OnTriggerExit(Collider other)
{
if (other.gameObject.GetComponent<GhostHorizontalOnlyIndicator>())
{
horizontalOnly = false;
}
else if (other.gameObject.GetComponent<GhostTunnelIndicator>())
{
SetInTunnel(false);
}
var success = base.WriteSyncedData(data, ref index, eventType);
frozenState = (PacManGhostFrozenState)data.ReadByte(ref index);
return success;
}
}
}

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 33
Data: 32
- Name:
Entry: 7
Data:
@@ -283,19 +283,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: $v
Entry: 7
Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 18|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PelletManager, Assembly-CSharp
Data: Marro.PacManUdon.CollisionManager, Assembly-CSharp
- Name:
Entry: 8
Data:
@@ -1081,64 +1081,10 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: ghostScaredQueue
Data: blinkingActivated
- Name: $v
Entry: 7
Data: 54|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: ghostScaredQueue
- Name: <UserType>k__BackingField
Entry: 7
Data: 55|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.SDK3.Data.DataList, VRCSDK3
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 55
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 56|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: blinkingActivated
- Name: $v
Entry: 7
Data: 57|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: blinkingActivated
@@ -1162,7 +1108,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 58|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 55|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1186,7 +1132,7 @@ MonoBehaviour:
Data: blinkCountdown
- Name: $v
Entry: 7
Data: 59|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 56|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: blinkCountdown
@@ -1210,7 +1156,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 60|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 57|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1234,7 +1180,7 @@ MonoBehaviour:
Data: blinkCurrentlyWhite
- Name: $v
Entry: 7
Data: 61|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 58|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: blinkCurrentlyWhite
@@ -1258,7 +1204,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 62|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 59|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1282,7 +1228,7 @@ MonoBehaviour:
Data: scatterCounter
- Name: $v
Entry: 7
Data: 63|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 60|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: scatterCounter
@@ -1306,7 +1252,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 64|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 61|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1330,7 +1276,7 @@ MonoBehaviour:
Data: scatterPatternIndex
- Name: $v
Entry: 7
Data: 65|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 62|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: scatterPatternIndex
@@ -1354,7 +1300,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 66|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 63|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1378,7 +1324,7 @@ MonoBehaviour:
Data: elroyLevel
- Name: $v
Entry: 7
Data: 67|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 64|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: elroyLevel
@@ -1402,7 +1348,7 @@ MonoBehaviour:
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 68|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 65|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1426,7 +1372,7 @@ MonoBehaviour:
Data: sharedPelletCounterActive
- Name: $v
Entry: 7
Data: 69|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 66|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: sharedPelletCounterActive
@@ -1450,7 +1396,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 70|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 67|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1474,7 +1420,7 @@ MonoBehaviour:
Data: sharedPelletCounter
- Name: $v
Entry: 7
Data: 71|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 68|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: sharedPelletCounter
@@ -1496,6 +1442,60 @@ MonoBehaviour:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 69|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: sharedPelletCounterReleaseValues
- Name: $v
Entry: 7
Data: 70|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: sharedPelletCounterReleaseValues
- Name: <UserType>k__BackingField
Entry: 7
Data: 71|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 71
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 72|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
@@ -1519,64 +1519,10 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: sharedPelletCounterReleaseValues
Data: pelletTimeout
- Name: $v
Entry: 7
Data: 73|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: sharedPelletCounterReleaseValues
- Name: <UserType>k__BackingField
Entry: 7
Data: 74|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 74
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 75|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: pelletTimeout
- Name: $v
Entry: 7
Data: 76|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletTimeout
@@ -1600,7 +1546,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 77|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 74|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1624,7 +1570,7 @@ MonoBehaviour:
Data: frozen
- Name: $v
Entry: 7
Data: 78|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 75|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: frozen
@@ -1648,7 +1594,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 79|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 76|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1672,7 +1618,7 @@ MonoBehaviour:
Data: kinematic
- Name: $v
Entry: 7
Data: 80|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 77|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: kinematic
@@ -1696,7 +1642,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 81|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 78|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0

View File

@@ -11,7 +11,7 @@ namespace Marro.PacManUdon
private Ghost[] ghosts;
private Ghost blinky;
private PelletManager pelletManager;
private CollisionManager collisionManager;
// Level constants
private float speedDefault;
@@ -33,8 +33,6 @@ namespace Marro.PacManUdon
private float powerPelletCountdown;
private int powerPelletMultiplier;
private DataList ghostScaredQueue;
// Blink logic
private const float blinkCycleRate = 0.233333333f;
private bool blinkingActivated;
@@ -57,10 +55,10 @@ namespace Marro.PacManUdon
private bool frozen;
private bool kinematic;
public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, PelletManager pelletManager, GameManager gameController)
public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, CollisionManager collisionManager, GameManager gameController)
{
this.gameController = gameController;
this.pelletManager = pelletManager;
this.collisionManager = collisionManager;
ghosts = transform.GetComponentsInChildren<Ghost>(true);
blinky = ghosts[0];
@@ -72,13 +70,12 @@ namespace Marro.PacManUdon
Vector2 idlePosition2 = ghostTargets[2 + ghostIndex * 3].localPosition;
Vector2 cornerPosition = ghostTargets[3 + ghostIndex * 3].localPosition;
ghosts[ghostIndex].Initialize(pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition, ghostIndex);
ghosts[ghostIndex].Initialize(collisionManager, pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition, ghostIndex);
}
}
public void RestartLevel(bool afterLifeLost = false)
{
ghostScaredQueue = new DataList();
powerPelletActive = false;
scatterCounter = 0;
scatterPatternIndex = 0;
@@ -92,18 +89,15 @@ namespace Marro.PacManUdon
SetSharedPelletCounterActive(true);
}
foreach (Ghost ghost in ghosts)
foreach (var ghost in ghosts)
{
ghost.Reset();
}
SetScattering(true, reverseDirection: false);
}
public void NewLevel()
{
SetSharedPelletCounterActive(false);
UpdateElroyLevel();
UpdateElroyLevel(collisionManager.PelletCount);
foreach (Ghost ghost in ghosts)
{
ghost.ResetHousePelletCounter();
@@ -174,7 +168,7 @@ namespace Marro.PacManUdon
for (int ghostIndex = 0; ghostIndex < ghosts.Length; ghostIndex++)
{
Ghost ghost = ghosts[ghostIndex];
var ghost = ghosts[ghostIndex];
if (ghost.GetGhostState() == PacManGhostState.Home)
{
ghost.Release();
@@ -184,7 +178,7 @@ namespace Marro.PacManUdon
}
}
public void GhostCaughtQueue(Ghost ghost)
public void GhostCaught(Ghost ghost)
{
if (gameController.GameState == PacManGameState.AttractMode)
{
@@ -192,33 +186,6 @@ namespace Marro.PacManUdon
return;
}
// Debug.Log($"{gameObject} GhostCaughtQueue with ghost {ghost}");
//networkManager.SendEventSoon(NetworkEventType.GhostUpdate);
ghostScaredQueue.Add(ghost);
GhostCaughtExecute(ghost);
}
public void GhostCaughtContinue()
{
// Debug.Log($"{gameObject} GhostCaughtContinue with ghost queue length {ghostScaredQueue.Count}");
if (!ghostScaredQueue.TryGetValue(0, out DataToken currentGhost))
{
Debug.LogError("Called GhostCaughtContinue without a ghost in the queue!");
return;
}
((Ghost)currentGhost.Reference).ReturnHome();
ghostScaredQueue.RemoveAt(0);
if (ghostScaredQueue.TryGetValue(0, out DataToken nextGhost))
{
GhostCaughtExecute((Ghost)nextGhost.Reference);
}
}
void GhostCaughtExecute(Ghost ghost)
{
int scoreBonus = 200 * (int)Math.Pow(2, powerPelletMultiplier);
powerPelletMultiplier += 1;
ghost.Caught(scoreBonus);
@@ -274,7 +241,7 @@ namespace Marro.PacManUdon
void SetGhostBlinkingState(bool white)
{
blinkCurrentlyWhite = white;
foreach (Ghost ghost in ghosts)
foreach (var ghost in ghosts)
{
ghost.SetWhite(white);
}
@@ -289,7 +256,7 @@ namespace Marro.PacManUdon
powerPelletCountdown = powerPelletDuration;
powerPelletMultiplier = 0;
SetGhostBlinking(false);
foreach (Ghost ghost in ghosts)
foreach (var ghost in ghosts)
{
ghost.BecomeScared();
}
@@ -307,7 +274,7 @@ namespace Marro.PacManUdon
public void SetFrozen(bool frozen, bool ignoreIfCaught = false)
{
this.frozen = frozen;
foreach (Ghost ghost in ghosts)
foreach (var ghost in ghosts)
{
ghost.SetFrozen(frozen, ignoreIfCaught: ignoreIfCaught);
}
@@ -315,14 +282,14 @@ namespace Marro.PacManUdon
public void SetLevel(int level)
{
Debug.Log($"GhostManager: SetLevel {level}");
//Debug.Log($"GhostManager: SetLevel {level}");
SetLevelConstants(level);
int[] privatePelletCounterReleaseValues = PacManConstants.GetGhostHousePrivatePelletCounterLimitForLevel(level);
for (int i = 0; i < ghosts.Length; i++)
{
ghosts[i].SetHousePelletCounterLimit(privatePelletCounterReleaseValues[i]);
RestartLevel(); // Reset needed to properly apply level
ghosts[i].UpdateSpeed();
}
}
@@ -376,8 +343,8 @@ namespace Marro.PacManUdon
void SetScattering(bool scattering, bool reverseDirection = true)
{
Debug.Log($"{gameObject} SetScattering: {scattering}");
foreach (Ghost ghost in ghosts)
//Debug.Log($"{gameObject} SetScattering: {scattering}");
foreach (var ghost in ghosts)
{
if (ghost == blinky && elroyLevel > 0) // Once blinky is elroy he no longer scatters
{
@@ -393,19 +360,19 @@ namespace Marro.PacManUdon
/// </summary>
void SetSharedPelletCounterActive(bool active)
{
Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
//Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
sharedPelletCounterActive = active;
foreach (Ghost ghost in ghosts)
foreach (var ghost in ghosts)
{
ghost.SetHousePelletCounterActive(!active);
}
}
public void PelletConsumed()
public void PelletConsumed(int pelletsRemainingCount)
{
pelletTimeout = 0;
UpdateElroyLevel();
UpdateElroyLevel(pelletsRemainingCount);
if (sharedPelletCounterActive)
{
@@ -423,7 +390,7 @@ namespace Marro.PacManUdon
//Debug.Log($"Incremented shared pellet counter to {sharedPelletCounter}");
for (int ghostIndex = 0; ghostIndex < sharedPelletCounterReleaseValues.Length; ghostIndex++)
{
Ghost ghost = ghosts[ghostIndex];
var ghost = ghosts[ghostIndex];
if (ghost.GetGhostState() == PacManGhostState.Home && sharedPelletCounter == sharedPelletCounterReleaseValues[ghostIndex])
{
ghost.Release();
@@ -440,7 +407,7 @@ namespace Marro.PacManUdon
{
for (int ghostIndex = 0; ghostIndex < ghosts.Length; ghostIndex++)
{
Ghost ghost = ghosts[ghostIndex];
var ghost = ghosts[ghostIndex];
if (ghost.GetGhostState() == PacManGhostState.Home)
{
ghost.IncrementHousePelletCounter();
@@ -449,14 +416,13 @@ namespace Marro.PacManUdon
}
}
void UpdateElroyLevel()
void UpdateElroyLevel(int pelletsRemainingCount)
{
// Debug.Log($"{gameObject} Updating Elroy Level with pelletsRemaining {pelletsRemaining} with elroy2PelletCount {elroy2PelletCount} and elroy1PelletCount {elroy1PelletCount}");
var oldElroyLevel = elroyLevel;
var pelletsRemaining = pelletManager.PelletCount - pelletManager.PelletCollectedCount;
if (pelletsRemaining < elroy2PelletCount) elroyLevel = 2;
else if (pelletsRemaining < elroy1PelletCount) elroyLevel = 1;
if (pelletsRemainingCount < elroy2PelletCount) elroyLevel = 2;
else if (pelletsRemainingCount < elroy1PelletCount) elroyLevel = 1;
else elroyLevel = 0;
if (elroyLevel != oldElroyLevel)
@@ -468,7 +434,7 @@ namespace Marro.PacManUdon
public void SetActive(bool active)
{
gameObject.SetActive(active);
foreach (Ghost ghost in ghosts)
foreach (var ghost in ghosts)
{
ghost.SetActive(active);
}
@@ -477,7 +443,7 @@ namespace Marro.PacManUdon
public void SetKinematic(bool kinematic)
{
this.kinematic = kinematic;
foreach (Ghost ghost in ghosts)
foreach (var ghost in ghosts)
{
ghost.SetKinematic(kinematic);
}
@@ -485,11 +451,6 @@ namespace Marro.PacManUdon
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.GhostUpdate)
{
return;
}
// Power Pellet logic
data.Append(powerPelletActive, ref index);
data.Append(powerPelletCountdown, ref index);
@@ -517,28 +478,14 @@ namespace Marro.PacManUdon
data.AppendAsByte(gameController.Level, ref index);
var ghostScaredQueueArray = new byte[ghosts.Length];
for (int i = 0; i < ghostScaredQueueArray.Length; i++)
foreach (var ghost in ghosts)
{
var add = ghostScaredQueue.TryGetValue(i, out var ghost);
if (!add)
{
ghostScaredQueueArray[i] = byte.MaxValue; // Add a terminator
break;
}
ghostScaredQueueArray[i] = (byte)((Ghost)ghost.Reference).Index;
ghost.CollectSyncedData(data, ref index, eventType);
}
Debug.Log($"{gameObject} Sent a ghostScareQueue of length {ghostScaredQueue.Count}");
data.Append(ghostScaredQueueArray, ref index);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.GhostUpdate)
{
return true;
}
// Power Pellet logic
powerPelletActive = data.ReadBool(ref index);
powerPelletCountdown = data.ReadFloat(ref index);
@@ -567,18 +514,10 @@ namespace Marro.PacManUdon
var level = data.ReadByte(ref index);
SetLevelConstants(level);
ghostScaredQueue.Clear();
for (int i = 0; i < ghosts.Length; i++)
foreach (var ghost in ghosts)
{
var ghostIndex = data[index + i];
if (ghostIndex > ghosts.Length) // Reached terminator
{
break;
}
ghostScaredQueue.Add(ghosts[ghostIndex]);
ghost.WriteSyncedData(data, ref index, eventType);
}
index += ghosts.Length;
Debug.Log($"{gameObject} Read back a ghostScareQueue of length {ghostScaredQueue.Count}");
return true;
}

View File

@@ -3,45 +3,211 @@ namespace Marro.PacManUdon
using System;
using UnityEngine;
public enum Direction
{
Zero = 0, Up = 1, Down = 2, Left = 4, Right = 8, UpLeft = 5, UpRight = 9, DownLeft = 6, DownRight = 10
}
public enum DirectionAxis
{
Horizontal = 0,
Vertical = 1,
Both = 2
}
public abstract class GridMover : SyncedObject
{
protected Vector2 direction;
protected Vector2 position;
protected Direction direction;
protected Direction targetDirection;
// Cannot be static
public readonly Vector2[] directionVectors =
{
Vector2.zero, // 0
Vector2.up, // 1
Vector2.down, // 2
Vector2.zero, // 3
Vector2.left, // 4
Vector2.up + Vector2.left, // 5
Vector2.down + Vector2.left, // 6
Vector2.left, // 7
Vector2.right, // 8
Vector2.up + Vector2.right, // 9
Vector2.down + Vector2.right, // 10
Vector2.right, // 11
Vector2.zero, // 12
Vector2.up, // 13
Vector2.down, // 14
Vector2.zero, // 15
};
public virtual Vector2 GetPosition()
{
return (Vector2)transform.localPosition;
//return (Vector2)transform.localPosition;
return position;
}
public virtual void SetPosition(Vector2 position)
{
this.position = position;
transform.localPosition = new Vector3(position.x, position.y, transform.localPosition.z);
}
public virtual Vector2 GetDirection()
public Direction GetDirection()
{
return direction;
}
public void SetDirection(Vector2 direction)
public Direction GetTargetDirection()
{
return targetDirection;
}
public void SetDirection(Direction direction)
{
this.direction = direction;
UpdateAnimator();
}
protected void SetTargetDirection(Direction targetDirection)
{
this.targetDirection = targetDirection;
UpdateAnimator();
}
public void SetDirectionAndTargetDirection(Direction direction)
{
this.direction = direction;
this.targetDirection = direction;
UpdateAnimator();
}
protected static Direction HorizontalToDirection(float horizontal)
{
if (horizontal < 0)
{
return Direction.Left;
}
if (horizontal > 0)
{
return Direction.Right;
}
return Direction.Zero;
}
protected static Direction VerticalToDirection(float vertical)
{
if (vertical < 0)
{
return Direction.Down;
}
if (vertical > 0)
{
return Direction.Up;
}
return Direction.Zero;
}
protected abstract void UpdateAnimator();
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
data.Append(GetPosition(), ref index);
data.Append(GetDirection(), ref index);
data.AppendAsByte((int)direction, ref index);
data.AppendAsByte((int)targetDirection, ref index);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
SetPosition(data.ReadVector2(ref index));
SetDirection(data.ReadVector2(ref index));
direction = (Direction)data.ReadByte(ref index);
targetDirection = (Direction)data.ReadByte(ref index);
UpdateAnimator();
return true;
}
public void PadSyncedData(ref int index)
{
index += 10;
}
#region Utils
public static Direction GetInverseDirection(Direction direction)
{
switch (direction)
{
case Direction.Up:
return Direction.Down;
case Direction.Down:
return Direction.Up;
case Direction.Left:
return Direction.Right;
case Direction.Right:
return Direction.Left;
case Direction.UpLeft:
return Direction.DownRight;
case Direction.UpRight:
return Direction.DownLeft;
case Direction.DownLeft:
return Direction.UpRight;
case Direction.DownRight:
return Direction.UpLeft;
default:
return Direction.Zero;
}
}
public static bool IsVertical(Direction direction) => ((int)direction & 0b0011) != 0;
public static bool IsHorizontal(Direction direction) => ((int)direction & 0b1100) != 0;
public static Direction VerticalComponent(Direction direction) => (Direction)((int)direction & 0b0011);
public static Direction HorizontalComponent(Direction direction) => (Direction)((int)direction & 0b1100);
public static Vector2 GetNextPosition(Vector2 currentPosition, Vector2 directionVector, float speed, float deltaTime)
{
var nextPosition = currentPosition + deltaTime * speed * directionVector;
nextPosition = new Vector2((nextPosition.x + 32) % 32, (nextPosition.y + 32) % 32);
return nextPosition;
}
public static Vector2 PositionToGrid(Vector2 position)
{
return new Vector2((int)position.x + 0.5f, (int)position.y + 0.5f);
}
public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, Direction direction)
{
bool result = false;
if (IsHorizontal(direction))
{
result = Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x);
}
if (!result && IsVertical(direction))
{
result = Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y);
}
return result;
}
public static bool CrossesTileCenter(Vector2 currentPosition, Vector2 nextPosition, Direction direction)
{
bool result = false;
if (IsHorizontal(direction))
{
result = Math.Round(currentPosition.x) != Math.Round(nextPosition.x);
}
if (!result && IsVertical(direction))
{
result = Math.Round(currentPosition.y) != Math.Round(nextPosition.y);
}
return result;
}
#endregion
}
}

View File

@@ -1,64 +0,0 @@
namespace Marro.PacManUdon
{
using System;
using UnityEngine;
public static class GridMoverTools
{
public static Vector2 GetNextPosition(Vector2 currentPosition, Vector2 direction, float speed, float deltaTime)
{
return currentPosition + direction * speed * deltaTime;
}
public static Vector2 PositionToGrid(Vector2 position)
{
return new Vector2((float)Math.Round(position.x), (float)Math.Round(position.y));
}
public static bool CrossesTileCenter(Vector2 currentPosition, Vector2 nextPosition, bool horizontal, bool vertical)
{
bool result = false;
if (horizontal)
{
result = result || Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x);
}
if (vertical)
{
result = result || Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y);
}
// Debug.Log($"CrossesTileCenter at currentPosition {currentPosition} with nextPosition {nextPosition}, horizontal {horizontal} and vertical {vertical} gives {result}");
return result;
}
public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, bool horizontal, bool vertical)
{
bool result = false;
if (horizontal)
{
result = result || nextPosition.x != currentPosition.x
&& ((Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x) && nextPosition.x % 1 != 0)
|| currentPosition.x % 1 == 0);
}
if (vertical)
{
result = result || nextPosition.y != currentPosition.y
&& ((Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y) && nextPosition.y % 1 != 0)
|| currentPosition.y % 1 == 0);
}
return result;
}
public static bool CheckCollisionInDirection(Transform transform, Vector2 position, Vector2 direction)
{
// Debug.Log("Collision check");
bool result = Physics.Linecast(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), 1 << 22, QueryTriggerInteraction.Ignore);
// Debug.DrawLine(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), Color.red, 1);
// Debug.Log($"{gameObject} Collision; Position {position} became {transform.parent.TransformPoint(position)}, direction {direction.normalized} became {transform.parent.TransformDirection(direction.normalized)}");
// Debug.Log("collision check for " + position + " in direction " + direction + " returned " + result);
return result;
}
}
}

View File

@@ -47,7 +47,7 @@ namespace Marro.PacManUdon
public void SetActive(bool isActive)
{
Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) SetActive {isActive}.");
//Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) SetActive {isActive}.");
gameObject.SetActive(isActive);
}
@@ -115,7 +115,7 @@ namespace Marro.PacManUdon
public void SetStrechLevel(PoleStrechLevels level)
{
Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) Set strech level to {level}.");
//Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) Set strech level to {level}.");
_animator.SetFloat("Strech", GetAnimatorValueForStrechLevel(level));
}
@@ -143,15 +143,5 @@ namespace Marro.PacManUdon
{
return (Vector2)transform.localPosition;
}
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
return true;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,6 @@
using System;
using Newtonsoft.Json.Linq;
using System;
using System.Numerics;
using System.Text;
using TMPro;
using UdonSharp;
@@ -13,13 +15,14 @@ namespace Marro.PacManUdon
{
FullSyncForced = 0,
FullSync = 1,
PacManTurn = 2,
InputChange = 2,
StartGameButtonPressed = 3,
SyncPellets = 4,
GhostUpdate = 5,
Pause = 7,
Resume = 8,
Step = 9,
}
public class NetworkManager : UdonSharpBehaviour
public class NetworkManager : SyncedObject
{
// The network manager works by serializing event and state data into a byte array, including a timestamp for each event.
// If user is owner, this data is created and stored in a buffer which is cleared upon transmission.
@@ -48,9 +51,9 @@ namespace Marro.PacManUdon
/// </summary>
[SerializeField] private GameObject root;
/// <summary>
/// The delay at which the receiving side replays events.
/// The delay in ticks at which the receiving side replays events.
/// </summary>
[SerializeField] private float delay = 1f;
[SerializeField] private int delay = 50;
/// <summary>
/// The maximum amount of times a message is sent.
/// </summary>
@@ -58,11 +61,11 @@ namespace Marro.PacManUdon
/// <summary>
/// How long to wait since last message to send next ping.
/// </summary>
[SerializeField] private float pingDelay = 0.3f;
[SerializeField] private int pingDelay = 15;
/// <summary>
/// The rate at which updates occur.
/// The time delta at which updates occur.
/// </summary>
[SerializeField] private float updateRate = 0.0166666667f;
[SerializeField] private float tickDelta = 0.0165f;
#endregion
#region Constants
@@ -99,27 +102,49 @@ namespace Marro.PacManUdon
#region Private attributes
/// <summary>
/// Objects which are controlled by this <see cref="NetworkManager"/>.
/// Whether <see cref="Initialize"/> has been called successfully.
/// </summary>
private SyncedObject[] syncedObjects;
private bool initialized = false;
/// <summary>
/// Offset from system time to network time, including delay.
/// Subscribers to each <see cref="NetworkEventType"/>.
/// </summary>
private float offsetTime;
/// <summary>
/// Time since last full sync, captured when this FixedUpdate started, with network delay applied.
/// </summary>
private float internalTime;
private SyncedObject[][] networkEventSubscribers;
/// <summary>
/// Time at which the latest update occured
/// Indices for <see cref="networkEventSubscribers"/>.
/// </summary>
private float nextUpdateTime;
private int[] networkEventSubscribersIndices;
/// <summary>
/// Time at which next received event occured.
/// Subscribers for <see cref="SyncedObject.SyncedUpdate"/>.
/// </summary>
private float nextEventTime;
private SyncedObject[] syncedUpdateSubscribers;
/// <summary>
/// The <see cref="Time.fixedTime"/> that corresponds to tick 0.
/// </summary>
private float startTime;
/// <summary>
/// Time in ticks since start of game.
/// </summary>
private int targetTicks;
/// <summary>
/// True if time is paused
/// </summary>
private bool paused;
/// <summary>
/// True if a step should happen next update
/// </summary>
private bool stepNext;
/// <summary>
/// Time at which next received event occured, in ticks.
/// </summary>
private int nextEventTime;
/// <summary>
/// Amounot of retries in a row without a successful sync.
@@ -137,13 +162,21 @@ namespace Marro.PacManUdon
private bool serializationRequested;
/// <summary>
/// Events to send at the end of SyncedUpdate cycle
/// Events to send at the end of SyncedUpdate cycle.
/// </summary>
private NetworkEventType[] eventsToSend;
private NetworkEventType[] eventsToSendEarly;
/// <summary>
/// Index for <see cref="eventsToSend"/>
/// Index for <see cref="eventsToSendEarly"/>.
/// </summary>
private int eventsToSendIndex;
private int eventsToSendEarlyIndex;
/// <summary>
/// Events to send at the end of SyncedUpdate cycle, delayed by a tick.
/// </summary>
private NetworkEventType[] eventsToSendLate;
/// <summary>
/// Index for <see cref="eventsToSendLate"/>.
/// </summary>
private int eventsToSendLateIndex;
/// <summary>
/// Queue of events to be transmitted or processed.
@@ -167,9 +200,9 @@ namespace Marro.PacManUdon
/// </summary>
private int eventTransmissionHistoryIndex;
/// <summary>
/// Time of last event transmission.
/// Time of last event transmission, in ticks.
/// </summary>
private float lastEventTransmissionTime;
private int lastEventTransmissionTime;
/// <summary>
@@ -185,26 +218,55 @@ namespace Marro.PacManUdon
#endregion
#region Public fields
private bool ready = false;
/// <summary>
/// Whether this <see cref="NetworkManager"/> is ready to transmit or receive data.
/// If false, networking is disabled and this <see cref="NetworkManager"/> acts as a pass-through.
/// </summary>
public bool Ready { get; private set; } = false;
public bool Ready
{
get => ready;
private set
{
ready = value;
if (DebugImageToIndicateReady != null)
{
DebugImageToIndicateReady.SetFloat("Color", value ? 1 : 0);
}
}
}
/// <summary>
/// Whether the current perspective is synced with the owner. (Always true if current perspective is owner.)
/// </summary>
public bool Synced { get; private set; } = false;
public bool Synced
{
get => synced;
private set
{
synced = value;
if (DebugImageToIndicateSynced != null)
{
DebugImageToIndicateSynced.SetFloat("Color", value ? 1 : 0);
}
}
}
private bool synced = false;
/// <summary>
/// The time since last full sync which is currently being simulated.
/// The time since start of game, in ticks.
/// </summary>
public int SyncedTimeTicks { get; private set; }
/// <summary>
/// The time since start of game which is currently being simulated.
/// </summary>
public float SyncedTime { get; private set; }
/// <summary>
/// Time since the last simulation, in seconds.
/// </summary>
public float SyncedDeltaTime { get; private set; }
public float SyncedDeltaTime => tickDelta;
/// <summary>
/// Is the current simulation to prepare for applying a network event?
@@ -216,16 +278,36 @@ namespace Marro.PacManUdon
/// <summary>
/// Is the local user owner?
/// </summary>
public bool IsOwner { get; private set; }
public bool IsOwner
{
get => isOwner;
private set
{
isOwner = value;
if (DebugImageToIndicateOwner != null)
{
DebugImageToIndicateOwner.SetFloat("Color", value ? 1 : 0);
}
}
}
private bool isOwner = false;
#endregion
#region General
/// <summary>
/// Initializes the <see cref="NetworkManager"/>. Call <see cref="Reset"/> afterwards to activate networking.
/// </summary>
public void Initialize()
{
if (initialized)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Tried to call {nameof(Initialize)} when already initialized!");
return;
}
if (!BitConverter.IsLittleEndian)
{
Debug.LogError($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Fatal: NetworkManager only supports little endian! Network sync will not be possible.");
Ready = false;
return;
}
@@ -234,15 +316,46 @@ namespace Marro.PacManUdon
root = transform.parent.gameObject;
}
syncedObjects = root.GetComponentsInChildren<SyncedObject>(includeInactive: true);
foreach (var obj in syncedObjects)
InitializeSubscribers();
initialized = true;
Reset();
}
private void InitializeSubscribers()
{
syncedUpdateSubscribers = root.GetComponentsInChildren<SyncedObject>(includeInactive: true);
foreach (var obj in syncedUpdateSubscribers)
{
obj.networkManager = this;
}
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Found {syncedObjects.Length} {nameof(SyncedObject)} in children of {root.name}.");
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Found {syncedUpdateSubscribers.Length} {nameof(SyncedObject)} in children of {root.name}.");
SetOwner(Networking.IsOwner(gameObject));
const int eventTypeCount = byte.MaxValue + 1;
networkEventSubscribers = new SyncedObject[eventTypeCount][];
networkEventSubscribersIndices = new int[eventTypeCount];
}
public void Reset()
{
if (!initialized)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Tried to call {nameof(Reset)} while not initialized. Call {nameof(Initialize)} first.");
return;
}
if (tester == null)
{
IsOwner = Networking.IsOwner(gameObject);
}
else
{
IsOwner = tester.ShouldBeOwner(this);
}
ClearBuffer();
@@ -250,32 +363,50 @@ namespace Marro.PacManUdon
retriesWithoutSuccess = 0;
hasFullSyncReady = false;
offsetTime = Time.fixedTime;
internalTime = 0;
targetTicks = 0;
startTime = Time.fixedTime;
SyncedTime = 0;
SyncedDeltaTime = Time.fixedDeltaTime;
nextUpdateTime = SyncedTime;
if (!Synced)
{
RequestEvent(NetworkEventType.FullSync); // See if we can sync up
}
SyncedTimeTicks = 0;
Ready = true;
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Initialized, time offset: {offsetTime}");
// Sync up
if (IsOwner)
{
SendEventSoon(NetworkEventType.FullSyncForced);
}
else
{
RequestEvent(NetworkEventType.FullSync);
}
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Initialized");
}
public void Update()
{
if (!Ready)
if (debugOutput != null)
{
WriteDebugOutput(debugOutput);
}
if (!initialized)
{
return;
}
// Fetch the current time
// Get our target time
UpdateInternalTime();
// Forwards simulated time by updateDelta until we're caught up
while (SyncedTimeTicks <= targetTicks)
{
PerformFixedSyncedUpdate();
}
}
private void PerformFixedSyncedUpdate()
{
if (Ready)
{
if (IsOwner)
@@ -283,33 +414,23 @@ namespace Marro.PacManUdon
ProcessEventsToSend(); // Prepare events from last cycle
ProgressPingTime(); // See if we need to send a ping
}
else
if (!isOwner)
{
ApplyReceivedEvents(); // See if there's events that need to be replayed
ApplyReceivedEvents(); // See if there's events after last update that need to be replayed
}
}
// Forwards simulated time at the updateRate pace
while (nextUpdateTime <= internalTime)
{
ProgressSyncedTime(nextUpdateTime);
PerformFixedSyncedUpdate();
nextUpdateTime = SyncedTime + updateRate;
}
ProgressSyncedTime();
CallSyncedUpdate();
}
private void UpdateInternalTime()
{
internalTime = Time.fixedTime - offsetTime;
}
private void PerformFixedSyncedUpdate()
private void CallSyncedUpdate()
{
IsEventUpdate = false;
for (int i = 0; i < syncedObjects.Length; i++)
for (int i = 0; i < syncedUpdateSubscribers.Length; i++)
{
var obj = syncedObjects[i];
var obj = syncedUpdateSubscribers[i];
if (obj.gameObject.activeInHierarchy)
{
@@ -348,19 +469,35 @@ namespace Marro.PacManUdon
}
}
private void SetOwner(bool isOwner)
{
IsOwner = isOwner;
private SyncedObject[] GetEventSubscribers(NetworkEventType eventType) => networkEventSubscribers[(int)eventType];
if (DebugImageToIndicateOwner != null)
public void SubscribeToEvent(SyncedObject syncedObject, NetworkEventType eventType)
{
// This is inefficient, but I'd rather initialize slowly than perform bounds checks in often called code
var eventTypeIndex = (int)eventType;
var subscribers = networkEventSubscribers[eventTypeIndex];
int subscribersIndex = networkEventSubscribersIndices[eventTypeIndex];
if (subscribers == null)
{
DebugImageToIndicateOwner.SetFloat("Color", isOwner ? 1 : 0);
subscribers = new SyncedObject[1];
}
else
{
subscribers = new SyncedObject[subscribersIndex+1];
Array.Copy(networkEventSubscribers[eventTypeIndex], subscribers, subscribersIndex);
}
subscribers[subscribersIndex] = syncedObject;
networkEventSubscribers[eventTypeIndex] = subscribers;
networkEventSubscribersIndices[eventTypeIndex] = subscribersIndex;
}
#endregion
#region Sender
public void SendEventSoon(NetworkEventType eventType)
public void SendEventSoon(NetworkEventType eventType, bool early = false)
{
if (!Ready)
{
@@ -369,31 +506,52 @@ namespace Marro.PacManUdon
if (!IsOwner)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Attempted {nameof(SendEventSoon)} while not the owner!");
//Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Attempted {nameof(SendEventSoon)} while not the owner!");
return;
}
if (eventsQueueIndex > eventsToSend.Length)
if (early)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) {nameof(eventsToSend)} overflow!");
HandleError(false);
return;
}
if (eventsToSendEarlyIndex >= eventsToSendEarly.Length)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) {nameof(eventsToSendEarly)} overflow!");
HandleError(false);
return;
}
eventsToSend[eventsToSendIndex++] = eventType;
eventsToSendEarly[eventsToSendEarlyIndex++] = eventType;
}
else
{
if (eventsToSendLateIndex >= eventsToSendLate.Length)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) {nameof(eventsToSendLate)} overflow!");
HandleError(false);
return;
}
eventsToSendLate[eventsToSendLateIndex++] = eventType;
}
}
private void ProcessEventsToSend()
{
for (int i = 0; i < eventsToSendIndex; i++)
for (int i = 0; i < eventsToSendEarlyIndex; i++)
{
SendEventNow(eventsToSend[0]);
SendEventNow(eventsToSendEarly[i], true);
}
eventsToSendIndex = 0;
eventsToSendEarlyIndex = 0;
for (int i = 0; i < eventsToSendLateIndex; i++)
{
SendEventNow(eventsToSendLate[i], false);
}
eventsToSendLateIndex = 0;
}
public void SendEventNow(NetworkEventType eventType)
public void SendEventNow(NetworkEventType eventType, bool early)
{
if (!Ready)
{
@@ -406,15 +564,27 @@ namespace Marro.PacManUdon
return;
}
var timestamp = SyncedTime;
var timestamp = SyncedTimeTicks;
if (early)
{
timestamp--;
}
var eventId = GetNextEventId(lastEventId);
InitializeEvent(eventType, timestamp, eventId, out byte[] data, out var index);
foreach (var obj in syncedObjects)
var effectiveEventType = eventType == NetworkEventType.FullSyncForced ? NetworkEventType.FullSync : eventType;
var subscibers = GetEventSubscribers(effectiveEventType);
if (subscibers != null)
{
obj.CollectSyncedData(data, ref index, eventType);
foreach (var obj in subscibers)
{
obj.CollectSyncedData(data, ref index, effectiveEventType);
}
}
// Validate and fill in event size
@@ -430,7 +600,7 @@ namespace Marro.PacManUdon
QueueEventInBuffer(data);
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Prepared event of type {eventType} with {data.Length} bytes, timestamp {timestamp} and id {eventId} for serialization.");
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Prepared event of type {eventType} with {data.Length} bytes, timestamp {timestamp} and id {eventId} for serialization.");
RequestSerializationForEvents();
@@ -439,7 +609,7 @@ namespace Marro.PacManUdon
retriesWithoutSuccess = 0; // We had success!
}
private static void InitializeEvent(NetworkEventType eventType, float timestamp, byte eventId, out byte[] data, out int index)
private static void InitializeEvent(NetworkEventType eventType, int timestamp, byte eventId, out byte[] data, out int index)
{
data = new byte[MaxEventSize];
@@ -455,6 +625,10 @@ namespace Marro.PacManUdon
{
RequestSerialization();
serializationRequested = true;
if (tester != null)
{
tester.RequestSerializationTest();
}
}
[NetworkCallable]
@@ -481,8 +655,8 @@ namespace Marro.PacManUdon
private void ProgressPingTime()
{
if (eventsQueueIndex > 0
&& internalTime - lastEventTransmissionTime >= pingDelay)
if (eventsQueueIndex > 0 && !serializationRequested
&& targetTicks - lastEventTransmissionTime >= pingDelay)
{
RequestSerializationForEvents();
}
@@ -506,23 +680,26 @@ namespace Marro.PacManUdon
serializationRequested = false;
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Serializing {eventsQueueIndex} event(s), eventTransmissionHistory is now {ArrayToString(eventTransmissionHistory)} with index {eventTransmissionHistoryIndex}");
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Serializing {eventsQueueIndex} event(s), eventTransmissionHistory is now {ArrayToString(eventTransmissionHistory)} with index {eventTransmissionHistoryIndex}");
}
public override void OnPostSerialization(SerializationResult result)
public override void OnPostSerialization(SerializationResult result) => OnPostSerializationInternal(result.success, result.byteCount);
// Version of OnPostSerialization which does not require instantiating SerializationResult, so that it can be called for debugging purposes.
public void OnPostSerializationInternal(bool success, int byteCount)
{
if (!Ready || !IsOwner || networkedData.Length == 0)
{
return;
}
if (!result.success)
if (!success)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Serialization failed! Tried to send {result.byteCount} bytes.");
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Serialization failed! Tried to send {byteCount} bytes.");
return;
}
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Serialized with {networkedData.Length} bytes.\nBytes sent:\n{ArrayToString(networkedData)}");
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Serialized with {networkedData.Length} bytes.\nBytes sent:\n{ArrayToString(networkedData)}");
// Remove data from the buffer that no longer needs to be (re)transmitted
DequeueEventsFromBuffer(eventTransmissionHistory[eventTransmissionHistoryIndex]);
@@ -534,7 +711,7 @@ namespace Marro.PacManUdon
// If there was a full sync in the queue, it has now been transmitted at least once
hasFullSyncReady = false;
lastEventTransmissionTime = internalTime;
lastEventTransmissionTime = targetTicks;
}
#endregion
@@ -553,6 +730,11 @@ namespace Marro.PacManUdon
}
SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.Owner, "RequestEventReceived", eventType);
if (tester != null)
{
tester.RequestEvent(eventType);
}
}
private void StoreIncomingData()
@@ -562,7 +744,7 @@ namespace Marro.PacManUdon
return; // Nothing to store
}
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Received {networkedData.Length} bytes!\nBytes received:\n{ArrayToString(networkedData)}");
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Received {networkedData.Length} bytes!\nBytes received:\n{ArrayToString(networkedData)}");
var length = networkedData.Length;
int index = 0;
@@ -618,7 +800,7 @@ namespace Marro.PacManUdon
QueueEventInBuffer(@event);
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)} Queued event with id {eventId}");
//Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)} Queued event with id {eventId}");
}
else
{
@@ -645,18 +827,18 @@ namespace Marro.PacManUdon
QueueEventInBuffer(@event);
// Set this event to play after the default delay
nextEventTime = internalTime + delay;
nextEventTime = targetTicks + delay;
hasFullSyncReady = true;
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Queued full sync in buffer, should execute at {nextEventTime}.");
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Queued full sync in buffer, should execute at {nextEventTime}.");
}
private void ApplyReceivedEvents()
{
IsEventUpdate = true;
while (eventsQueueIndex > 0 && nextEventTime <= internalTime)
while (eventsQueueIndex > 0 && nextEventTime <= SyncedTimeTicks)
{
var success = ApplyEvent(eventsQueue[0]);
@@ -681,25 +863,37 @@ namespace Marro.PacManUdon
{
SyncToTimestamp(timestamp);
}
else if (timestamp < SyncedTimeTicks)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Next received event is in the past! " +
$"{nameof(nextEventTime)}: {nextEventTime} < {nameof(SyncedTimeTicks)}: {SyncedTimeTicks}.");
HandleError(true);
return false;
}
if (eventType == NetworkEventType.FullSyncForced)
{
eventType = NetworkEventType.FullSync;
}
var index = (int)HeaderLength; // Skip header
ProgressSyncedTime(timestamp);
var subscribers = GetEventSubscribers(eventType);
foreach (var obj in syncedObjects)
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) ApplyEvent with dt {SyncedDeltaTime}");
if (subscribers != null)
{
obj.SyncedUpdate();
}
foreach (var obj in syncedObjects)
{
var success = obj.WriteSyncedData(@event, ref index, eventType);
if (!success)
foreach (var obj in subscribers)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Malformed data reported by {obj.name} during event type {eventType}!");
HandleError(true);
return false;
var success = obj.WriteSyncedData(@event, ref index, eventType);
if (!success)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Malformed data reported by {obj.name} during event type {eventType}!");
HandleError(true);
return false;
}
}
}
@@ -717,7 +911,7 @@ namespace Marro.PacManUdon
Synced = true;
}
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Performed incoming eventof type {eventType}! Total {index} bytes.");
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Performed incoming event of type {eventType}! Total {index} bytes.");
retriesWithoutSuccess = 0; // We had success!
@@ -746,8 +940,11 @@ namespace Marro.PacManUdon
eventTransmissionHistory = new int[maxEventSendTries];
eventTransmissionHistoryIndex = 0;
eventsQueueIndexAtLastTransmission = 0;
eventsToSend = new NetworkEventType[BufferMaxTotalEvents];
eventsToSendIndex = 0;
eventsToSendEarly = new NetworkEventType[BufferMaxTotalEvents];
eventsToSendEarlyIndex = 0;
eventsToSendLate = new NetworkEventType[BufferMaxTotalEvents];
eventsToSendLateIndex = 0;
}
private void DequeueEventsFromBuffer(int eventCount)
@@ -778,30 +975,38 @@ namespace Marro.PacManUdon
#endregion
#region Time
private void ProgressSyncedTime(float newTime)
private void UpdateInternalTime()
{
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) updating SyncedTime from {SyncedTime} to {newTime}");
SyncedDeltaTime = newTime - SyncedTime;
if (SyncedDeltaTime < 0)
if (paused && !stepNext)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Negative Dt: {SyncedDeltaTime}! Going from {SyncedTime} to {newTime}, IsEventUpdate: {IsEventUpdate}");
return;
}
SyncedTime = newTime;
if (paused && stepNext)
{
targetTicks++;
stepNext = false;
return;
}
targetTicks = (int)((Time.fixedTime - startTime) / tickDelta);
}
private void SyncToTimestamp(float timestamp)
private void ProgressSyncedTime()
{
var oldOffset = offsetTime;
offsetTime = Time.fixedTime - timestamp;
SyncedTimeTicks++;
SyncedTime = SyncedTimeTicks * tickDelta;
}
var delta = offsetTime - oldOffset;
internalTime -= delta;
SyncedTime -= delta;
nextEventTime -= delta;
private void SyncToTimestamp(int timestamp)
{
startTime = Time.fixedTime - timestamp * tickDelta;
targetTicks = timestamp;
SyncedTimeTicks = timestamp;
SyncedTime = SyncedTimeTicks * tickDelta;
nextEventTime = timestamp;
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Synced to timestamp {timestamp}, current time is {Time.fixedTime}, offsetTime is now {offsetTime}, internalTime is now {internalTime}, SyncedTime is now {SyncedTime}, nextEventTime is now {nextEventTime}");
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Synced to timestamp {timestamp}, internalTime is now {targetTicks}, SyncedTime is now {SyncedTime}, nextEventTime is now {nextEventTime}");
}
private void UpdateNextEventTime()
@@ -819,10 +1024,10 @@ namespace Marro.PacManUdon
HandleError(true);
return;
}
if (nextEventTime < SyncedTime)
if (nextEventTime < SyncedTimeTicks)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) New event timestamp is earlier than our current synced time by {SyncedTime - nextEventTime} seconds! nextEventTime: {nextEventTime} SyncedTime: {SyncedTime}, internalTime: {internalTime}");
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) New event timestamp is earlier than our current synced time by {SyncedTime - nextEventTime} seconds! nextEventTime: {nextEventTime} SyncedTime: {SyncedTime}, internalTime: {targetTicks}");
HandleError(true);
return;
}
@@ -853,8 +1058,8 @@ namespace Marro.PacManUdon
private static NetworkEventType GetEventTypeFromHeader(byte[] @event, int eventIndex = 0) =>
(NetworkEventType)@event[eventIndex + HeaderEventTypeIndex];
private static float GetTimestampFromHeader(byte[] @event, int eventIndex = 0) =>
BitConverter.ToSingle(@event, eventIndex + HeaderTimestampIndex);
private static int GetTimestampFromHeader(byte[] @event, int eventIndex = 0) =>
BitConverter.ToInt32(@event, eventIndex + HeaderTimestampIndex);
private static byte GetEventIdFromHeader(byte[] @event, int eventIndex = 0) =>
@event[eventIndex + HeaderEventIdIndex];
@@ -869,7 +1074,7 @@ namespace Marro.PacManUdon
}
bool newOwnerIsLocalPlayer = newOwner == Networking.LocalPlayer;
SetOwner(newOwnerIsLocalPlayer);
IsOwner = newOwnerIsLocalPlayer;
if (newOwnerIsLocalPlayer)
{
@@ -936,23 +1141,48 @@ namespace Marro.PacManUdon
}
#endregion
#region SyncedData
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
// Nothing
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
switch (eventType)
{
case NetworkEventType.Pause:
Pause();
break;
case NetworkEventType.Resume:
Resume();
break;
case NetworkEventType.Step:
Step();
break;
}
return true;
}
#endregion
#region Debug
public void SimulateSyncToTimestamp(float timestamp)
{
SyncToTimestamp(timestamp);
//SyncToTimestamp(timestamp);
}
public void WriteDebugOutput(TMP_InputField debugOutput)
{
debugOutput.text += $"{nameof(NetworkManager)}:\n" +
debugOutput.text = $"{nameof(NetworkManager)}:\n" +
$"IsOwner: {IsOwner}\n" +
$"Ready: {Ready}\n" +
$"Synced: {Synced}\n" +
$"hasFullSyncReady: {hasFullSyncReady}\n" +
$"lastEventId: {lastEventId}" +
$"lastEventId: {lastEventId}\n" +
$"Time.fixedTime: {Time.fixedTime}\n" +
$"offsetTime: {offsetTime}\n" +
$"internalTime: {internalTime}\n" +
$"startTime: {startTime}\n" +
$"targetTicks: {targetTicks}\n" +
$"SyncedTime: {SyncedTime}\n" +
$"Dt: {SyncedDeltaTime}\n" +
$"BufferIndex: {eventsQueueIndex}\n" +
@@ -960,24 +1190,81 @@ namespace Marro.PacManUdon
$"\n";
}
/// <summary>
/// Text field to display debug info in.
/// </summary>
[SerializeField] private TMP_InputField debugOutput;
/// <summary>
/// An animator which visualizes whether the current perspective is the owner.
/// </summary>
[SerializeField] private Animator DebugImageToIndicateOwner;
/// <summary>
/// An animator which visualizes whether the NetworkManager is synced.
/// </summary>
[SerializeField] private Animator DebugImageToIndicateSynced;
/// <summary>
/// An animator which visualizes whether the NetworkManager is synced.
/// </summary>
[SerializeField] private Animator DebugImageToIndicateReady;
private NetworkManagerTester tester;
public void SetNetworkManagerTester(NetworkManagerTester tester)
{
this.tester = tester;
}
public byte[] NetworkedData
{
get => networkedData;
set => networkedData = value;
}
public bool SerializationRequested => serializationRequested;
public void SetIsOwner(bool isOwner) => IsOwner = isOwner;
public void DoFullSync()
{
SendEventSoon(NetworkEventType.FullSync);
SendEventSoon(NetworkEventType.FullSyncForced);
}
public void DoPelletSync()
public void Pause()
{
SendEventSoon(NetworkEventType.SyncPellets);
paused = true;
stepNext = false;
}
public void DoGhostSync()
private void Resume()
{
SendEventSoon(NetworkEventType.GhostUpdate);
paused = false;
stepNext = false;
}
private void Step()
{
paused = true;
stepNext = true;
}
public void PauseButtonPressed()
{
Pause();
SendEventSoon(NetworkEventType.Pause);
}
public void ResumeButtonPressed()
{
Resume();
SendEventSoon(NetworkEventType.Resume);
}
public void StepButtonPressed()
{
Step();
SendEventSoon(NetworkEventType.Step);
}
#endregion
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,70 +1,75 @@
using System;
using UnityEngine;
using UnityEngine;
namespace Marro.PacManUdon
{
enum PacManAnimatorState
{
Idle,
Moving,
Stopped,
Big,
Dead,
}
enum PacManState
{
Idle,
Normal,
PowerPellet,
Dead,
Big,
}
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(Renderer))]
public class PacMan : GridMover
{
private GameManager gameController;
private PlayerInput input;
private CollisionManager collisionManager;
private Animator animator;
private new Renderer renderer;
private Vector2 startPosition;
private float defaultSpeed;
private float powerPelletSpeed;
private PacManState state;
private float speed;
private Vector3 startPosition;
private Quaternion startRotation;
private Animator animator;
new Renderer renderer;
private bool hideUntilUnfrozen;
private bool dead;
private bool kinematic;
private bool followingPredefinedPath;
private Vector2[] predefinedPath;
private int predefinedPathIndex;
private Vector2 targetDirection;
private float freezeSeconds;
private bool frozen;
#region Animator constants
private const string AnimatorKeyDead = "Dead";
private const string AnimatorKeyDirection = "Direction";
private const float AnimatorDirectionNone = 0f;
private const float AnimatorDirectionRight = 0.25f;
private const float AnimatorDirectionLeft = 0.50f;
private const float AnimatorDirectionUp = 0.75f;
private const float AnimatorDirectionDown = 1f;
private const float AnimatorDirectionRightBig = 1.25f;
#endregion
private bool kinematic;
private bool followingPredefinedPath;
private Direction[] predefinedPath;
private int predefinedPathIndex;
public void Initialize(PlayerInput input, Transform startTransform, GameManager gameController)
private readonly int animatorKeyState = Animator.StringToHash("State");
private readonly int animatorKeyDirection = Animator.StringToHash("Direction");
public void Initialize(PlayerInput input, Transform startTransform, GameManager gameManager, CollisionManager collisionManager)
{
this.gameController = gameController;
this.collisionManager = collisionManager;
this.input = input;
animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>();
frozen = false;
hideUntilUnfrozen = false;
startPosition = startTransform.localPosition;
startRotation = startTransform.localRotation;
}
public void Reset()
{
transform.SetLocalPositionAndRotation(startPosition, startRotation);
direction = Vector2.left;
targetDirection = Vector2.left;
speed = defaultSpeed;
SetPosition(startPosition);
direction = Direction.Left;
targetDirection = Direction.Left;
kinematic = false;
followingPredefinedPath = false;
SetDead(false);
animator.SetTrigger("Reset");
state = PacManState.Idle;
Debug.Log($"{gameObject} Reset! Position is now {GetPosition()}.");
UpdateSpeed();
UpdateAnimator();
}
public override void SyncedUpdate()
@@ -76,33 +81,10 @@ namespace Marro.PacManUdon
return;
}
if (hideUntilUnfrozen)
{
hideUntilUnfrozen = false;
SetVisibility(true);
}
float speed = this.speed;
if (freezeSeconds > 0)
{
float freezePart = freezeSeconds / networkManager.SyncedDeltaTime;
if (freezePart >= 1)
{
freezeSeconds -= networkManager.SyncedDeltaTime;
animator.speed = 0;
return;
}
speed *= 1 - freezePart;
animator.speed = 1 - freezePart;
freezeSeconds = 0;
}
else
{
animator.speed = 1;
}
float speed = GetNextSpeed();
Vector2 position = GetPosition();
Vector2 nextPosition = GridMoverTools.GetNextPosition(position, direction, speed, networkManager.SyncedDeltaTime); // The position pacman will move to, assuming it doens't get changed
Vector2 nextPosition = GetNextPosition(position, directionVectors[(int)direction], speed, networkManager.SyncedDeltaTime); // The position pacman will move to, assuming it doens't get changed
if (!kinematic)
{
@@ -116,42 +98,75 @@ namespace Marro.PacManUdon
}
}
if (CrossesTileBorder(position, nextPosition, direction))
{
CheckNewTile(position, nextPosition);
}
SetPosition(nextPosition);
}
private float GetNextSpeed()
{
float speed = this.speed;
if (freezeSeconds > 0)
{
float freezePart = freezeSeconds / networkManager.SyncedDeltaTime;
if (freezePart >= 1)
{
freezeSeconds -= networkManager.SyncedDeltaTime;
animator.speed = 0;
speed = 0;
}
else
{
speed *= 1 - freezePart;
animator.speed = 1 - freezePart;
freezeSeconds = 0;
}
}
else
{
animator.speed = 1;
}
return speed;
}
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
{
if (GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, false) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis
&& (targetDirection.x == 0 || GridMoverTools.CheckCollisionInDirection(transform, nextPosition, new Vector2(direction.x, 0))))
if (CrossesTileCenter(position, nextPosition, Direction.Left) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis
&& (!IsHorizontal(targetDirection) || collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)HorizontalComponent(direction)])))
{ // If the target direction is in the other axis or if we're about to run into a wall
nextPosition.x = GridMoverTools.PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis
SetDirection(new Vector2(0, direction.y));
// Debug.Log($"{gameObject} crossed X tile center from {currentPosition}, nextPosition is now {nextPosition} and direction is now {direction}");
nextPosition.x = PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis
SetDirection(VerticalComponent(direction));
//Debug.Log($"{gameObject} crossed X tile center from {position}, nextPosition is now {nextPosition} and direction is now {direction}");
}
if (GridMoverTools.CrossesTileCenter(position, nextPosition, false, direction.y != 0) // See comments above but now vertical
&& (targetDirection.y == 0 || GridMoverTools.CheckCollisionInDirection(transform, nextPosition, new Vector2(0, direction.y))))
if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical
&& (!IsVertical(targetDirection) || collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
{
nextPosition.y = GridMoverTools.PositionToGrid(nextPosition).y;
SetDirection(new Vector2(direction.x, 0));
// Debug.Log($"{gameObject} crossed Y tile center from {currentPosition} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
nextPosition.y = PositionToGrid(nextPosition).y;
SetDirection(HorizontalComponent(direction));
//Debug.Log($"{gameObject} crossed Y tile center from {position} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
}
Vector2 inputDirection = input.GetDirection();
if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
&& (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) && (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border
&& !GridMoverTools.CheckCollisionInDirection(transform, nextPosition, inputDirection))
{ // Check if the requested direction does not have a wall
if (inputDirection.x != 0)
{ // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
SetDirection(inputDirection + new Vector2(0, GridMoverTools.PositionToGrid(nextPosition).y - nextPosition.y).normalized);
var inputDirection = input.GetDirection();
if (!inputDirection.Equals(Direction.Zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
&& !collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection])) // Check if the requested direction does not have a wall
{
// Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
if (IsHorizontal(inputDirection))
{
var directionToCenter = VerticalToDirection(PositionToGrid(nextPosition).y - nextPosition.y);
SetDirection((Direction)((int)inputDirection | (int)directionToCenter));
}
else
{
SetDirection(inputDirection + new Vector2(GridMoverTools.PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized);
var directionToCenter = HorizontalToDirection(PositionToGrid(nextPosition).x - nextPosition.x);
SetDirection((Direction)((int)inputDirection | (int)directionToCenter));
}
SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
networkManager.SendEventSoon(NetworkEventType.PacManTurn);
}
return nextPosition;
@@ -159,22 +174,21 @@ namespace Marro.PacManUdon
private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition)
{
if (GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, direction.y != 0))
if (CrossesTileCenter(position, nextPosition, direction))
{
// Find the next valid direction which isn't Vector2.zero
int nextValidDirectionIndex = predefinedPathIndex;
while (predefinedPath[nextValidDirectionIndex] == Vector2.zero)
while (predefinedPath[nextValidDirectionIndex] == Direction.Zero)
{
nextValidDirectionIndex += 1;
}
if (!GridMoverTools.CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex]))
if (!collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)predefinedPath[nextValidDirectionIndex]]))
{
// If we're at a Vector2.zero, we skip applying the direction and only increment.
if (nextValidDirectionIndex == predefinedPathIndex)
{
SetDirection(predefinedPath[nextValidDirectionIndex]);
SetTargetDirection(predefinedPath[nextValidDirectionIndex]);
nextPosition = GridMoverTools.PositionToGrid(nextPosition) + direction.normalized * 0.01f;
SetDirectionAndTargetDirection(predefinedPath[nextValidDirectionIndex]);
nextPosition = PositionToGrid(nextPosition) + directionVectors[(int)direction] * 0.01f;
// Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero
do
@@ -185,7 +199,7 @@ namespace Marro.PacManUdon
followingPredefinedPath = false;
break;
}
} while (predefinedPath[nextValidDirectionIndex] == Vector2.zero);
} while (predefinedPath[nextValidDirectionIndex] == Direction.Zero);
}
// gameStateManager.statusDisplay.SetDebugText(1, predefinedPathIndex.ToString());
@@ -196,62 +210,78 @@ namespace Marro.PacManUdon
return nextPosition;
}
protected override void UpdateAnimator()
private void CheckNewTile(Vector2 position, Vector2 nextPosition)
{
// Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}");
if (!gameObject.activeInHierarchy)
return;
var eatResult = collisionManager.PacManMoveToTile(position, nextPosition);
animator.SetBool(AnimatorKeyDead, dead);
if (dead)
if (eatResult == EatResult.Pellet)
{
animator.speed = 1;
return;
freezeSeconds = 0.0165f;
}
if (frozen || direction.Equals(Vector2.zero))
else if (eatResult == EatResult.PowerPellet)
{
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionNone);
animator.speed = 0;
}
else
{
animator.speed = 1;
if (targetDirection.Equals(Vector2.right))
{
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionRight);
}
else if (targetDirection.Equals(Vector2.left))
{
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionLeft);
}
else if (targetDirection.Equals(Vector2.up))
{
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionUp);
}
else if (targetDirection.Equals(Vector2.down))
{
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionDown);
}
freezeSeconds = 0.0495f;
}
}
public void SetDead(bool dead)
protected override void UpdateAnimator()
{
this.dead = dead;
//Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}");
if (!gameObject.activeInHierarchy)
return;
switch (state)
{
case PacManState.Dead:
SetAnimatorState((int)PacManAnimatorState.Dead);
animator.speed = 1;
return;
case PacManState.Idle:
SetAnimatorState((int)PacManAnimatorState.Idle);
return;
case PacManState.Big:
SetAnimatorState((int)PacManAnimatorState.Big);
animator.speed = 1;
return;
}
if (direction.Equals(Direction.Zero))
{
SetAnimatorState((int)PacManAnimatorState.Stopped);
}
else
{
SetAnimatorState((int)PacManAnimatorState.Moving);
}
animator.speed = frozen ? 0 : 1;
SetAnimatorDirection((int)targetDirection);
}
private void SetAnimatorDirection(int value) =>
animator.SetFloat(animatorKeyDirection, value);
private void SetAnimatorState(int value) =>
animator.SetFloat(animatorKeyState, value);
public void Die()
{
state = PacManState.Dead;
UpdateAnimator();
}
public void SetFrozen(bool frozen)
{
this.frozen = frozen;
UpdateAnimator();
}
public void HideUntilUnfrozen()
{
hideUntilUnfrozen = true;
SetVisibility(false);
if (!frozen && state == PacManState.Idle)
{
state = PacManState.Normal;
}
UpdateAnimator();
}
public void SetLevel(int level)
@@ -259,11 +289,18 @@ namespace Marro.PacManUdon
// Debug.Log($"{gameObject} SetLevel {level}");
defaultSpeed = PacManConstants.GetPacManDefaultSpeedForLevel(level);
powerPelletSpeed = PacManConstants.GetPacManPowerPelletSpeedForLevel(level);
UpdateSpeed();
}
public void SetPowerPellet(bool powerPellet)
{
if (powerPellet)
state = powerPellet ? PacManState.PowerPellet : PacManState.Normal;
UpdateSpeed();
}
private void UpdateSpeed()
{
if (state == PacManState.PowerPellet)
{
speed = powerPelletSpeed;
}
@@ -288,7 +325,7 @@ namespace Marro.PacManUdon
this.kinematic = kinematic;
}
public void SetPredefinedPath(Vector2[] predefinedPath)
public void SetPredefinedPath(Direction[] predefinedPath)
{
this.predefinedPath = predefinedPath;
followingPredefinedPath = true;
@@ -297,63 +334,31 @@ namespace Marro.PacManUdon
public void BecomeBig()
{
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionRightBig);
state = PacManState.Big;
UpdateAnimator();
}
void SetVisibility(bool visible)
public void SetVisibility(bool visible)
{
renderer.enabled = visible;
}
public void SetTargetDirection(Vector2 targetDirection)
{
this.targetDirection = targetDirection;
UpdateAnimator();
}
void OnTriggerEnter(Collider other)
{
Pellet pellet = other.gameObject.GetComponent<Pellet>();
if (pellet)
{
if (pellet.isPowerPellet)
{
gameController.GotPowerPellet(pellet);
freezeSeconds = 0.05f;
}
else
{
gameController.GotPellet(pellet);
freezeSeconds = 0.0166666666666667f;
}
return;
}
else if (other.gameObject.GetComponent<BonusFruit>())
{
gameController.GotFruit();
}
}
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.PacManTurn || kinematic || frozen || !enabled)
{
return;
}
data.Append(targetDirection, ref index);
data.AppendAsByte((int)state, ref index);
data.Append(freezeSeconds, ref index);
data.Append(frozen, ref index);
base.CollectSyncedData(data, ref index, eventType);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.PacManTurn || kinematic || frozen || !enabled)
{
return true;
}
state = (PacManState)data.ReadByte(ref index);
freezeSeconds = data.ReadFloat(ref index);
frozen = data.ReadBool(ref index);
SetTargetDirection(data.ReadVector2(ref index));
UpdateSpeed();
return base.WriteSyncedData(data, ref index, eventType);
}

View File

@@ -2,7 +2,7 @@ namespace Marro.PacManUdon
{
using UnityEngine;
public enum PacManFruitType
public enum PacManFruitType
{
None = -1,
Cherries = 0,
@@ -15,7 +15,7 @@ namespace Marro.PacManUdon
Key = 7
}
public enum PacManGameState
public enum PacManGameState
{
AttractMode,
AttractModeDemo,
@@ -23,14 +23,14 @@ namespace Marro.PacManUdon
InGame,
}
public enum PacManGhostFrozenState
public enum PacManGhostFrozenState
{
Frozen,
FrozenIfNotCaught,
NotFrozen
}
public enum PacManTimeSequence
public enum PacManTimeSequence
{
AttractScreenIntroduction,
AttractScreenDemo,
@@ -49,16 +49,124 @@ namespace Marro.PacManUdon
Intermission3
}
public static class PacManConstants
public enum PacManCollisionInfoType
{
Tunnel = 0b00100000,
HorizontalOnly = 0b00010000, // Bit that indicates tiles on which ghosts are only allowed to go horizontal unless they're scared
NoTurn = 0b01000000,
Wall = 0b10000000,
}
public enum PacManConsumableType
{
None = 255,
FruitLeft = 254,
FruitRight = 253,
}
public static class PacManConstants
{
// Jagged or 2D arrays can't be static so we work with 1D arrays
public static byte[] GetMazeCollisionInfo() => new byte[]
{
192, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, 192, 192, 192,
192, 192, 200, 009, 076, 076, 076, 076, 076, 076, 076, 076, 076, 076, 013, 076, 076, 013, 076, 076, 076, 076, 076, 076, 076, 076, 076, 076, 005, 196, 192, 192,
192, 192, 200, 067, 134, 194, 194, 194, 194, 194, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 194, 194, 194, 194, 194, 138, 067, 196, 192, 192,
192, 192, 200, 067, 133, 193, 193, 193, 193, 192, 192, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 192, 192, 193, 193, 193, 193, 137, 067, 196, 192, 192,
192, 192, 200, 010, 076, 013, 076, 076, 005, 196, 200, 009, 076, 076, 006, 196, 200, 010, 076, 076, 005, 196, 200, 009, 076, 076, 013, 076, 006, 196, 192, 192,
192, 192, 192, 194, 138, 067, 134, 138, 067, 196, 200, 067, 134, 194, 194, 192, 192, 194, 194, 138, 067, 196, 200, 067, 134, 138, 067, 134, 194, 192, 192, 192,
192, 192, 192, 193, 137, 067, 196, 200, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 196, 200, 067, 133, 193, 192, 192, 192,
192, 192, 200, 009, 076, 006, 196, 200, 011, 076, 076, 014, 076, 076, 029, 076, 076, 029, 076, 076, 014, 076, 076, 007, 196, 200, 010, 076, 005, 196, 192, 192,
192, 192, 200, 067, 134, 194, 192, 200, 067, 134, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 138, 067, 196, 192, 194, 138, 067, 196, 192, 192,
192, 192, 200, 067, 133, 193, 193, 137, 067, 133, 193, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 193, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192,
192, 192, 200, 010, 076, 076, 076, 076, 015, 076, 076, 013, 076, 076, 006, 196, 200, 010, 076, 076, 013, 076, 076, 015, 076, 076, 076, 076, 006, 196, 192, 192,
192, 192, 192, 194, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 192, 192, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 194, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 011, 076, 076, 076, 076, 076, 076, 076, 076, 007, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 067, 134, 194, 194, 194, 194, 194, 194, 138, 067, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
193, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 196, 192, 192, 192, 192, 192, 192, 200, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 193,
108, 108, 108, 108, 108, 108, 108, 076, 015, 076, 076, 007, 196, 192, 192, 192, 192, 192, 192, 200, 011, 076, 076, 015, 076, 108, 108, 108, 108, 108, 108, 108,
194, 194, 194, 194, 194, 194, 194, 138, 067, 134, 138, 067, 196, 192, 192, 192, 192, 192, 192, 200, 067, 134, 138, 067, 134, 194, 194, 194, 194, 194, 194, 194,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 200, 010, 076, 076, 029, 076, 076, 029, 076, 076, 006, 196, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 200, 067, 196, 192, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 192, 200, 067, 196, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 193, 193, 193, 193, 137, 067, 196, 192, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 192, 200, 067, 133, 193, 193, 193, 193, 192, 192, 192,
192, 192, 200, 009, 076, 076, 076, 076, 007, 196, 200, 009, 076, 076, 006, 196, 200, 010, 076, 076, 005, 196, 200, 011, 076, 076, 076, 076, 005, 196, 192, 192,
192, 192, 200, 067, 134, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 192, 192, 194, 194, 138, 067, 196, 200, 067, 134, 194, 194, 138, 067, 196, 192, 192,
192, 192, 200, 067, 133, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 193, 193, 193, 193, 137, 067, 133, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192,
192, 192, 200, 011, 076, 076, 076, 076, 015, 076, 076, 014, 076, 076, 013, 076, 076, 013, 076, 076, 014, 076, 076, 015, 076, 076, 076, 076, 007, 196, 192, 192,
192, 192, 200, 067, 134, 194, 194, 138, 067, 134, 194, 194, 194, 138, 067, 134, 138, 067, 134, 194, 194, 194, 138, 067, 134, 194, 194, 138, 067, 196, 192, 192,
192, 192, 200, 067, 196, 192, 192, 200, 067, 196, 192, 192, 192, 200, 067, 196, 200, 067, 196, 192, 192, 192, 200, 067, 196, 192, 192, 200, 067, 196, 192, 192,
192, 192, 200, 067, 133, 193, 193, 137, 067, 133, 193, 193, 193, 137, 067, 196, 200, 067, 133, 193, 193, 193, 137, 067, 133, 193, 193, 137, 067, 196, 192, 192,
192, 192, 200, 010, 076, 076, 076, 076, 014, 076, 076, 076, 076, 076, 006, 196, 200, 010, 076, 076, 076, 076, 076, 014, 076, 076, 076, 076, 006, 196, 192, 192,
192, 192, 192, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 192, 192, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
};
public static byte[] GetMazePelletMap() => new byte[]
{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, 255, 255, 255,
255, 255, 255, 020, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 072, 255, 255, 071, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 047, 255, 255, 255,
255, 255, 255, 019, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 073, 255, 255, 070, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 048, 255, 255, 255,
255, 255, 255, 018, 017, 016, 015, 014, 013, 255, 255, 077, 076, 075, 074, 255, 255, 069, 068, 067, 066, 255, 255, 054, 053, 052, 051, 050, 049, 255, 255, 255,
255, 255, 255, 255, 255, 080, 255, 255, 012, 255, 255, 078, 255, 255, 255, 255, 255, 255, 255, 255, 065, 255, 255, 055, 255, 255, 113, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 081, 255, 255, 011, 255, 255, 079, 255, 255, 255, 255, 255, 255, 255, 255, 064, 255, 255, 056, 255, 255, 114, 255, 255, 255, 255, 255,
255, 255, 255, 000, 083, 082, 255, 255, 010, 009, 008, 007, 006, 005, 004, 255, 255, 063, 062, 061, 060, 059, 058, 057, 255, 255, 115, 116, 001, 255, 255, 255,
255, 255, 255, 084, 255, 255, 255, 255, 093, 255, 255, 255, 255, 255, 101, 255, 255, 102, 255, 255, 255, 255, 255, 112, 255, 255, 255, 255, 117, 255, 255, 255,
255, 255, 255, 085, 255, 255, 255, 255, 092, 255, 255, 255, 255, 255, 100, 255, 255, 103, 255, 255, 255, 255, 255, 111, 255, 255, 255, 255, 118, 255, 255, 255,
255, 255, 255, 086, 087, 088, 089, 090, 091, 094, 095, 096, 097, 098, 099, 255, 255, 104, 105, 106, 107, 108, 109, 110, 123, 122, 121, 120, 119, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 243, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 124, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 242, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 125, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 241, 255, 255, 255, 255, 255, 255, 253, 254, 255, 255, 255, 255, 255, 255, 126, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 240, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 239, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 238, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 129, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 237, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 130, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 236, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 131, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 235, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 132, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 234, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 133, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 233, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 134, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 225, 226, 227, 228, 229, 232, 255, 255, 207, 208, 209, 210, 255, 255, 170, 169, 168, 167, 255, 255, 135, 136, 137, 138, 139, 140, 255, 255, 255,
255, 255, 255, 224, 255, 255, 255, 255, 231, 255, 255, 206, 255, 255, 255, 255, 255, 255, 255, 255, 166, 255, 255, 161, 255, 255, 255, 255, 141, 255, 255, 255,
255, 255, 255, 223, 255, 255, 255, 255, 230, 255, 255, 205, 255, 255, 255, 255, 255, 255, 255, 255, 165, 255, 255, 160, 255, 255, 255, 255, 142, 255, 255, 255,
255, 255, 255, 218, 219, 220, 221, 222, 199, 200, 201, 202, 203, 204, 185, 184, 183, 173, 172, 171, 164, 163, 162, 155, 156, 157, 158, 159, 143, 255, 255, 255,
255, 255, 255, 217, 255, 255, 255, 255, 198, 255, 255, 255, 255, 255, 186, 255, 255, 174, 255, 255, 255, 255, 255, 154, 255, 255, 255, 255, 144, 255, 255, 255,
255, 255, 255, 003, 255, 255, 255, 255, 197, 255, 255, 255, 255, 255, 187, 255, 255, 175, 255, 255, 255, 255, 255, 153, 255, 255, 255, 255, 002, 255, 255, 255,
255, 255, 255, 216, 255, 255, 255, 255, 196, 255, 255, 255, 255, 255, 188, 255, 255, 176, 255, 255, 255, 255, 255, 152, 255, 255, 255, 255, 145, 255, 255, 255,
255, 255, 255, 215, 214, 213, 212, 211, 195, 194, 193, 192, 191, 190, 189, 255, 255, 177, 178, 179, 180, 181, 182, 151, 150, 149, 148, 147, 146, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
};
public static int[] GetMazePelletIndices() => new int[]
{
227, 252, 892, 867, 238, 237, 236, 235, 234, 233, 232, 200, 168, 136, 135, 134,
133, 132, 131, 099, 067, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045,
046, 047, 048, 049, 050, 051, 052, 053, 054, 055, 056, 057, 058, 059, 060, 092,
124, 156, 155, 154, 153, 152, 151, 183, 215, 247, 246, 245, 244, 243, 242, 241,
212, 180, 148, 147, 146, 145, 113, 081, 078, 110, 142, 141, 140, 139, 171, 203,
165, 197, 229, 228, 259, 291, 323, 324, 325, 326, 327, 328, 296, 264, 329, 330,
331, 332, 333, 334, 302, 270, 273, 305, 337, 338, 339, 340, 341, 342, 343, 311,
279, 186, 218, 250, 251, 284, 316, 348, 347, 346, 345, 344, 375, 407, 439, 471,
503, 535, 567, 599, 631, 663, 695, 727, 728, 729, 730, 731, 732, 764, 796, 828,
860, 924, 956, 955, 954, 953, 952, 951, 919, 887, 855, 823, 824, 825, 826, 827,
791, 759, 822, 821, 820, 788, 756, 724, 723, 722, 721, 819, 818, 817, 849, 881,
913, 945, 946, 947, 948, 949, 950, 816, 815, 814, 846, 878, 910, 942, 941, 940,
939, 938, 937, 936, 904, 872, 840, 808, 809, 810, 811, 812, 813, 779, 747, 715,
716, 717, 718, 935, 934, 933, 932, 931, 899, 835, 803, 804, 805, 806, 807, 771,
739, 707, 708, 709, 710, 711, 776, 744, 712, 680, 648, 616, 584, 552, 520, 488,
456, 424, 392, 360,
};
public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false)
{
if (skipFirstComponent)
{
GameObject[] gameObjects = new GameObject[components.Length-1];
for (int i = 0; i < components.Length-1; i++)
GameObject[] gameObjects = new GameObject[components.Length - 1];
for (int i = 0; i < components.Length - 1; i++)
{
gameObjects[i] = components[i+1].gameObject;
gameObjects[i] = components[i + 1].gameObject;
}
return gameObjects;
}
@@ -71,7 +179,7 @@ namespace Marro.PacManUdon
}
return gameObjects;
}
}
public static float GetPowerPelletBlinkToggleInterval()
@@ -81,9 +189,9 @@ namespace Marro.PacManUdon
public static PacManFruitType GetFruitTypeForLevel(int level)
{
PacManFruitType[] FruitTypePerLevel = new PacManFruitType[]
PacManFruitType[] FruitTypePerLevel = new PacManFruitType[]
{
PacManFruitType.Cherries,
PacManFruitType.Cherries,
PacManFruitType.Strawberry,
PacManFruitType.Peach,
PacManFruitType.Peach,
@@ -97,15 +205,15 @@ namespace Marro.PacManUdon
PacManFruitType.Bell,
PacManFruitType.Key
};
if (level-1 < 0)
if (level - 1 < 0)
{
return PacManFruitType.None;
}
if (level-1 >= FruitTypePerLevel.Length)
if (level - 1 >= FruitTypePerLevel.Length)
{
return FruitTypePerLevel[FruitTypePerLevel.Length-1];
return FruitTypePerLevel[FruitTypePerLevel.Length - 1];
}
return FruitTypePerLevel[level-1];
return FruitTypePerLevel[level - 1];
}
public static float GetGhostHomeSpeed()
@@ -113,101 +221,101 @@ namespace Marro.PacManUdon
return 3.5f;
}
public static float GetPacManDefaultSpeedForLevel(int level)
public static float GetPacManDefaultSpeedForLevel(int level)
{
if(level <= 1) return 7.576f;
if(level <= 4) return 8.523f;
if(level <= 20) return 9.470f;
return 8.523f;
if (level <= 1) return 7.576f;
if (level <= 4) return 8.523f;
if (level <= 20) return 9.470f;
return 8.523f;
}
public static float GetPacManPowerPelletSpeedForLevel(int level)
{
if(level <= 1) return 8.523f;
if(level <= 4) return 8.996f;
return 9.470f;
if (level <= 1) return 8.523f;
if (level <= 4) return 8.996f;
return 9.470f;
}
public static float GetGhostDefaultSpeedForLevel(int level)
{
if(level <= 1) return 7.102f;
if(level <= 4) return 8.049f;
return 8.996f;
if (level <= 1) return 7.102f;
if (level <= 4) return 8.049f;
return 8.996f;
}
public static float GetGhostTunnelSpeedForLevel(int level)
{
if(level <= 1) return 3.788f;
if(level <= 4) return 4.261f;
return 4.735f;
if (level <= 1) return 3.788f;
if (level <= 4) return 4.261f;
return 4.735f;
}
public static float GetBlinkyElroy1SpeedForLevel(int level)
public static float GetBlinkyElroy1SpeedForLevel(int level)
{
if(level <= 1) return 7.576f;
if(level <= 4) return 8.523f;
return 9.470f;
if (level <= 1) return 7.576f;
if (level <= 4) return 8.523f;
return 9.470f;
}
public static float GetBlinkyElroy2SpeedForLevel(int level)
public static float GetBlinkyElroy2SpeedForLevel(int level)
{
if(level <= 1) return 8.049f;
if(level <= 4) return 8.996f;
return 9.943f;
if (level <= 1) return 8.049f;
if (level <= 4) return 8.996f;
return 9.943f;
}
public static float GetGhostScaredSpeedForLevel(int level)
public static float GetGhostScaredSpeedForLevel(int level)
{
if(level <= 1) return 4.735f;
if(level <= 4) return 5.208f;
return 5.682f;
if (level <= 1) return 4.735f;
if (level <= 4) return 5.208f;
return 5.682f;
}
public static int GetElroy1PelletsRemainingForLevel(int level)
public static int GetElroy1PelletsRemainingForLevel(int level)
{
if(level <= 1) return 20;
if(level <= 2) return 30;
if(level <= 5) return 40;
if(level <= 8) return 50;
if(level <= 11) return 60;
if(level <= 14) return 80;
if(level <= 18) return 100;
return 120;
if (level <= 1) return 20;
if (level <= 2) return 30;
if (level <= 5) return 40;
if (level <= 8) return 50;
if (level <= 11) return 60;
if (level <= 14) return 80;
if (level <= 18) return 100;
return 120;
}
public static int GetElroy2PelletsRemainingForLevel(int level)
public static int GetElroy2PelletsRemainingForLevel(int level)
{
if(level <= 1) return 10;
if(level <= 2) return 15;
if(level <= 5) return 20;
if(level <= 8) return 25;
if(level <= 11) return 30;
if(level <= 14) return 40;
if(level <= 18) return 50;
return 60;
if (level <= 1) return 10;
if (level <= 2) return 15;
if (level <= 5) return 20;
if (level <= 8) return 25;
if (level <= 11) return 30;
if (level <= 14) return 40;
if (level <= 18) return 50;
return 60;
}
public static float GetGhostHousePelletTimeoutLimitForLevel(int level)
{
if(level <= 4) return 4;
return 3;
if (level <= 4) return 4;
return 3;
}
public static int[] GetGhostHousePrivatePelletCounterLimitForLevel(int level)
{
if(level <= 1) return new int[] { 0, 0, 30, 60};
if(level <= 2) return new int[] { 0, 0, 0, 50};
return new int[] { 0, 0, 0, 0};
if (level <= 1) return new int[] { 0, 0, 30, 60 };
if (level <= 2) return new int[] { 0, 0, 0, 50 };
return new int[] { 0, 0, 0, 0 };
}
public static float[] GetScatterPatternForLevel(int level)
public static float[] GetScatterPatternForLevel(int level)
{
if(level <= 1) return new float[] { 7, 27, 34, 54, 59, 79, 84 };
if(level <= 4) return new float[] { 7, 27, 34, 54, 59, 1092, 1092.0166667f};
return new float[] { 5, 25, 30, 50, 55, 1092, 1092.0166667f};
if (level <= 1) return new float[] { 7, 27, 34, 54, 59, 79, 84 };
if (level <= 4) return new float[] { 7, 27, 34, 54, 59, 1092, 1092.0166667f };
return new float[] { 5, 25, 30, 50, 55, 1092, 1092.0166667f };
}
public static float GetScaredDurationForLevel(int level)
public static float GetScaredDurationForLevel(int level)
{
float[] scaredDurationPerLevel =
{
@@ -231,18 +339,18 @@ namespace Marro.PacManUdon
1,
0
};
if (level-1 < 0)
if (level - 1 < 0)
{
return scaredDurationPerLevel[0];
}
if (level-1 >= scaredDurationPerLevel.Length)
if (level - 1 >= scaredDurationPerLevel.Length)
{
return scaredDurationPerLevel[scaredDurationPerLevel.Length-1];
return scaredDurationPerLevel[scaredDurationPerLevel.Length - 1];
}
return scaredDurationPerLevel[level-1];
return scaredDurationPerLevel[level - 1];
}
public static float GetScaredNumberOfFlashesForLevel(int level)
public static float GetScaredNumberOfFlashesForLevel(int level)
{
int[] scaredNumberOfFlashesPerLevel = new int[]
{
@@ -266,19 +374,20 @@ namespace Marro.PacManUdon
3,
0
};
if (level-1 < 0)
if (level - 1 < 0)
{
return scaredNumberOfFlashesPerLevel[0];
}
if (level-1 >= scaredNumberOfFlashesPerLevel.Length)
if (level - 1 >= scaredNumberOfFlashesPerLevel.Length)
{
return scaredNumberOfFlashesPerLevel[scaredNumberOfFlashesPerLevel.Length-1];
return scaredNumberOfFlashesPerLevel[scaredNumberOfFlashesPerLevel.Length - 1];
}
return scaredNumberOfFlashesPerLevel[level-1];
return scaredNumberOfFlashesPerLevel[level - 1];
}
public static int FruitTypeToValue(PacManFruitType fruitType) { // I can't get casting from enum to int to work so this is a workaround
switch (fruitType)
public static int FruitTypeToValue(PacManFruitType fruitType)
{ // I can't get casting from enum to int to work so this is a workaround
switch (fruitType)
{
default:
case PacManFruitType.None:

View File

@@ -1,133 +0,0 @@
using System;
using UnityEngine;
namespace Marro.PacManUdon
{
public class PelletManager : SyncedObject
{
public int PelletCount => pellets.Length;
public int PelletCollectedCount { get; private set; }
Pellet[] pellets;
Animator[] powerPellets;
bool powerPelletBlinkEnabled;
float powerPelletBlinkToggleInterval;
float powerPelletBlinkProgress;
bool powerPelletBlinkCurrentlyVisible;
byte[] syncedPelletsCollected;
public void Initialize()
{
gameObject.SetActive(true);
pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
powerPellets = GetComponentsInChildren<Animator>(true);
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
SetPowerPelletsBlink(false);
RestoreAllPellets();
}
public override void SyncedUpdate()
{
if (!powerPelletBlinkEnabled)
{
return;
}
powerPelletBlinkProgress += networkManager.SyncedDeltaTime;
if (powerPelletBlinkProgress >= powerPelletBlinkToggleInterval)
{
// Debug.Log($"{gameObject} PowerPelletBlink toggle");
powerPelletBlinkProgress -= powerPelletBlinkToggleInterval;
powerPelletBlinkCurrentlyVisible = !powerPelletBlinkCurrentlyVisible;
SetPowerPelletsVisible(powerPelletBlinkCurrentlyVisible);
}
}
void SetPowerPelletsVisible(bool visible)
{
// Debug.Log($"{gameObject} SetPowerPelletVisible {visible}, powerPellets.Length: {powerPellets.Length}");
foreach (Animator powerPellet in powerPellets)
{
powerPellet.SetBool("Visible", visible);
}
}
public void SetPowerPelletsBlink(bool enabled)
{
// Debug.Log($"{gameObject} SetPowerPelletBlink {enabled}");
powerPelletBlinkEnabled = enabled;
powerPelletBlinkCurrentlyVisible = true;
powerPelletBlinkProgress = 0;
SetPowerPelletsVisible(true);
}
public void FreezePowerPelletsBlink(bool frozen)
{
powerPelletBlinkEnabled = !frozen;
}
public int PelletCollected(Pellet pellet)
{
pellet.gameObject.SetActive(false);
var index = pellet.transform.GetSiblingIndex();
syncedPelletsCollected[index/8] |= (byte)(1 << index%8);
PelletCollectedCount++;
return PelletCollectedCount;
}
public int RestoreAllPellets()
{
foreach (var pellet in pellets)
{
pellet.gameObject.SetActive(true);
}
syncedPelletsCollected = new byte[pellets.Length/8 + 1];
PelletCollectedCount = 0;
return PelletCount;
}
private void SetPelletsCollectedFromSync()
{
for (int i = 0; i < pellets.Length; i++)
{
var active = (syncedPelletsCollected[i/8] & (byte)(1 << i%8)) == 0;
pellets[i].gameObject.SetActive(active);
}
}
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.SyncPellets)
{
return;
}
data.Append((byte)PelletCollectedCount, ref index);
data.Append(syncedPelletsCollected, ref index);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.SyncPellets)
{
return true;
}
PelletCollectedCount = data.ReadByte(ref index);
Array.Copy(data, index, syncedPelletsCollected, 0, syncedPelletsCollected.Length);
index += syncedPelletsCollected.Length;
SetPelletsCollectedFromSync();
return true;
}
}
}

View File

@@ -43,31 +43,37 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 8
Data: 10
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: active
Data: networkManager
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: active
Data: networkManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
Data: Marro.PacManUdon.NetworkManager, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 3
Entry: 7
Data: 4|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.Udon.UdonBehaviour, VRC.Udon
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -82,7 +88,7 @@ MonoBehaviour:
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 4|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -103,31 +109,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: gameManager
Data: active
- Name: $v
Entry: 7
Data: 5|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: gameManager
Data: active
- Name: <UserType>k__BackingField
Entry: 7
Data: 6|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.GameManager, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 7|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.Udon.UdonBehaviour, VRC.Udon
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 7
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -139,7 +139,7 @@ MonoBehaviour:
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 8|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
@@ -163,25 +163,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: inputHorizontal
Data: gameManager
- Name: $v
Entry: 7
Data: 9|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: inputHorizontal
Data: gameManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 10|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Vector2, UnityEngine.CoreModule
Data: Marro.PacManUdon.GameManager, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 10
Data: 4
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -217,19 +217,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: inputVertical
Data: player
- Name: $v
Entry: 7
Data: 12|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: inputVertical
Data: player
- Name: <UserType>k__BackingField
Entry: 9
Data: 10
Entry: 7
Data: 13|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.SDKBase.VRCPlayerApi, VRCSDKBase
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 10
Data: 13
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -244,7 +250,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 13|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 14|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -265,73 +271,31 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: horizontalValue
Data: inputMethod
- Name: $v
Entry: 7
Data: 14|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 15|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: horizontalValue
Data: inputMethod
- Name: <UserType>k__BackingField
Entry: 7
Data: 15|System.RuntimeType, mscorlib
Data: 16|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
Data: Marro.PacManUdon.InputMethod, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
Data: 17|System.RuntimeType, mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 16|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: verticalValue
- Name: $v
Entry: 7
Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: verticalValue
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -367,19 +331,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: horizontalPriority
Data: resultInput
- Name: $v
Entry: 7
Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: horizontalPriority
Data: resultInput
- Name: <UserType>k__BackingField
Entry: 9
Data: 3
Entry: 7
Data: 20|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Direction, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 3
Data: 17
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -394,7 +364,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 20|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 21|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -415,25 +385,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: player
Data: analogInput
- Name: $v
Entry: 7
Data: 21|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: player
Data: analogInput
- Name: <UserType>k__BackingField
Entry: 7
Data: 22|System.RuntimeType, mscorlib
Data: 23|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.SDKBase.VRCPlayerApi, VRCSDKBase
Data: UnityEngine.Vector2, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 22
Data: 23
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -448,7 +418,157 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 23|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 24|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: dirty
- Name: $v
Entry: 7
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: dirty
- Name: <UserType>k__BackingField
Entry: 9
Data: 7
- Name: <SystemType>k__BackingField
Entry: 9
Data: 7
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 26|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: lastUsedHand
- Name: $v
Entry: 7
Data: 27|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: lastUsedHand
- Name: <UserType>k__BackingField
Entry: 7
Data: 28|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.Udon.Common.HandType, VRC.Udon.Common
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 28
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 29|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: horizontalPriority
- Name: $v
Entry: 7
Data: 30|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: horizontalPriority
- Name: <UserType>k__BackingField
Entry: 9
Data: 7
- Name: <SystemType>k__BackingField
Entry: 9
Data: 7
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 31|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0

View File

@@ -1,30 +1,80 @@
namespace Marro.PacManUdon
{
using System;
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using VRC.Udon.Common;
public class PlayerInput : UdonSharpBehaviour
enum InputMethod
{
KeyboardMouse,
Other,
}
public class PlayerInput : SyncedObject
{
public bool active;
private GameManager gameManager;
Vector2 inputHorizontal;
Vector2 inputVertical;
float horizontalValue;
float verticalValue;
bool horizontalPriority;
VRCPlayerApi player;
private VRCPlayerApi player;
private InputMethod inputMethod;
private Direction resultInput;
private Vector2 analogInput;
private bool dirty;
private HandType lastUsedHand;
private bool horizontalPriority;
public void Initialize(GameManager gameManager)
{
this.gameManager = gameManager;
inputHorizontal = Vector2.zero;
inputVertical = Vector2.zero;
horizontalPriority = false;
player = Networking.LocalPlayer;
inputMethod = InputMethod.KeyboardMouse;
resultInput = Direction.Zero;
analogInput = Vector2.zero;
dirty = false;
horizontalPriority = false;
SubscribeToEvent(NetworkEventType.InputChange);
}
void Update()
{
if (active)
{
if (Input.GetKeyDown(KeyCode.R))
{
gameManager.ResetButtonPressed();
}
if (Input.GetKeyDown(KeyCode.G))
{
gameManager.networkManager.DoFullSync();
}
if (Input.GetKeyDown(KeyCode.C))
{
gameManager.JumpToTimeSequenceBoardClear();
}
}
else
{
if (Input.GetKeyDown(KeyCode.T))
{
gameManager.ResetButtonPressed();
}
}
}
public override void SyncedUpdate()
{
if (dirty) // Update now to ensure input feedback is performed timely
{
UpdateResultInput();
}
}
public void Activate()
@@ -68,33 +118,10 @@
{
return;
}
horizontalValue = Math.Abs(value);
if (value < -0.5)
{
inputHorizontal = Vector2.left;
if (horizontalValue >= verticalValue)
{
// horizontalPriority = true;
SetPriority(true);
}
}
else if (value > 0.5)
{
inputHorizontal = Vector2.right;
if (horizontalValue >= verticalValue)
{
// horizontalPriority = true;
SetPriority(true);
}
}
else
{
inputHorizontal = Vector2.zero;
// horizontalPriority = false;
SetPriority(false);
}
// Debug.Log("Horizontal Input Event: " + value + " | Direction: " + direction + " | lastDirection: " + lastDirection + " | Left: " + left + " | Right: " + right);
analogInput.x = value;
lastUsedHand = args.handType;
dirty = true;
}
public override void InputMoveVertical(float value, UdonInputEventArgs args)
@@ -103,101 +130,145 @@
{
return;
}
verticalValue = Math.Abs(value);
if (value < -0.5)
{
inputVertical = Vector2.down;
if (verticalValue >= horizontalValue)
{
// horizontalPriority = false;
SetPriority(false);
}
}
else if (value > 0.5)
{
inputVertical = Vector2.up;
if (verticalValue >= horizontalValue)
{
// horizontalPriority = false;
SetPriority(false);
}
}
else
{
inputVertical = Vector2.zero;
// horizontalPriority = true;
SetPriority(true);
}
// Debug.Log("Vertical Input Event: " + value + " | Direction: " + direction + " | lastDirection : " + lastDirection);
analogInput.y = value;
lastUsedHand = args.handType;
dirty = true;
}
private void SetPriority(bool horizontalPriority)
public override void OnInputMethodChanged(VRCInputMethod inputMethod)
{
if (this.horizontalPriority != horizontalPriority)
switch (inputMethod)
{
player.PlayHapticEventInHand(VRC_Pickup.PickupHand.Left, 0.1f, 0.15f, 75);
this.horizontalPriority = horizontalPriority;
case VRCInputMethod.Keyboard:
case VRCInputMethod.Mouse:
this.inputMethod = InputMethod.KeyboardMouse;
return;
default:
this.inputMethod = InputMethod.Other;
return;
}
}
// public Vector2[] GetDirections() {
// return new Vector2[]{inputHorizontal, inputVertical};
// }
public Vector2 GetDirection()
private void UpdateResultInput()
{
dirty = false;
var newResult = GetResultInput(analogInput);
if (newResult == resultInput)
{
return;
}
//Debug.Log($"Switched to input direction {newResult} from analogInput {analogInput} with HorizontalPriority {horizontalPriority}");
resultInput = newResult;
networkManager.SendEventSoon(NetworkEventType.InputChange, true);
PlayHaptics();
}
private void PlayHaptics()
{
if (inputMethod == InputMethod.KeyboardMouse)
{
return;
}
VRC_Pickup.PickupHand hand;
switch (lastUsedHand)
{
case HandType.LEFT:
hand = VRC_Pickup.PickupHand.Left;
break;
case HandType.RIGHT:
hand = VRC_Pickup.PickupHand.Right;
break;
default:
return;
}
player.PlayHapticEventInHand(hand, 0.1f, 0.15f, 75);
}
private Direction GetResultInput(Vector2 analogInput)
{
if (analogInput.magnitude < 0.8)
{
return Direction.Zero;
}
var normalized = analogInput.normalized;
//Debug.Log($"Checking analogInput {analogInput} with HorizontalPriority {horizontalPriority}, normalized {normalized}");
const float directionDivider = 0.72f;
if (normalized.x > directionDivider)
{
horizontalPriority = false;
return Direction.Right;
}
else if (normalized.x < -directionDivider)
{
horizontalPriority = false;
return Direction.Left;
}
else if (normalized.y > directionDivider)
{
horizontalPriority = true;
return Direction.Up;
}
else if (normalized.y < -directionDivider)
{
horizontalPriority = true;
return Direction.Down;
}
if (horizontalPriority)
{
return inputHorizontal;
if (normalized.x > 0)
{
return Direction.Right;
}
return Direction.Left;
}
else
if (normalized.y > 0)
{
return inputVertical;
return Direction.Up;
}
return Direction.Down;
}
public void OverrideDirection(Vector2 direction) // For recording the demo only, should not be used when shipped as it is very much a hack
public Direction GetDirection()
{
inputHorizontal = new Vector2(direction.x, direction.y);
horizontalPriority = true;
if (dirty) // Update now to reduce input delay
{
UpdateResultInput();
}
return resultInput;
}
// public Vector2 GetRotatedDirection() {
// return RotateDirection(GetDirection(), rotation);
// }
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.InputChange)
{
return;
}
// public Vector2 RotateDirection(Vector2 direction, int rotation) {
// rotation = rotation%4;
// // Debug.Log(direction + " " + rotation);
// switch(rotation) {
// default:
// return direction;
// case 1:
// return new Vector2(direction.y, -direction.x);
// case 2:
// return new Vector2(-direction.x, -direction.y);
// case 3:
// return new Vector2(-direction.y, direction.x);
// }
// }
ByteUtils.AppendAsByte(data, (int)resultInput, ref index);
}
// public override void InputLookHorizontal(float value, UdonInputEventArgs args)
// {
// float rotation = player.GetRotation().eulerAngles.y;
// if(rotation > 45 && rotation <= 135) {
// // Debug.Log("Right");
// this.rotation = 1;
// } else if(rotation > 135 && rotation <= 225) {
// // Debug.Log("Backward");
// this.rotation = 2;
// } else if(rotation > 225 && rotation <= 315) {
// // Debug.Log("Left");
// this.rotation = 3;
// } else if(rotation > 315 || rotation <= 45) {
// // Debug.Log("Forward");
// this.rotation = 0;
// }
// }
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.InputChange)
{
return true;
}
resultInput = (Direction)ByteUtils.ReadByte(data, ref index);
return true;
}
}
}

View File

@@ -1,52 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: PowerPellet
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: bc9582994932aa648bc02c914215e7cc, type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 55d0efe8af4dba540a508287baca6656, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: 7835090324168685075
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: fieldDefinitions
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
UdonSharp.Editor]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
mscorlib]], mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

View File

@@ -1,12 +0,0 @@
namespace Marro.PacManUdon
{
using UdonSharp;
public class PowerPellet : UdonSharpBehaviour
{
// Oh how I wish I could just have this method extend pellet and do things the normal way...
// But alas, with 'typeof', 'is' and overriding base fields all broken/not available I don't see a good way of differentiating between a type or its derivatives...
// The only reason I even want to use this class is so I can do GetComponentsInChildren<PowerPellet> instead of gathering all Pellets and then sorting through them.
// But since power pellets are the only pellets with animators, I'll probably just use GetComponentsInChildren<Animator> instead without further checking, since the animator is what I need to manipulate anyway.
}
}

View File

@@ -14,316 +14,314 @@ namespace Marro.PacManUdon
SetGameState(PacManGameState.AttractModeDemo);
break;
case 1:
InitializeLevel();
SetMazeVisible(true);
SetLevel(1);
break;
case 2:
// Setup ghosts
ghostManager.Ghosts[0].SetPredefinedPath(new Vector2[]{ // Blinky
Vector2.down,
Vector2.left,
Vector2.up,
Vector2.right,
Vector2.zero,
Vector2.zero,
Vector2.up,
Vector2.right,
Vector2.down,
Vector2.zero,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.down,
Vector2.right,
Vector2.up,
Vector2.zero,
Vector2.left,
Vector2.down,
Vector2.zero,
Vector2.left,
Vector2.down,
Vector2.right,
ghostManager.Ghosts[0].SetPredefinedPath(new Direction[]{ // Blinky
Direction.Up,
Direction.Left,
Direction.Down,
Direction.Right,
Direction.Zero,
Direction.Zero,
Direction.Down,
Direction.Right,
Direction.Up,
Direction.Zero,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Up,
Direction.Right,
Direction.Down,
Direction.Zero,
Direction.Left,
Direction.Up,
Direction.Zero,
Direction.Left,
Direction.Up,
Direction.Right,
// Goes through tunnel
Vector2.zero,
Vector2.up,
Vector2.left,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.right,
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.zero,
Vector2.down,
Vector2.left,
Vector2.zero,
Vector2.up,
Vector2.left,
Direction.Zero,
Direction.Down,
Direction.Left,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Right,
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Zero,
Direction.Up,
Direction.Left,
Direction.Zero,
Direction.Down,
Direction.Left,
// Gets eaten
Vector2.zero,
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.right,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.left,
Direction.Zero,
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Right,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Left,
});
ghostManager.Ghosts[1].SetPredefinedPath(new Vector2[]{ // Pinky
Vector2.down,
Vector2.left,
Vector2.up,
Vector2.zero,
Vector2.zero,
Vector2.left,
Vector2.down,
Vector2.right,
ghostManager.Ghosts[1].SetPredefinedPath(new Direction[]{ // Pinky
Direction.Up,
Direction.Left,
Direction.Down,
Direction.Zero,
Direction.Zero,
Direction.Left,
Direction.Up,
Direction.Right,
// Pellet starts
Vector2.up,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.up,
Vector2.right,
Direction.Down,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Down,
Direction.Right,
// Pellet ends
Vector2.zero,
Vector2.down,
Direction.Zero,
Direction.Up,
// Pellet starts
Vector2.left,
Vector2.down,
Vector2.zero,
Vector2.left,
Direction.Left,
Direction.Up,
Direction.Zero,
Direction.Left,
// Caught
Vector2.up,
Vector2.right,
Vector2.zero,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.right,
Direction.Down,
Direction.Right,
Direction.Zero,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Right,
// Home
Vector2.down,
Vector2.left,
Vector2.up,
Vector2.right,
Vector2.down,
Vector2.zero,
Vector2.right,
Vector2.down,
Vector2.right,
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.zero,
Vector2.down,
Vector2.left,
Direction.Up,
Direction.Left,
Direction.Down,
Direction.Right,
Direction.Up,
Direction.Zero,
Direction.Right,
Direction.Up,
Direction.Right,
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Zero,
Direction.Up,
Direction.Left,
// Power pellet active
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.up,
Vector2.left,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.up
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Down,
Direction.Left,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Down
});
ghostManager.Ghosts[2].SetPredefinedPath(new Vector2[]{ // Inky
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.zero,
Vector2.zero,
Vector2.down,
Vector2.right,
ghostManager.Ghosts[2].SetPredefinedPath(new Direction[]{ // Inky
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Zero,
Direction.Zero,
Direction.Up,
Direction.Right,
// Pellet starts
Vector2.up,
Vector2.right,
Vector2.up,
Direction.Down,
Direction.Right,
Direction.Down,
// Caught
Vector2.right,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.left,
Vector2.up,
Vector2.left,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.right,
Vector2.zero,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.zero,
Vector2.zero,
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.up,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.left,
Vector2.zero,
Vector2.up,
Vector2.left
Direction.Right,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Left,
Direction.Down,
Direction.Left,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Right,
Direction.Zero,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Zero,
Direction.Zero,
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Down,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Left,
Direction.Zero,
Direction.Down,
Direction.Left
});
ghostManager.Ghosts[3].SetPredefinedPath(new Vector2[]{ // Clyde
Vector2.down,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.down,
Vector2.zero,
Vector2.left,
Vector2.zero,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.right,
Vector2.up,
Vector2.right,
Vector2.zero,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.left,
Vector2.zero,
Vector2.up,
Vector2.right,
Vector2.zero,
Vector2.up,
Vector2.left,
Vector2.down,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.up,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.left,
Vector2.zero,
Vector2.up,
Vector2.right
ghostManager.Ghosts[3].SetPredefinedPath(new Direction[]{ // Clyde
Direction.Up,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Up,
Direction.Zero,
Direction.Left,
Direction.Zero,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Right,
Direction.Down,
Direction.Right,
Direction.Zero,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Left,
Direction.Zero,
Direction.Down,
Direction.Right,
Direction.Zero,
Direction.Down,
Direction.Left,
Direction.Up,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Down,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Left,
Direction.Zero,
Direction.Down,
Direction.Right
});
pacMan.SetPredefinedPath(new Vector2[]{
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.right,
Vector2.zero,
Vector2.up,
Vector2.left,
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.zero,
Vector2.up,
Vector2.zero,
Vector2.left,
Vector2.down,
Vector2.left,
Vector2.up,
Vector2.zero,
Vector2.zero,
Vector2.left,
Vector2.down,
Vector2.right,
Vector2.zero,
Vector2.up,
Vector2.left,
Vector2.down,
Vector2.zero,
Vector2.left,
Vector2.up,
Vector2.right,
Vector2.zero,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.left,
Vector2.zero,
Vector2.down,
Vector2.zero,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.zero,
Vector2.zero,
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.up,
Vector2.right,
Vector2.zero,
Vector2.down,
Vector2.right,
Vector2.up,
Vector2.right,
Vector2.zero,
Vector2.down,
Vector2.left,
Vector2.down,
Vector2.right,
Vector2.down,
Vector2.left,
Vector2.zero,
Vector2.zero,
Vector2.up,
Vector2.right,
Vector2.up,
Vector2.left,
Vector2.up,
Vector2.right,
pacMan.SetPredefinedPath(new Direction[]{
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Right,
Direction.Zero,
Direction.Down,
Direction.Left,
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Zero,
Direction.Down,
Direction.Zero,
Direction.Left,
Direction.Up,
Direction.Left,
Direction.Down,
Direction.Zero,
Direction.Zero,
Direction.Left,
Direction.Up,
Direction.Right,
Direction.Zero,
Direction.Down,
Direction.Left,
Direction.Up,
Direction.Zero,
Direction.Left,
Direction.Down,
Direction.Right,
Direction.Zero,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Left,
Direction.Zero,
Direction.Up,
Direction.Zero,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Zero,
Direction.Zero,
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Down,
Direction.Right,
Direction.Zero,
Direction.Up,
Direction.Right,
Direction.Down,
Direction.Right,
Direction.Zero,
Direction.Up,
Direction.Left,
Direction.Up,
Direction.Right,
Direction.Up,
Direction.Left,
Direction.Zero,
Direction.Zero,
Direction.Down,
Direction.Right,
Direction.Down,
Direction.Left,
Direction.Down,
Direction.Right,
});
break;
case 3:
SetPelletsActive(true);
pelletManager.RestoreAllPellets();
statusDisplay.SetGameOverTextVisible(true);
break;
case 4:

View File

@@ -12,11 +12,11 @@ namespace Marro.PacManUdon
PrepareForCutscene();
SetGameState(PacManGameState.AttractMode);
// Initialize
soundManager.SuppressSound(true);
attractScreen.gameObject.SetActive(true);
attractScreen.Initialize();
attractScreen.Initialize(this, bonusFruit, ghostManager.Ghosts);
for (int i = 0; i <= 15; i++)
{
// Debug.Log($"{gameObject} TimeSequenceAttractScreen deactivating with iteration i");
@@ -90,9 +90,8 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true);
pacMan.SetActive(true);
pacMan.SetPosition(attractScreenElements[16].transform.localPosition);
pacMan.SetDirection(Vector2.left);
pacMan.SetDirection(Direction.Left);
ghostManager.RestartLevel();
ghostManager.SetLevel(2);
ghostManager.SetKinematic(true);
ghostManager.SetActive(true);
@@ -100,7 +99,7 @@ namespace Marro.PacManUdon
for (int i = 0; i < ghosts.Length; i++)
{
ghosts[i].SetPosition(attractScreenElements[17 + i].transform.localPosition);
ghosts[i].SetDirection(Vector2.left);
ghosts[i].SetDirectionAndTargetDirection(Direction.Left);
ghosts[i].SetState(PacManGhostState.Normal);
}
break;
@@ -119,8 +118,7 @@ namespace Marro.PacManUdon
case 18:
// Turn PacMan around after eating power pellet
pacMan.SetDirection(Vector2.right);
pacMan.SetTargetDirection(Vector2.right);
pacMan.SetDirectionAndTargetDirection(Direction.Right);
break;
case 19:

View File

@@ -9,7 +9,7 @@ namespace Marro.PacManUdon
case 0:
// Show game over text, freeze power pellet blink
statusDisplay.SetGameOverTextVisible(true);
pelletManager.FreezePowerPelletsBlink(true);
collisionManager.FreezePowerPelletsBlink(true);
break;
case 1:
break;

View File

@@ -21,8 +21,7 @@ namespace Marro.PacManUdon
{
// Unfreeze and reveal pacman
SetPacManActive(true);
SetFrozen(false);
ghostManager.GhostCaughtContinue();
SetFrozen(false); // This also makes the caught ghost return home
soundManager.SetGhostRetreat(true);
}
}

View File

@@ -26,14 +26,14 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true);
pacMan.SetActive(true);
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
pacMan.SetDirection(Vector2.left);
pacMan.SetDirectionAndTargetDirection(Direction.Left);
ghostManager.SetLevel(5);
ghostManager.SetKinematic(true);
ghostManager.gameObject.SetActive(true);
blinky.SetElroy(2);
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
blinky.SetDirection(Vector2.left);
blinky.SetDirectionAndTargetDirection(Direction.Left);
blinky.SetState(PacManGhostState.Normal);
SetFrozen(false);
@@ -46,14 +46,14 @@ namespace Marro.PacManUdon
// Reached end, make ghost scared and turn around
blinky.BecomeScared();
blinky.SetPosition(intermissionScreenElements[3].transform.localPosition);
pacMan.SetDirection(Vector2.zero);
pacMan.SetDirection(Direction.Zero);
pacMan.SetPosition(intermissionScreenElements[2].transform.localPosition);
pacMan.SetPowerPellet(true);
break;
case 4:
// Pacman starts chasing ghosts
pacMan.SetDirection(Vector2.right);
pacMan.SetDirectionAndTargetDirection(Direction.Right);
pacMan.BecomeBig();
break;
case 5:

View File

@@ -34,14 +34,14 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true);
pacMan.SetActive(true);
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
pacMan.SetDirection(Vector2.left);
pacMan.SetDirectionAndTargetDirection(Direction.Left);
ghostManager.SetLevel(5);
ghostManager.SetKinematic(true);
ghostManager.gameObject.SetActive(true);
blinky.SetElroy(2);
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
blinky.SetDirection(Vector2.left);
blinky.SetDirectionAndTargetDirection(Direction.Left);
blinky.SetState(PacManGhostState.Normal);
SetFrozen(false);
@@ -65,16 +65,16 @@ namespace Marro.PacManUdon
case 8:
// Blinky sprite updates with broken cover
blinky.SetSpecialLook(true);
blinky.SetDirection(Vector2.up);
blinky.SetDirectionAndTargetDirection(Direction.Up);
blinky.SetPosition(blinky.GetPosition() + new Vector2(-0.250f, 0f));
break;
case 9:
// Blinky looks at broken cover
blinky.SetDirection(Vector2.down);
blinky.SetDirectionAndTargetDirection(Direction.Down);
break;
case 10:
// Cutscene starts to unload
blinky.SetDirection(Vector2.zero);
blinky.SetDirectionAndTargetDirection(Direction.Zero);
break;
case 11:
// End cutscene

View File

@@ -26,14 +26,14 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true);
pacMan.SetActive(true);
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
pacMan.SetDirection(Vector2.left);
pacMan.SetDirectionAndTargetDirection(Direction.Left);
ghostManager.SetLevel(5);
ghostManager.SetKinematic(true);
ghostManager.gameObject.SetActive(true);
blinky.SetElroy(2);
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
blinky.SetDirection(Vector2.left);
blinky.SetDirectionAndTargetDirection(Direction.Left);
blinky.SetState(PacManGhostState.Normal);
blinky.SetSpecialLook(true);
@@ -45,13 +45,13 @@ namespace Marro.PacManUdon
break;
case 3:
// Reached end, freeze
pacMan.SetDirection(Vector2.zero);
blinky.SetDirection(Vector2.zero);
pacMan.SetDirectionAndTargetDirection(Direction.Zero);
blinky.SetDirectionAndTargetDirection(Direction.Zero);
break;
case 4:
// Ghost runs back on screen
blinky.SetPosition(intermissionScreenElements[3].transform.localPosition);
blinky.SetDirection(Vector2.right);
blinky.SetDirectionAndTargetDirection(Direction.Right);
break;
case 5:
// End cutscene

View File

@@ -14,7 +14,7 @@ namespace Marro.PacManUdon
case 1:
// Hide ghosts, start pacman death animation
SetGhostsActive(false);
pacMan.SetDead(true);
pacMan.Die();
break;
case 2:
// Start playing death sound

View File

@@ -42,7 +42,6 @@ namespace Marro.PacManUdon
SetFrozen(false);
soundManager.SuppressSound(false);
soundManager.StartGhostSound();
soundManager.UpdatePelletCount(pelletManager.PelletCount - pelletManager.PelletCollectedCount);
}
}
}

View File

@@ -11,7 +11,6 @@ namespace Marro.PacManUdon
gameState = PacManGameState.InGame;
InitializeNewGame();
InitializeLevel();
PrepareForCutscene();
soundManager.SuppressSound(false);

View File

@@ -10,9 +10,9 @@ namespace Marro.PacManUdon
PrepareForCutscene();
// Reset, show maze and score display
InitializeLevel();
SetMazeVisible(true);
statusDisplay.SetScoreDisplayVisible(true);
statusDisplay.SetLabel1UPTextBlinking(true);
break;
case 1:
// Increment level, show ready, show pellets, show lives indicators

View File

@@ -5,9 +5,8 @@ namespace Marro.PacManUdon
public partial class GameManager
{
// A note about the quality of the code here:
// I intended to write this using proper classes, right until I realized Udon does not support instantiating classes.
// While I'm not a big fan of the partial class solution that I ended up doing (static classes would still be neater, or perhaps separate UdonSharpBehaviour instances),
// I'm not redoing this unless I get instantiatable classes before I wrap up this project.
// I intended to write this using separate classes per time sequence, until I realized Udon does not support instantiating classes.
// While I'm not a big fan of using partial classes for this, I'm not redoing this unless there's a major Udon update before I wrap up this project.
bool currentlyInTimeSequence;
bool waitingForTimeSequenceFinalize;
bool jumpingToTimeSequence;
@@ -18,12 +17,9 @@ namespace Marro.PacManUdon
private void StartTimeSequence(PacManTimeSequence timeSequence)
{
Debug.Log($"StartTimeSequence: {timeSequence}");
//Debug.Log($"StartTimeSequence: {timeSequence}");
if (currentlyInTimeSequence)
{
TimeSequenceEndCurrent();
}
TimeSequenceTryEndCurrent();
TimeSequencePrepareForStart(timeSequence);
@@ -35,12 +31,23 @@ namespace Marro.PacManUdon
TimeSequenceProgressToTime(timeSequenceSecondsPassed);
}
private void TimeSequenceEndCurrent()
private void TimeSequenceTryEndCurrent()
{
if (!currentlyInTimeSequence)
{
return;
}
//Debug.Log($"{gameObject} TimeSequenceEndCurrent");
jumpingToTimeSequence = true;
TimeSequenceProgressToTime(100000f);
Debug.LogWarning($"{gameObject} TimeSequenceEndCurrent");
TryFinalizeTimeSequence();
if (waitingForTimeSequenceFinalize)
{
TimeSequenceExecuteFinalize(currentTimeSequence);
}
jumpingToTimeSequence = false;
}
@@ -56,7 +63,7 @@ namespace Marro.PacManUdon
private void TimeSequenceSkipToNextStep()
{
Debug.Log($"{gameObject} TimeSequenceSkipToNextStep");
//Debug.Log($"{gameObject} TimeSequenceSkipToNextStep");
if (timeSequenceProgress < timeSequenceKeyframeTimes.Length)
{
TimeSequenceProgressToTime(timeSequenceKeyframeTimes[timeSequenceProgress]);
@@ -79,61 +86,40 @@ namespace Marro.PacManUdon
if (timeSequenceProgress >= timeSequenceKeyframeTimes.Length)
{
currentlyInTimeSequence = false;
TimeSequencePrepareForFinish(currentTimeSequence);
TimeSequenceFinish(currentTimeSequence);
break;
}
}
}
private void TimeSequencePrepareForFinish(PacManTimeSequence timeSequence)
private void TimeSequenceFinish(PacManTimeSequence timeSequence)
{
//if (networkManager.IsOwner)
//{
Debug.LogWarning($"{gameObject} TimeSequencePrepareForFinish");
TimeSequenceExecuteFinalize(timeSequence);
if (!jumpingToTimeSequence)
{
TimeSequenceExecuteFinished(timeSequence);
}
//}
//else
//{
// waitingForTimeSequenceFinalize = true;
//}
}
private void TryFinalizeTimeSequence()
private void TimeSequenceSyncWithRemote(PacManTimeSequence remoteCurrentTimeSequence, float timeSequenceSecondsPassedRemote)
{
if (!waitingForTimeSequenceFinalize)
// If our current time sequence state is incompatible with the remote time sequence, kill it
if (currentlyInTimeSequence && remoteCurrentTimeSequence != currentTimeSequence
|| timeSequenceSecondsPassedRemote < timeSequenceSecondsPassed)
{
return;
currentlyInTimeSequence = false;
}
TimeSequenceExecuteFinalize(currentTimeSequence);
waitingForTimeSequenceFinalize = false;
// If we're not/no longer in a time sequence, start the remote's time sequence
if (!currentlyInTimeSequence)
{
StartTimeSequence(remoteCurrentTimeSequence);
}
// Jump our progress to match the one on the remote
TimeSequenceProgressToTime(timeSequenceSecondsPassedRemote);
}
//private void TimeSequenceSyncWithRemote(bool currentlyInTimeSequence, PacManTimeSequence currentTimeSequence, float timeSequenceSecondsPassed)
//{
// // If the remote is in a time sequence but we're not, or we're in a different time sequence, jump to the remote's time sequence.
// if (currentlyInTimeSequence && (!this.currentlyInTimeSequence || currentTimeSequence != this.currentTimeSequence))
// {
// StartTimeSequence(currentTimeSequence);
// }
// // If we're (now) in a time sequence, jump our progress to match the one on the remote
// if (this.currentlyInTimeSequence)
// {
// TimeSequenceProgressToTime(timeSequenceSecondsPassed);
// }
// // If the remote has finished it's time sequence and we have one waiting to be finalized, we can do so now
// if (!currentlyInTimeSequence)
// {
// TryFinalizeTimeSequence();
// }
//}
#region Events
public void JumpToTimeSequenceAttractScreenIntroduction()
@@ -244,7 +230,7 @@ namespace Marro.PacManUdon
private void TimeSequenceExecuteStep(PacManTimeSequence timeSequence, int sequenceProgress)
{
Debug.Log($"{gameObject} Triggered time sequence step for sequence {currentTimeSequence} with progress {sequenceProgress}");
//Debug.Log($"{gameObject} Triggered time sequence step for sequence {currentTimeSequence} with progress {sequenceProgress}");
switch (timeSequence)
{
default:
@@ -298,7 +284,7 @@ namespace Marro.PacManUdon
private void TimeSequenceExecuteFinalize(PacManTimeSequence timeSequence)
{
Debug.Log($"{gameObject} Triggered time sequence finalize for sequence {currentTimeSequence}");
//Debug.Log($"{gameObject} Triggered time sequence finalize for sequence {currentTimeSequence}");
switch (timeSequence)
{
default:
@@ -342,7 +328,7 @@ namespace Marro.PacManUdon
private void TimeSequenceExecuteFinished(PacManTimeSequence timeSequence)
{
Debug.Log($"{gameObject} Triggered time sequence finished for sequence {currentTimeSequence}");
//Debug.Log($"{gameObject} Triggered time sequence finished for sequence {currentTimeSequence}");
switch (timeSequence)
{
default:

View File

@@ -1147,19 +1147,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _nextDotSound
Data: alternatePelletSound
- Name: $v
Entry: 7
Data: 65|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _nextDotSound
Data: alternatePelletSound
- Name: <UserType>k__BackingField
Entry: 9
Data: 17
Entry: 7
Data: 66|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 17
Data: 66
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1174,7 +1180,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 66|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 67|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1195,25 +1201,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _ghostRetreating
Data: ghostRetreating
- Name: $v
Entry: 7
Data: 67|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 68|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _ghostRetreating
Data: ghostRetreating
- Name: <UserType>k__BackingField
Entry: 7
Data: 68|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
Entry: 9
Data: 66
- Name: <SystemType>k__BackingField
Entry: 9
Data: 68
Data: 66
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1249,19 +1249,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _ghostBlue
Data: ghostBlue
- Name: $v
Entry: 7
Data: 70|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _ghostBlue
Data: ghostBlue
- Name: <UserType>k__BackingField
Entry: 9
Data: 68
Data: 66
- Name: <SystemType>k__BackingField
Entry: 9
Data: 68
Data: 66
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1297,13 +1297,13 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _ghostSoundLevel
Data: ghostSoundLevel
- Name: $v
Entry: 7
Data: 72|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _ghostSoundLevel
Data: ghostSoundLevel
- Name: <UserType>k__BackingField
Entry: 7
Data: 73|System.RuntimeType, mscorlib
@@ -1351,19 +1351,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _currentlyPlayingSiren
Data: currentlyPlayingSiren
- Name: $v
Entry: 7
Data: 75|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _currentlyPlayingSiren
Data: currentlyPlayingSiren
- Name: <UserType>k__BackingField
Entry: 9
Data: 68
Data: 66
- Name: <SystemType>k__BackingField
Entry: 9
Data: 68
Data: 66
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1399,19 +1399,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: _suppress
Data: suppress
- Name: $v
Entry: 7
Data: 77|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: _suppress
Data: suppress
- Name: <UserType>k__BackingField
Entry: 9
Data: 68
Data: 66
- Name: <SystemType>k__BackingField
Entry: 9
Data: 68
Data: 66
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib

View File

@@ -1,9 +1,7 @@
using JetBrains.Annotations;
using Marro.PacManUdon;
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class SoundManager : SyncedObject
{
@@ -30,13 +28,13 @@ public class SoundManager : SyncedObject
[SerializeField] private AudioClip siren3;
[SerializeField] private AudioClip siren4;
private AudioClip _nextDotSound;
private bool _ghostRetreating;
private bool _ghostBlue;
private int _ghostSoundLevel;
private bool _currentlyPlayingSiren;
private bool alternatePelletSound;
private bool ghostRetreating;
private bool ghostBlue;
private int ghostSoundLevel;
private bool currentlyPlayingSiren;
private bool _suppress;
private bool suppress;
public void Initialize()
{
@@ -47,19 +45,19 @@ public class SoundManager : SyncedObject
{
StopAllSound();
_nextDotSound = pacDot2;
alternatePelletSound = false;
_ghostRetreating = false;
_ghostBlue = false;
_ghostSoundLevel = 0;
_currentlyPlayingSiren = false;
ghostRetreating = false;
ghostBlue = false;
ghostSoundLevel = 0;
currentlyPlayingSiren = false;
_suppress = true;
suppress = true;
}
public void SuppressSound(bool suppress)
{
_suppress = suppress;
this.suppress = suppress;
if (suppress)
{
@@ -79,8 +77,8 @@ public class SoundManager : SyncedObject
public void PlayPelletSound()
{
PlaySound(audioSourcePacMan, _nextDotSound);
_nextDotSound = _nextDotSound == pacDot1 ? pacDot2 : pacDot1;
PlaySound(audioSourcePacMan, alternatePelletSound ? pacDot2 : pacDot1);
alternatePelletSound = !alternatePelletSound;
}
public void PlayDeathSound()
@@ -115,13 +113,13 @@ public class SoundManager : SyncedObject
public void SetGhostBlue(bool isBlue)
{
_ghostBlue = isBlue;
ghostBlue = isBlue;
UpdateGhostSound();
}
public void SetGhostRetreat(bool isRetreating)
{
_ghostRetreating = isRetreating;
ghostRetreating = isRetreating;
UpdateGhostSound();
}
@@ -154,19 +152,19 @@ public class SoundManager : SyncedObject
// Debug.Log($"UpdatePelletCount: {pelletCount}, level: {level}");
if (_ghostSoundLevel >= level)
if (ghostSoundLevel >= level)
{
return;
}
_ghostSoundLevel = level;
ghostSoundLevel = level;
UpdateGhostSound();
}
private void PlaySound(AudioSource audioSource, AudioClip audioClip, bool loop = false)
{
// Debug.Log($"PlaySound, audioSource: {audioSource}, audioClip: {audioClip}, loop: {loop}, suppress: {_suppress}");
if (_suppress)
if (suppress)
{
return;
}
@@ -184,7 +182,7 @@ public class SoundManager : SyncedObject
private void SwitchSound(AudioSource audioSource, AudioClip audioClip, bool loop)
{
if (_suppress)
if (suppress)
{
return;
}
@@ -210,22 +208,22 @@ public class SoundManager : SyncedObject
private void UpdateGhostSound()
{
if (_ghostRetreating)
if (ghostRetreating)
{
PlaySound(audioSourceGhosts, pacGhostRetreat, true);
_currentlyPlayingSiren = false;
currentlyPlayingSiren = false;
return;
}
if (_ghostBlue)
if (ghostBlue)
{
PlaySound(audioSourceGhosts, pacGhostBlue, true);
_currentlyPlayingSiren = false;
currentlyPlayingSiren = false;
return;
}
var currentGhostLevelSound = GetSoundForGhostLevel(_ghostSoundLevel);
if (_currentlyPlayingSiren)
var currentGhostLevelSound = GetSoundForGhostLevel(ghostSoundLevel);
if (currentlyPlayingSiren)
{
SwitchSound(audioSourceGhosts, currentGhostLevelSound, true);
}
@@ -234,7 +232,7 @@ public class SoundManager : SyncedObject
PlaySound(audioSourceGhosts, currentGhostLevelSound, true);
}
_currentlyPlayingSiren = true;
currentlyPlayingSiren = true;
}
private AudioClip GetSoundForGhostLevel(int ghostLevel)
@@ -256,11 +254,23 @@ public class SoundManager : SyncedObject
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
data.Append(alternatePelletSound, ref index);
data.Append(ghostRetreating, ref index);
data.Append(ghostBlue, ref index);
data.AppendAsByte(ghostSoundLevel, ref index);
data.Append(currentlyPlayingSiren, ref index);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
alternatePelletSound = data.ReadBool(ref index);
ghostRetreating = data.ReadBool(ref index);
ghostBlue = data.ReadBool(ref index);
ghostSoundLevel = data.ReadByte(ref index);
currentlyPlayingSiren = data.ReadBool(ref index);
UpdateGhostSound();
return true;
}
}

View File

@@ -166,15 +166,5 @@ namespace Marro.PacManUdon
levelDisplayDigitAnimators[i].SetFloat("FruitType", PacManConstants.FruitTypeToValue(PacManConstants.GetFruitTypeForLevel(level - i)));
}
}
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
return true;
}
}
}

View File

@@ -1,6 +1,4 @@
using System.Collections;
using UdonSharp;
using UnityEngine;
using UdonSharp;
namespace Marro.PacManUdon
{
@@ -9,7 +7,9 @@ namespace Marro.PacManUdon
public NetworkManager networkManager;
public virtual void SyncedUpdate() { }
public abstract void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType);
public abstract bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType);
public virtual void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType) { }
public virtual bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType) { return false; }
protected void SubscribeToEvent(NetworkEventType eventType) => networkManager.SubscribeToEvent(this, eventType);
}
}

View File

@@ -1,63 +0,0 @@
namespace Marro.PacManUdon
{
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
enum Direction
{
Any,
Up,
Left,
Down,
Right
}
public class Teleporter : UdonSharpBehaviour
{
[SerializeField] private Direction direction = Direction.Any;
[SerializeField] private Transform target;
void OnTriggerEnter(Collider other)
{
GridMover gridMover = other.gameObject.GetComponent<GridMover>();
if (gridMover == null)
{
return;
}
switch (direction)
{
case Direction.Up:
if (gridMover.GetDirection().y < 0)
{
return;
}
break;
case Direction.Down:
if (gridMover.GetDirection().y > 0)
{
return;
}
break;
case Direction.Left:
if (gridMover.GetDirection().x > 0)
{
return;
}
break;
case Direction.Right:
if (gridMover.GetDirection().x < 0)
{
return;
}
break;
default:
break;
}
gridMover.SetPosition(gridMover.GetPosition() + (Vector2)(target.localPosition - transform.localPosition));
}
}
}

View File

@@ -1,14 +0,0 @@
namespace Marro.PacManUdon
{
using UdonSharp;
using UnityEngine;
public class Test : UdonSharpBehaviour
{
[SerializeField] Pellet pellet;
public void Start()
{
Debug.Log(pellet.enabled);
}
}
}

View File

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

View File

@@ -1,118 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: Test1
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 6457f9f1332ac0742bdff23291631f30, type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 0227a738d77ab0849bdc9047b5b27c78, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: -4571266787425106669
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: fieldDefinitions
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
UdonSharp.Editor]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
mscorlib]], mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: pellet
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pellet
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Pellet, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 4|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.Udon.UdonBehaviour, VRC.Udon
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 6|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

View File

@@ -1,65 +0,0 @@
// // Silly me for wanting to make the code neat, forgot this was Udon :)
// using System.Collections;
// using System.Collections.Generic;
// using UdonSharp;
// using UnityEngine;
// public abstract class TimeSequence : UdonSharpBehaviour
// {
// [UdonSynced] float secondsPassed;
// int sequenceProgress;
// float[] sequenceTimeSeconds;
// protected TimeSequence(float[] sequenceTimeSeconds)
// {
// sequenceProgress = 0;
// secondsPassed = 0;
// this.sequenceTimeSeconds = sequenceTimeSeconds;
// ProgressSequenceToTime(secondsPassed);
// }
// public void ProgressInTime(float deltaSeconds)
// {
// ProgressSequenceToTime(secondsPassed + deltaSeconds);
// }
// public void ProgressSequenceToTime(float seconds)
// {
// secondsPassed = seconds;
// while (secondsPassed >= sequenceTimeSeconds[sequenceProgress])
// {
// sequenceProgress += 1;
// SequenceStep(sequenceProgress);
// }
// }
// protected abstract void SequenceStep(int sequneceProgress);
// public static float[] DeltaToAbsolute(float[] delta)
// {
// if (delta.Length < 1)
// {
// return new float[0];
// }
// float[] absolute = new float[delta.Length];
// absolute[0] = delta[0];
// for (int i = 1; i < delta.Length; i++)
// {
// absolute[i] = delta[i] + absolute[i-1];
// }
// return absolute;
// }
// public int SequenceProgress
// {
// get => sequenceProgress;
// }
// public float SecondsPassed
// {
// get => secondsPassed;
// set => ProgressSequenceToTime(value);
// }
// }

View File

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

View File

@@ -10,17 +10,17 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: Teleporter
m_Name: MazeDefinitionGenerator
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 1589eb7cce8925e4da3272208dfa87f4, type: 2}
serializedUdonProgramAsset: {fileID: 11400000, guid: ea99e044f80fed446bb669640608f521, type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: aae1c5d18ae01b3488b54c72e6f1edf6, type: 3}
sourceCsScript: {fileID: 11500000, guid: 30a9bec71a4b36a41a9b6ee899bef38c, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: -7788394196284941649
scriptID: 1069201558343068808
serializationData:
SerializedFormat: 2
SerializedBytes:
@@ -49,19 +49,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: direction
Data: bonusFruit
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: direction
Data: bonusFruit
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Direction, Assembly-CSharp
Data: Marro.PacManUdon.BonusFruit, Assembly-CSharp
- Name:
Entry: 8
Data:
@@ -70,7 +70,7 @@ MonoBehaviour:
Data: 4|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32, mscorlib
Data: VRC.Udon.UdonBehaviour, VRC.Udon
- Name:
Entry: 8
Data:
@@ -91,13 +91,7 @@ MonoBehaviour:
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 6|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
Data: 0
- Name:
Entry: 13
Data:
@@ -115,25 +109,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: target
Data: pelletManager
- Name: $v
Entry: 7
Data: 7|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: target
Data: pelletManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 8|System.RuntimeType, mscorlib
Data: 7|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Transform, UnityEngine.CoreModule
Data: Marro.PacManUdon.CollisionManager, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 8
Data: 4
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -148,16 +142,10 @@ MonoBehaviour:
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 9|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 8|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 10|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
Data: 0
- Name:
Entry: 13
Data:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 896816ace5640c644bd057ab48c3b9a1
guid: 909752e684c57f24093795e3ba5e2c80
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

View File

@@ -0,0 +1,204 @@
using Marro.PacManUdon;
using UdonSharp;
using UnityEngine;
using UnityEngine.UIElements;
using VRC.SDKBase;
using VRC.Udon;
namespace Marro.PacManUdon.Dev
{
enum CollisionMap
{
Wall = 0x00,
Open = 0xFF,
Tunnel = 0x61,
HorizontalOnly = 0x56,
}
public class MazeDefinitionGenerator : UdonSharpBehaviour
{
public BonusFruit bonusFruit;
public CollisionManager pelletManager;
const int width = 32;
const int height = 32;
void Start()
{
PrintPelletMap();
PrintMazeMap();
}
private void PrintPelletMap()
{
var pellets = pelletManager.gameObject.GetComponentsInChildren<Pellet>(includeInactive: true);
int[] map = new int[width * height];
int[] pelletLocations = new int[pellets.Length];
for (int i = 0; i < map.Length; i++)
{
map[i] = (int)PacManConsumableType.None;
}
for (int i = 0; i < pellets.Length; i++)
{
Pellet pellet = pellets[i];
var position = GridMover.PositionToGrid(new Vector2(pellet.transform.localPosition.x, pellet.transform.localPosition.y));
var index = (int)position.x + (int)position.y * width;
map[index] = i;
pelletLocations[i] = index;
}
WriteBonusFruitTiles(map);
PrintMap(map, width);
PrintMap(pelletLocations, 16);
}
private void WriteBonusFruitTiles(int[] map)
{
var position = GridMover.PositionToGrid(new Vector2(bonusFruit.transform.localPosition.x, bonusFruit.transform.localPosition.y));
var leftTileIndex = CollisionManager.GetTilemapIndex(position);
map[leftTileIndex] = (int)PacManConsumableType.FruitLeft;
var rightTileIndex = leftTileIndex - 1;
map[rightTileIndex] = (int)PacManConsumableType.FruitRight;
}
private static void PrintMazeMap()
{
int[] map = new int[width * height];
var collisionMap = GetCollisionMap();
for (int i = 0; i < map.Length; i++)
{
byte result = 0;
var tile = GetTileAtIndex(collisionMap, i);
if (tile == (byte)CollisionMap.Wall)
{
result |= (byte)PacManCollisionInfoType.Wall;
}
if (tile == (byte)CollisionMap.Tunnel)
{
result |= (byte)PacManCollisionInfoType.Tunnel;
}
if (tile == (byte)CollisionMap.HorizontalOnly)
{
result |= (byte)PacManCollisionInfoType.HorizontalOnly;
}
result |= GetGhostTurnInformation(collisionMap, i, width, height);
map[i] = result;
}
PrintMap(map, width);
}
private static byte GetGhostTurnInformation(byte[] collisionMap, int i, int width, int height)
{
byte result = 0;
var totalAvailableDirections = 0;
if (GetTileAtIndex(collisionMap, GetTilemapIndex(i, Vector2.up, width, height)) != (byte)CollisionMap.Wall)
{
result |= (byte)Direction.Up;
totalAvailableDirections += 1;
}
if (GetTileAtIndex(collisionMap, GetTilemapIndex(i, Vector2.down, width, height)) != (byte)CollisionMap.Wall)
{
result |= (byte)Direction.Down;
totalAvailableDirections += 1;
}
if (GetTileAtIndex(collisionMap, GetTilemapIndex(i, Vector2.left, width, height)) != (byte)CollisionMap.Wall)
{
result |= (byte)Direction.Left;
totalAvailableDirections += 1;
}
if (GetTileAtIndex(collisionMap, GetTilemapIndex(i, Vector2.right, width, height)) != (byte)CollisionMap.Wall)
{
result |= (byte)Direction.Right;
totalAvailableDirections += 1;
}
if (totalAvailableDirections < 2
|| result == 0b0011 || result == 0b1100)
{
result |= (byte)PacManCollisionInfoType.NoTurn;
}
return result;
}
private static int GetTilemapIndex(int index, Vector2 direction, int width, int height)
{
var position = new Vector2(index % width, index / width) + direction;
var result = ((int)position.x + width) % width + ((int)position.y + height) % height * width;
return result;
}
private static void PrintMap(int[] map, int width)
{
var result = "";
for (int i = 0; i < map.Length; i++)
{
if (map[i] < 0)
{
result += $"{map[i]:00}, ";
}
else
{
result += $"{map[i]:000}, ";
}
if (i % width == width - 1)
{
result += "\n";
}
}
Debug.Log(result);
}
private static byte GetTileAtIndex(byte[] map, int index) => map[GetUpsideDownIndex(index)];
private static int GetUpsideDownIndex(int index) => (index % width) + (height - index / width - 1) * width;
public static byte[] GetCollisionMap() => new byte[] {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x56, 0xff, 0xff, 0x56, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x56, 0xff, 0xff, 0x56, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: aae1c5d18ae01b3488b54c72e6f1edf6
guid: 30a9bec71a4b36a41a9b6ee899bef38c
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -10,17 +10,17 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: PelletManager
m_Name: NetworkManagerSyncTester
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 9047ff9c4ab51104b8b0160387ad180b, type: 2}
serializedUdonProgramAsset: {fileID: 11400000, guid: b33acf2ffaef28f49ba36d29b13cf487, type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 71c8438dc95de4c44896841f1fece6b9, type: 3}
sourceCsScript: {fileID: 11500000, guid: cbbf384cde136444d9f640ff9f3445cf, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: 2205517818672966804
scriptID: -7942820763917989394
serializationData:
SerializedFormat: 2
SerializedBytes:
@@ -43,19 +43,19 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 9
Data: 10
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: networkManager
Data: networkManager1
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: networkManager
Data: networkManager1
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
@@ -91,7 +91,13 @@ MonoBehaviour:
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Data: 1
- Name:
Entry: 7
Data: 6|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
@@ -109,79 +115,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: <PelletCollectedCount>k__BackingField
Data: gridMovers1
- Name: $v
Entry: 7
Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 7|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <PelletCollectedCount>k__BackingField
Data: gridMovers1
- Name: <UserType>k__BackingField
Entry: 7
Data: 7|System.RuntimeType, mscorlib
Data: 8|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 7
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 8|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: pellets
- Name: $v
Entry: 7
Data: 9|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pellets
- Name: <UserType>k__BackingField
Entry: 7
Data: 10|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Pellet[], Assembly-CSharp
Data: Marro.PacManUdon.GridMover[], Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 11|System.RuntimeType, mscorlib
Data: 9|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
@@ -199,13 +151,19 @@ MonoBehaviour:
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 12|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 10|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Data: 1
- Name:
Entry: 7
Data: 11|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
@@ -223,25 +181,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: powerPellets
Data: networkManager2
- Name: $v
Entry: 7
Data: 13|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 12|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: powerPellets
Data: networkManager2
- Name: <UserType>k__BackingField
Entry: 7
Data: 14|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Animator[], UnityEngine.AnimationModule
- Name:
Entry: 8
Data:
Entry: 9
Data: 3
- Name: <SystemType>k__BackingField
Entry: 9
Data: 14
Data: 4
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -253,13 +205,19 @@ MonoBehaviour:
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 15|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 13|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Data: 1
- Name:
Entry: 7
Data: 14|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
@@ -277,25 +235,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: powerPelletBlinkEnabled
Data: gridMovers2
- Name: $v
Entry: 7
Data: 16|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 15|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: powerPelletBlinkEnabled
Data: gridMovers2
- Name: <UserType>k__BackingField
Entry: 7
Data: 17|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
Entry: 9
Data: 8
- Name: <SystemType>k__BackingField
Entry: 9
Data: 17
Data: 9
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -307,13 +259,19 @@ MonoBehaviour:
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 18|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 16|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Data: 1
- Name:
Entry: 7
Data: 17|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
@@ -331,25 +289,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: powerPelletBlinkToggleInterval
Data: debugImageToIndicateSynced
- Name: $v
Entry: 7
Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 18|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: powerPelletBlinkToggleInterval
Data: debugImageToIndicateSynced
- Name: <UserType>k__BackingField
Entry: 7
Data: 20|System.RuntimeType, mscorlib
Data: 19|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
Data: UnityEngine.Animator, UnityEngine.AnimationModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 20
Data: 19
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -361,13 +319,19 @@ MonoBehaviour:
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 21|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 20|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
Data: 1
- Name:
Entry: 7
Data: 21|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
@@ -385,19 +349,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: powerPelletBlinkProgress
Data: captureTimes
- Name: $v
Entry: 7
Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: powerPelletBlinkProgress
Data: captureTimes
- Name: <UserType>k__BackingField
Entry: 9
Data: 20
Entry: 7
Data: 23|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 20
Data: 23
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -412,7 +382,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 23|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 24|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -433,73 +403,31 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: powerPelletBlinkCurrentlyVisible
Data: positionCaptures
- Name: $v
Entry: 7
Data: 24|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: powerPelletBlinkCurrentlyVisible
Data: positionCaptures
- Name: <UserType>k__BackingField
Entry: 9
Data: 17
Entry: 7
Data: 26|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Vector2[][], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 17
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 25|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: syncedPelletsCollected
- Name: $v
Entry: 7
Data: 26|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: syncedPelletsCollected
- Name: <UserType>k__BackingField
Entry: 7
Data: 27|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Byte[], mscorlib
Data: System.Object[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 27
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -530,6 +458,156 @@ MonoBehaviour:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: ownerIndex
- Name: $v
Entry: 7
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: ownerIndex
- Name: <UserType>k__BackingField
Entry: 7
Data: 30|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 31|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: remoteIndex
- Name: $v
Entry: 7
Data: 32|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: remoteIndex
- Name: <UserType>k__BackingField
Entry: 9
Data: 30
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 33|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: previousCaptureTime
- Name: $v
Entry: 7
Data: 34|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: previousCaptureTime
- Name: <UserType>k__BackingField
Entry: 9
Data: 30
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 35|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 184e93443ec1bb24fa4e1db8b51405da
guid: bcf028de1e758ca45bcd8834df0b821c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

View File

@@ -0,0 +1,124 @@
using Marro.PacManUdon;
using Newtonsoft.Json.Linq;
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class NetworkManagerSyncTester : UdonSharpBehaviour
{
[SerializeField] NetworkManager networkManager1;
[SerializeField] GridMover[] gridMovers1;
[SerializeField] NetworkManager networkManager2;
[SerializeField] GridMover[] gridMovers2;
[SerializeField] Animator debugImageToIndicateSynced;
private int[] captureTimes = new int[1000];
private Vector2[][] positionCaptures = new Vector2[1000][];
private int ownerIndex = -1;
private int remoteIndex = 0;
private int previousCaptureTime = -1;
public void Update()
{
if (!networkManager1.Synced || !networkManager2.Synced)
{
ownerIndex = -1;
remoteIndex = 0;
return;
}
var ownerTime = networkManager1.SyncedTimeTicks;
if (ownerTime > previousCaptureTime)
{
IncrementIndex(ref ownerIndex);
captureTimes[ownerIndex] = ownerTime;
previousCaptureTime = ownerTime;
positionCaptures[ownerIndex] = GetPositions(gridMovers1);
}
var remoteTime = networkManager2.SyncedTimeTicks;
while (captureTimes[remoteIndex] < remoteTime && remoteIndex != ownerIndex)
{
DiscardCapture();
}
//Debug.Log($"ownerTime: {ownerTime}, remoteTime: {remoteTime}, ownerIndex: {ownerIndex} ({captureTimes[ownerIndex]}), remoteIndex: {remoteIndex} ({captureTimes[remoteIndex]})");
if (captureTimes[remoteIndex] == remoteTime)
{
bool equal = IsEqual(remoteIndex, remoteTime);
SetIndicator(equal);
DiscardCapture();
}
}
private void DiscardCapture()
{
positionCaptures[remoteIndex] = null;
IncrementIndex(ref remoteIndex);
}
private bool IsEqual(int index, int time)
{
var equal = true;
var positions1 = positionCaptures[index];
var positions2 = GetPositions(gridMovers2);
for (int i = 0; i < positions1.Length; i++)
{
var gridMover1 = gridMovers1[i];
var gridMover1Position = positions1[i];
var gridMover2 = gridMovers2[i];
var gridMover2Position = positions2[i];
if (gridMover1Position != gridMover2Position)
{
Debug.LogWarning($"{nameof(NetworkManagerSyncTester)} Desync found at {time} in {gridMover1.name}:\n {gridMover1Position} (local) != {gridMover2Position} (remote)");
//networkManager1.Pause();
//networkManager2.Pause();
equal = false;
}
}
return equal;
}
private void SetIndicator(bool value)
{
if (debugImageToIndicateSynced != null)
{
debugImageToIndicateSynced.SetFloat("Color", value ? 1 : 0);
}
}
private static Vector2[] GetPositions(GridMover[] gridMovers)
{
var length = gridMovers.Length;
var positions = new Vector2[length];
for (int i = 0; i < length; i++)
{
positions[i] = gridMovers[i].GetPosition();
}
return positions;
}
private void IncrementIndex(ref int index)
{
if (index >= positionCaptures.Length - 1)
{
index = 0;
}
else
{
index++;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f317309f5509067439e01d1111249555
guid: cbbf384cde136444d9f640ff9f3445cf
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,340 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: NetworkManagerTester
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 2a95858b6f853584c8e55a5140383df5, type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 8261cb80d1b7e5f45b0b9afd3f6bb801, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: 3371975218947168961
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: fieldDefinitions
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
UdonSharp.Editor]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
mscorlib]], mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 5
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: networkManagers
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: networkManagers
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.NetworkManager[], Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 4|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 6|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: interval
- Name: $v
Entry: 7
Data: 7|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: interval
- Name: <UserType>k__BackingField
Entry: 7
Data: 8|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 8
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 9|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 10|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: ownerIndex
- Name: $v
Entry: 7
Data: 11|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: ownerIndex
- Name: <UserType>k__BackingField
Entry: 7
Data: 12|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 12
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 13|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 14|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: countdown
- Name: $v
Entry: 7
Data: 15|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: countdown
- Name: <UserType>k__BackingField
Entry: 9
Data: 8
- Name: <SystemType>k__BackingField
Entry: 9
Data: 8
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 16|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: serializationRequested
- Name: $v
Entry: 7
Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: serializationRequested
- Name: <UserType>k__BackingField
Entry: 7
Data: 18|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 18
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 19|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c6e306d768eba5b469eea599abcf4800
guid: 46452140f2a4ee7458e4f4e13fea6578
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

View File

@@ -0,0 +1,99 @@
using Marro.PacManUdon;
using System;
using UdonSharp;
using UnityEngine;
public class NetworkManagerTester : UdonSharpBehaviour
{
[SerializeField] private NetworkManager[] networkManagers;
[SerializeField] private float interval = 0.1f;
[SerializeField] private int ownerIndex = 0;
private float countdown = 0;
private bool serializationRequested;
private void Start()
{
foreach (var networkManager in networkManagers)
{
networkManager.SetNetworkManagerTester(this);
if (networkManager.Ready)
{
networkManager.Reset();
}
}
}
private void FixedUpdate()
{
countdown -= Time.deltaTime;
if (countdown > 0)
{
return;
}
countdown = interval;
if (!serializationRequested)
{
return;
}
var source = networkManagers[ownerIndex];
var data = PerformSerialization(source);
//Debug.Log($"{nameof(NetworkManagerTester)} Transferring {data.Length} bytes.");
foreach (var target in networkManagers)
{
if (target == source)
{
continue;
}
PerformDeserialization(target, data);
}
serializationRequested = false;
}
private byte[] PerformSerialization(NetworkManager networkManager)
{
networkManager.OnPreSerialization();
var data = networkManager.NetworkedData;
networkManager.OnPostSerializationInternal(true, data.Length) ;
return data;
}
private byte[] PerformDeserialization(NetworkManager networkManager, byte[] data)
{
networkManager.NetworkedData = data;
networkManager.OnDeserialization();
return data;
}
public bool ShouldBeOwner(NetworkManager manager) => Array.IndexOf(networkManagers, manager) == ownerIndex;
public void RequestSerializationTest()
{
serializationRequested = true;
}
public void RequestEvent(NetworkEventType eventType)
{
foreach (var target in networkManagers)
{
if (!target.IsOwner || !target.SerializationRequested)
{
continue;
}
//Debug.Log($"{nameof(NetworkManagerTester)} Requested event with type {eventType}.");
target.RequestEventReceived(eventType);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 55d0efe8af4dba540a508287baca6656
guid: 8261cb80d1b7e5f45b0b9afd3f6bb801
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -6,6 +6,7 @@ using UnityEngine;
using UnityEngine.UI;
using VRC.SDKBase;
using VRC.Udon;
using UnityEngine.Tilemaps;
public class TestBallManager : UdonSharpBehaviour
{
@@ -49,7 +50,7 @@ public class TestBallManager : UdonSharpBehaviour
testBall.UpButtonPressed();
}
networkManager.SendEventSoon(NetworkEventType.PacManTurn);
networkManager.SendEventSoon(NetworkEventType.InputChange);
}
public void SyncButtonPressed()