Example #1
0
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int remotePlayersSynced = 0;

            foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData)
            {
                waitScreenItem.SetProgress(remotePlayersSynced, packet.RemotePlayerData.Count);

                List <TechType> equippedTechTypes = playerData.EquippedTechTypes.Select(techType => techType.ToUnity()).ToList();
                RemotePlayer    player            = remotePlayerManager.Create(playerData.PlayerContext, equippedTechTypes);

                if (playerData.SubRootId.HasValue)
                {
                    Optional <GameObject> sub = NitroxEntity.GetObjectFrom(playerData.SubRootId.Value);

                    if (sub.HasValue)
                    {
                        Log.Debug($"sub value set to {sub.Value}. Try to find subroot");
                        SubRoot subroot = null;
                        sub.Value.TryGetComponent <SubRoot>(out subroot);
                        if (subroot != null)
                        {
                            Log.Debug("Found subroot for player. Will add him and update animation.");
                            player.SetSubRoot(subroot);
                            // Set the animation for the remote player to standing instead of swimming if player is not in a flooded subroot
                            if (!subroot.IsUnderwater(player.Body.transform.position))
                            {
                                player.UpdateAnimation(AnimChangeType.UNDERWATER, AnimChangeState.OFF);
                            }
                        }
                        Log.Debug("Trying to find escape pod.");
                        EscapePod escapePod = null;
                        sub.Value.TryGetComponent <EscapePod>(out escapePod);
                        if (escapePod != null)
                        {
                            Log.Debug("Found escape pod for player. Will add him and update animation.");
                            player.UpdateAnimation(AnimChangeType.UNDERWATER, AnimChangeState.OFF);
                        }
                    }
                    else
                    {
                        Log.Error("Could not spawn remote player into subroot/escape pod with id: " + playerData.SubRootId.Value);
                    }
                }

                remotePlayersSynced++;
                yield return(null);
            }
        }
        public override IEnumerator Process(InitialPlayerSync packet, WaitScreen.ManualWaitItem waitScreenItem)
        {
            int remotePlayersSynced = 0;

            foreach (InitialRemotePlayerData playerData in packet.RemotePlayerData)
            {
                waitScreenItem.SetProgress(remotePlayersSynced, packet.RemotePlayerData.Count);

                List <TechType> equippedTechTypes = playerData.EquippedTechTypes.Select(techType => techType.ToUnity()).ToList();

                RemotePlayer player = remotePlayerManager.Create(playerData.PlayerContext, playerData.SubRootId, equippedTechTypes, new List <Pickupable>());

                if (!IsSwimming(playerData.Position.ToUnity(), playerData.SubRootId))
                {
                    player.UpdateAnimation(AnimChangeType.UNDERWATER, AnimChangeState.OFF);
                }
                remotePlayersSynced++;
                yield return(null);
            }
        }