Пример #1
0
        public void OnFNPlayerDisconnected(IClientMockPlayer player)
        {
            LobbyPlayer convertedPlayer = GrabPlayer(player);

            MainThreadManager.Run(() =>
            {
                if (LobbyPlayers.Contains(convertedPlayer))
                {
                    _lobbyPlayers.Remove(convertedPlayer);
                    _lobbyPlayersMap.Remove(convertedPlayer.NetworkId);

                    LobbyPlayerItem item = GrabLobbyPlayerItem(convertedPlayer);
                    if (item != null)
                    {
                        PutBackToPool(item);
                    }
                }
            });
        }
Пример #2
0
    private void Awake()
    {
        if (Instance != null)
        {
            Destroy(gameObject);
            return;
        }

        Instance = this;
        MainThreadManager.Create();
        DontDestroyOnLoad(gameObject);

        foreach (var kvp in Prefabs)
        {
            Manager.GetType()
            .GetField(kvp.Key.ToString() + "NetworkObject")
            .SetValue(Manager, kvp.Value.data);
        }
    }
Пример #3
0
    //RCP
    public override void GenerateWorld(RpcArgs args)
    {
        MainThreadManager.Run(() =>
        {
            UnityEngine.Random.InitState(args.GetNext <int>());

            grid = new Assets.BlockGrid(levelWidth, levelHeight,
                                        new Vector2((destroyableWallBlock.transform.localScale.x * levelWidth),
                                                    (destroyableWallBlock.transform.localScale.z * levelHeight)));

            splits = SplitLevels();

            if (buildBlocks)
            {
                BuildBlocks(splits);
                SpawnLoot(splits);
            }
        });
    }
        private void Awake()
        {
            // Init the MainThreadManager if it has not been already
            MainThreadManager.Create();

            // Store a reference to the Multiplayer menu
            mpMenu = this.GetComponentInParent <SteamworksMultiplayerMenu>();
            serverListEntryTemplateHeight = ((RectTransform)serverListEntryTemplate.transform).rect.height;

            // Disable the connect button until the user has selected a server
            connectButton.interactable = false;

            SteamMatchmaking.OnLobbyDataChanged  += OnLobbyDataUpdated;
            SteamMatchmaking.OnLobbyMemberJoined += OnLobbyMemberJoined;
            SteamMatchmaking.OnLobbyMemberLeave  += OnLobbyMemberLeave;

            // Request the initial lobby list
            GetAvailableLobbyList();
        }
Пример #5
0
    private void DisconnectedFromServer(NetWorker sender)
    {
        NetworkManager.Instance.Networker.disconnected -= DisconnectedFromServer;

        MainThreadManager.Run(() =>
        {
            foreach (var no in sender.NetworkObjectList)
            {
                if (no.Owner.IsHost)
                {
                    BMSLogger.Instance.Log("Server disconnected");
                    //Should probably make some kind of "You disconnected" screen. ah well
                    UnityEngine.SceneManagement.SceneManager.LoadScene(0);
                }
            }

            NetworkManager.Instance.Disconnect();
        });
    }
        public virtual void InitializeDefaults()
        {
            MainThreadManager.Create();
            if (!_settings.UseTCP)
            {
                NetWorker.PingForFirewall(_settings.ServerAddress.Port);
            }

            if (_settings.UseMainThreadManagerForRPCs && Rpc.MainThreadRunner == null)
            {
                Rpc.MainThreadRunner = MainThreadManager.Instance;
            }

            UnityObjectMapper.Instance.UseAsDefault();
            if (NetworkObject.Factory == null)
            {
                NetworkObject.Factory = new NetworkObjectFactory();
            }
        }
