private void OnTreeDestroyed() { if (execContext != null) { execContext.Post((a) => TreeDestroyed?.Invoke(this, EventArgs.Empty), null); } else { TreeDestroyed?.Invoke(this, EventArgs.Empty); } }
/// <param name="p"></param> private async void ReceiveMatchStateHandle(Packet p) { // Outgoing messages can be async but absolutely everything in have to be ran on the main thread // (few exceptions: pure computing functions ...) await UniTask.SwitchToMainThread(); switch (p.TypeCase) { case Packet.TypeOneofCase.MatchJoin: Debug.Log($"Received match information {p.MatchJoin}"); seed = p.MatchJoin.Seed; region = p.MatchJoin.Region; break; case Packet.TypeOneofCase.UpdateTransform: TransformUpdated?.Invoke(p.UpdateTransform.Transform); break; case Packet.TypeOneofCase.NavMeshUpdate: NavMeshUpdated?.Invoke(p.NavMeshUpdate); break; case Packet.TypeOneofCase.RequestSpawn: switch (p.RequestSpawn.TypeCase) { case Spawn.TypeOneofCase.Any: break; case Spawn.TypeOneofCase.Tree: TreeSpawnRequested?.Invoke(p.RequestSpawn.Tree.Transform); break; case Spawn.TypeOneofCase.Animal: AnimalSpawnRequested?.Invoke(p.RequestSpawn.Animal.Transform); break; case Spawn.TypeOneofCase.None: break; default: throw new ArgumentOutOfRangeException(); } break; case Packet.TypeOneofCase.RequestDestroy: switch (p.RequestDestroy.TypeCase) { case Realtime.Destroy.TypeOneofCase.Any: break; case Realtime.Destroy.TypeOneofCase.Tree: TreeDestroyRequested?.Invoke(p.RequestDestroy.Tree.Transform); break; case Realtime.Destroy.TypeOneofCase.Animal: AnimalDestroyRequested?.Invoke(p.RequestDestroy.Animal.Transform); break; case Realtime.Destroy.TypeOneofCase.None: break; default: throw new ArgumentOutOfRangeException(); } break; case Packet.TypeOneofCase.Spawn: switch (p.Spawn.TypeCase) { case Spawn.TypeOneofCase.Any: break; case Spawn.TypeOneofCase.Tree: TreeSpawned?.Invoke(p.Spawn.Tree.Transform); break; case Spawn.TypeOneofCase.Animal: AnimalSpawned?.Invoke(p.Spawn.Animal.Transform); break; case Spawn.TypeOneofCase.None: break; default: throw new ArgumentOutOfRangeException(); } break; case Packet.TypeOneofCase.Destroy: switch (p.Destroy.TypeCase) { case Realtime.Destroy.TypeOneofCase.Any: break; case Realtime.Destroy.TypeOneofCase.Animal: AnimalDestroyed?.Invoke(p.Destroy.Animal.Transform); break; case Realtime.Destroy.TypeOneofCase.Tree: TreeDestroyed?.Invoke(p.Destroy.Tree.Transform); break; case Realtime.Destroy.TypeOneofCase.None: break; default: throw new ArgumentOutOfRangeException(); } break; case Packet.TypeOneofCase.Meme: MemeUpdated?.Invoke(p.Meme); break; case Packet.TypeOneofCase.Initialized: Initialized?.Invoke(p.SenderId); break; case Packet.TypeOneofCase.None: break; default: throw new ArgumentOutOfRangeException(); } }