Пример #7
0
    // Use this for initialization
    void Start()
    {
        //safety check lol
        if (!NetworkManager.Instance.IsMaster)
        {
            return;
        }

        NetworkManager.Instance.Networker.playerAccepted += (player, sender) =>
        {
            MainThreadManager.Run(() =>
            {
                //Do some counting logic here for a gamemode, eg, assign team to newly joined player, or restart round if enough people joined
                //Remember to remove players from counter in playerDisconnected event as well
            });
        };

        //Handle disconnection
        NetworkManager.Instance.Networker.playerDisconnected += (player, sender) =>
        {
            MainThreadManager.Run(() =>
            {
                NetworkObject networkObjectToDestroy = null;
                //Loop through all players and find the player who disconnected
                foreach (var no in sender.NetworkObjectList)
                {
                    if (no.Owner == player)
                    {
                        //Found him
                        networkObjectToDestroy = no;
                    }
                }

                //Remove the actual network object outside of the foreach loop, as we would modify the collection at runtime elsewise. (could also use a return, too late)
                if (networkObjectToDestroy != null)
                {
                    sender.NetworkObjectList.Remove(networkObjectToDestroy);
                    networkObjectToDestroy.Destroy();
                }
            });
        };
    }
Пример #8
0
        public void OnPlayerDisconnected(NetworkingPlayer player, NetWorker netWorker)
        {
            MainThreadManager.Run(() =>
            {
                //Loop through all players and find the player who disconnected, store all it's networkobjects to a list
                var objectsToDelete = netWorker.NetworkObjectList.Where(networkedObject => networkedObject.Owner == player).ToList();

                if (objectsToDelete.Count <= 0)
                {
                    return;
                }

                //iterate backwards to ensure indexing does not go out of bounds
                for (var i = objectsToDelete.Count - 1; i >= 0; i--)
                {
                    netWorker.NetworkObjectList.Remove(objectsToDelete[i]);
                    objectsToDelete[i].Destroy();
                }
            });
        }
Пример #9
0
    protected override void NetworkStart()
    {
        base.NetworkStart();

        if (networkObject.IsServer)
        {
            networkObject.SpawnPos1 = spawnPos1.transform.position;
            networkObject.SpawnPos2 = spawnPos2.transform.position;
            MainThreadManager.Run(() =>
            {
                MovableObjectBehavior go  = NetworkManager.Instance.InstantiateMovableObject(0, position: networkObject.SpawnPos1);
                go.networkObject.position = networkObject.SpawnPos1;

                MovableObjectBehavior obj  = NetworkManager.Instance.InstantiateMovableObject(1, position: Vector3.zero);
                obj.networkObject.position = Vector3.zero;
            });

            NetworkManager.Instance.Networker.playerAccepted += NewPlayer;
        }
    }
Пример #10
0
        private void Awake()
        {
            // Init the MainThreadManager if it has not been already
            MainThreadManager.Create();

            // Store a reference to the Multiplayer menu
            mpMenu = this.GetComponentInParent <SteamworksMultiplayerMenu>();
            serverListEntryTemplateHeight = ((RectTransform)serverListEntryTemplate.transform).rect.height;

            // Disable the connect button until the user has selected a server
            connectButton.interactable = false;

            // Make sure steam callbacks are set
            callbackLobbyListRequest = Callback <LobbyMatchList_t> .Create(OnLobbyListRequested);

            callbackLobbyDataUpdate = Callback <LobbyDataUpdate_t> .Create(OnLobbyDataUpdated);

            // Request the initial lobby list
            GetAvailableLobbyList();
        }
Пример #11
0
        public static ServiceCallback <RPCCreateNetworkSceneInNode, ServiceCallbackStateEnum> CreateNetworkSceneInNode(uint pSourceNodeId, uint pTargetNodeId, NetworkSceneTemplate pTemplate, bool pAutoAssignIp, bool pAutoAssignPort, byte[] pNetworkSceneMetaData)
        {
            ServiceCallback <RPCCreateNetworkSceneInNode, ServiceCallbackStateEnum> callback = new ServiceCallback <RPCCreateNetworkSceneInNode, ServiceCallbackStateEnum>(0, pSourceNodeId, GameTime.fixedTime);

            if (pTemplate == null)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_NO_DATA;
                return(callback);
            }

            if (!IsInitialized)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_SERVICE_NOT_INITIALIZED;
                return(callback);
            }

            if (Instance.Manager == null || !Instance.Manager.HasNetworker || !Instance.Manager.Networker.IsConnected)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_NO_CONNECTION;
                return(callback);
            }

            RPCCreateNetworkSceneInNode requestData = new RPCCreateNetworkSceneInNode()
            {
                targetNodeId = pTargetNodeId, template = pTemplate.ToRPC(), autoAssignIp = pAutoAssignIp, autoAssignPort = pAutoAssignPort, networkSceneMetaData = pNetworkSceneMetaData
            };

            callback.RequestDataOfT = requestData;
            callback.State          = ServiceCallbackStateEnum.AWAITING_RESPONSE;
            Instance.AddPendingServiceCallback(callback);
            MainThreadManager.Run(() => {
                if (!IsInitialized || Instance.networkObject == null)
                {
                    return;
                }

                Instance.networkObject.SendRpc(RPC_RELAY_CREATE_NETWORK_SCENE_IN_NODE, Receivers.Server, callback.ToByteArray());
            });

            return(callback);
        }
Пример #12
0
        private void Start()
        {
            localPlayer = NetworkManager.Instance.InstantiatePlayer() as NetworkedPlayer;

            NetworkManager.Instance.Networker.disconnected += (sender) =>
            {
                MainThreadManager.Run(() =>
                {
                    SceneManager.LoadScene(1);
                });
            };

            if (!NetworkManager.Instance.IsServer)
            {
                return;
            }

            NetworkManager.Instance.Networker.playerDisconnected += (player, networker) =>
            {
                MainThreadManager.Run(() =>
                {
                    List <NetworkObject> toDelete = new List <NetworkObject>();
                    foreach (var obj in networker.NetworkObjectList)
                    {
                        if (obj.Owner == player)
                        {
                            toDelete.Add(obj);
                        }
                    }

                    if (toDelete.Count > 0)
                    {
                        for (int i = toDelete.Count - 1; i >= 0; i--)
                        {
                            networker.NetworkObjectList.Remove(toDelete[i]);
                            toDelete[i].Destroy();
                        }
                    }
                });
            };
        }
Пример #13
0
        private void VOIPWorker()
        {
            while (Socket.IsConnected)
            {
                if (writeFlushTimer >= WRITE_FLUSH_TIME && writeSamples.Count > 0)
                {
                    writeFlushTimer = 0.0f;
                    lock (writeSamples)
                    {
                        writeBuffer.Clone(ToByteArray(writeSamples));
                        writeSamples.Clear();
                    }

                    Binary voice = new Binary(Socket.Time.Timestep, false, writeBuffer, Receivers.All, MessageGroupIds.VOIP, false);

                    ((BaseUDP)Socket).Send(voice);
                }

                MainThreadManager.ThreadSleep(10);
            }
        }
    void Networker_playerAccepted(NetworkingPlayer pPlayer, NetWorker pSender)
    {
        MainThreadManager.Run(() => {
            if (NetworkManager.Instance == null)
            {
                return;
            }

            InputListenerPlayerBehavior playerBehavior = NetworkManager.Instance.InstantiateInputListenerPlayer();
            if (playerBehavior == null)
            {
                return;
            }

            pPlayer.disconnected += (networker) => {
                playerBehavior.networkObject.Destroy();
            };

            playerBehavior.networkObject.ownerId = pPlayer.NetworkId;
        });
    }
Пример #15
0
    private void SetupPlayer(NetworkingPlayer np, string name, ulong customization)
    {
        MainThreadManager.Run(() => {
            int playerCount = m_LobbyPlayers.Count;

            LobbyPlayer player = NetworkManager.Instance.InstantiateLobbyPlayer() as LobbyPlayer;

            player.networkStarted += (NetworkBehavior behavior) =>
            {
                // Position setup
                player.UpdatePosition(playerCount);

                // Customization setup
                player.SetCustomization(customization);

                // Name setup
                player.UpdateName(name);
            };

            m_LobbyPlayers.Add(np, player);
        });
    }
Пример #16
0
    public override void Server_TakeDamage(RpcArgs args)
    {
        //this is the arg setup in the wizard
        int damage = args.GetNext <int>();

        int damageDealt = Mathf.Min(damage, networkObject.health);

        MainThreadManager.Run(() =>
        {
            if (networkObject != null)
            {
                //networkObject.health -= damageDealt;
                health -= damageDealt;
            }


            if (networkObject.health <= 0)
            {
                OnDeath();
            }
        });
    }
Пример #17
0
    ////////////////////
    ///
    /// HOST-ONLY CODE
    ///
    ////////////////////

    // Callback for when scene has loaded for all players
    public void OnSceneLoaded(Dictionary <NetworkingPlayer, PlayerDetails> detailsMap)
    {
        if (!networkObject.IsServer)
        {
            return;
        }

        // Run on main thread to send RPC.
        MainThreadManager.Run(() =>
        {
            // Set total player count
            networkObject.SendRpc(RPC_SET_PLAYER_COUNT, Receivers.All, detailsMap.Count);
        });

        // Host spawns all players
        NetworkManager.Instance.Networker.IteratePlayers(np =>
        {
            SpawnPlayer(np, detailsMap[np]);
        });

        AetherNetworkManager.Instance.SceneLoaded -= OnSceneLoaded;
    }
Пример #18
0
    private void Networker_playerAccepted(NetworkingPlayer player, NetWorker sender)
    {
        MainThreadManager.Run(() =>
        {
            Debug.Log("player accepted");
            GameObject[] spawnPoints = GameObject.FindGameObjectsWithTag("Spawn Point");

            Vector3 spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)].transform.position;
            Debug.Log("Found spawn points");

            //PlayerController playerController = NetworkManager.Instance.InstantiatePlayer(position: spawnPoint) as PlayerController;
            NewCharacterController playerController = NetworkManager.Instance.InstantiatePlayer(position: spawnPoint) as NewCharacterController;

            playerController.networkObject.position = spawnPoint;
            playerController.networkObject.AssignOwnership(player);

            //Debug.Log("Player Count: " + NetworkManager.Instance.Networker.Players.Count);
            NetworkManager.Instance.UpdateMasterServerListing(NetworkManager.Instance.Networker, "Opus", "BattleRoyale", "Solo");

            Debug.Log("Player Connected: " + player.Ip);
        });
    }
Пример #19
0
        protected override void NetworkStart()
        {
            base.NetworkStart();

            if (NetworkManager.Instance.IsServer)
            {
                NetworkManager.Instance.Networker.playerAccepted += (player, sender) =>
                {
                    // Instantiate the player on the main Unity thread, get the Id of its owner and add it to a list of players
                    MainThreadManager.Run(() =>
                    {
                        Debug.Log("Player : trying to instantiate");
                        PlayerBehavior p = NetworkManager.Instance.InstantiatePlayer();
                        Debug.Log("Player : Instantiated");
                        p.networkObject.ownerNetId = player.NetworkId;
                        Debug.Log("Player : ID " + p.networkObject.ownerNetId);
                        _playerObjects.Add(player.NetworkId, p);
                        Debug.Log("Player : added to the list ");
                    });
                };

                NetworkManager.Instance.Networker.playerDisconnected += (player, sender) =>
                {
                    // Remove the player from the list of players and destroy it
                    //PlayerBehavior p = _playerObjects[player.NetworkId];
                    PlayerBehavior p = _playerObjects[player.NetworkId];
                    _playerObjects.Remove(player.NetworkId);
                    p.networkObject.Destroy();
                };
            }
            else
            {
                // This is a local client - it needs to listen for input
                NetworkManager.Instance.InstantiateInputListener();
            }

            _networkReady = true;
        }
Пример #20
0
    public override void ModifyMoodBar(RpcArgs args)
    {
        float fillValue = args.GetNext <float>();

        MainThreadManager.Run(() =>
        {
            patientWorldspaceMoodBar.SetActive(true);
            patientWorldspaceMoodBar.GetComponent <Canvas>().enabled = true;

            switch (fillValue)
            {
            case 1:
                moodImg.sprite   = angry;
                moodBarText.text = "Angry";
                break;

            case 2:
                moodImg.sprite   = anxious;
                moodBarText.text = "Anxious";
                break;

            case 3:
                moodImg.sprite   = confused;
                moodBarText.text = "Confused";
                break;

            case 4:
                moodImg.sprite   = embarassed;
                moodBarText.text = "Embarassed";
                break;

            case 5:
                moodImg.sprite   = calm;
                moodBarText.text = "Calm";
                break;
            }
        });
    }
Пример #21
0
    public void Init(NetWorker server, ServerConfig config, RPCPackager rpcPackager)
    {
        Instance     = this;
        m_server     = (UDPServer)server;
        Players      = new Dictionary <string, PlayerModel>();
        MaxPlayers   = config.MaxPlayers;
        RPCInterface = new ServerInterface(rpcPackager);

        m_server.playerTimeout += (player, sender) =>
        {
            Debug.Log($"Player: {player.NetworkId} timed out.");
        };

        m_server.playerConnected += (player, sender) =>
        {
            PlayerConnected(player);
        };

        m_server.playerGuidAssigned += (player, sender) =>
        {
            Debug.Log($"Player: {player.NetworkId} assigned GUID: {player.InstanceGuid}");
        };

        m_server.playerAccepted += (player, sender) =>
        {
            MainThreadManager.Run(() => { PlayerAccepted(player); });
        };

        m_server.playerRejected += (player, sender) =>
        {
            Debug.Log($"Player: {player.NetworkId} rejected.");
        };

        m_server.playerDisconnected += (player, sender) =>
        {
            PlayerDisconnected(player);
        };
    }
        private void OnDisconnect(NetWorker sender)
        {
            MainThreadManager.Run(() =>
            {
                foreach (var netObject in sender.NetworkObjectList)
                {
                    if (netObject.Owner.IsHost)
                    {
                        BMSLog.Log("Server disconnected");
                        // Go back to the multiplayer menu
                        SceneManager.LoadScene(1);
                    }
                }
            });

            if (NetworkManager.Instance == null)
            {
                return;
            }

            NetworkManager.Instance.Networker.disconnected -= OnDisconnect;
            NetworkManager.Instance.Disconnect();
        }
Пример #23
0
    protected override void NetworkStart()
    {
        base.NetworkStart();

        if (networkObject.IsServer)
        {
            //Add player spawning code.
            //When a player joins, a cube is spawned with that player's ID assigned to the prefab
            NetworkManager.Instance.Networker.playerAccepted += (player) =>
            {
                MainThreadManager.Run(() =>
                {
                    var go  = NetworkManager.Instance.InstantiateGuyWithMovement(position: new Vector3(0, 0.1f, 0));
                    var guy = go.GetComponent <GuyWithMovement>();
                    guy.networkObject.inputOwnerId = player.NetworkId;
                });
            };
        }

        else
        {
            NetworkManager.Instance.InstantiateInputListener();
        }
    }
Пример #24
0
    public override void Server_AnnounceDeath(RpcArgs args)
    {
        MainThreadManager.Run(() =>
        {
            if (NetworkManager.Instance != null && NetworkManager.Instance.IsServer)
            {
                return;
            }

            string dyingPlayer   = args.GetNext <string>();
            string killingPlayer = args.GetNext <string>();

            //Debug.Log("dying player: " + dyingPlayer + " killingPlayer: " + killingPlayer);

            GameObject go = Instantiate(DeathUI_Announcement_prefab, GlobalGameUI.GetComponent <GameUI>().playersKilledScrollBoxContent.transform);
            Canvas.ForceUpdateCanvases();
            GlobalGameUI.GetComponent <GameUI>().playersKilledScrollBox.normalizedPosition = new Vector2(0, 0);

            PlayerKilledUI pkilled = go.GetComponent <PlayerKilledUI>();
            pkilled.UpdateUI(dyingPlayer, killingPlayer);

            Destroy(go, DEATH_UI_MESSAGE_TIMER);
        });
    }
Пример #25
0
    public override void RemovePlayer(RpcArgs args)
    {
        uint id       = args.GetNext <uint>();
        int  position = 0;

        for (int i = 0; i < leaderboard.Count; i++)
        {
            if (leaderboard[i].id == id)
            {
                GameObject objectToDestory = leaderboard[i].playerEntry;
                MainThreadManager.Run(() =>
                {
                    lock (leaderboard)
                    {
                        Destroy(objectToDestory);
                    }
                });
                Debug.Log("Removed Player with ID of " + id);
                position = i;
            }
        }

        leaderboard.RemoveAt(position);
    }
Пример #26
0
    private void Start()
    {
        var gC = FindObjectOfType <GameController>();

        networkController = (NetworkController)gC.GetController(typeof(NetworkController)) as NetworkController;
        if (!networkController)
        {
            BMSLog.LogWarning("Could not find networkController - should not see me");
        }

        // Init the MainThreadManager
        MainThreadManager.Create();

        playButton.enabled            = false;
        playerListEntryTemplateHeight = ((RectTransform)playerListEntryTemplate.transform).rect.height;
        RefreshPlayers();
        SetLobbyEvents();
        if (!networkController.GetIsHost())
        {
            LoadedAsClient();
        }

        GetLobby();
    }
Пример #27
0
 private void DestroyGameObject(NetWorker sender)
 {
     MainThreadManager.Run(() => { try { Destroy(gameObject); } catch { } });
     networkObject.onDestroy -= DestroyGameObject;
 }
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (TowerCaptureNetworkControllerNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("UpdateCaptureControllerOnNetwork", UpdateCaptureControllerOnNetwork);
            networkObject.RegisterRpc("UpdateCaptureOnNetwork", UpdateCaptureOnNetwork, typeof(uint), typeof(bool));
            networkObject.RegisterRpc("UpdateCapturesTimesOnNetwork", UpdateCapturesTimesOnNetwork, typeof(byte[]));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
Пример #29
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (GameModeNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("AllPlayersLeaveLobby", AllPlayersLeaveLobby);
            networkObject.RegisterRpc("PickRandomTerrainSeed", PickRandomTerrainSeed, typeof(string));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
Пример #30
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (PlayerNetworkManagerNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("SetPlayerCount", SetPlayerCount, typeof(int));
            networkObject.RegisterRpc("SetClientReady", SetClientReady, typeof(string));
            networkObject.RegisterRpc("SetAllReady", SetAllReady);
            networkObject.RegisterRpc("TriggerGameOver", TriggerGameOver, typeof(uint));
            networkObject.RegisterRpc("SetGameOver", SetGameOver, typeof(uint));
            networkObject.RegisterRpc("SignalPlayerDisconnected", SignalPlayerDisconnected, typeof(uint));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    bool changePos      = (transformFlags & 0x01) != 0;
                    bool changeRotation = (transformFlags & 0x02) != 0;
                    if (changePos || changeRotation)
                    {
                        MainThreadManager.Run(() =>
                        {
                            if (changePos)
                            {
                                transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            }
                            if (changeRotation)
                            {
                                transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                            }
                        });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                gameObject.SetActive(true);
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }