Exemplo n.º 1
0
        public override void NetworkCreateObject(NetWorker networker, int identity, uint id, FrameStream frame, Action <NetworkObject> callback)
        {
            if (NetworkManager.Instance.IsMaster)
            {
                if (frame.Sender != null && frame.Sender != networker.Me)
                {
                    if (!ValidateCreateRequest(networker, identity, id, frame))
                    {
                        return;
                    }
                }
            }

            bool          availableCallback = false;
            NetworkObject obj = null;

            MainThreadManager.Run(() =>
            {
                switch (identity)
                {
                case ChatManagerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new ChatManagerNetworkObject(networker, id, frame);
                    break;

                case GameModeNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new GameModeNetworkObject(networker, id, frame);
                    break;

                case PlayerNetworkObject.IDENTITY:
                    availableCallback = true;
                    ///obj = new PlayerNetworkObject(networker, id, frame);
                    obj = new PlayerNetworkObject();
                    PlayerNetworkObject playerObj = (PlayerNetworkObject)obj;
                    playerObj.SetupUID((int)id, true);
                    break;

                case WeaponPickupNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new WeaponPickupNetworkObject(networker, id, frame);
                    break;
                }

                if (!availableCallback)
                {
                    base.NetworkCreateObject(networker, identity, id, frame, callback);
                }
                else if (callback != null)
                {
                    callback(obj);
                }
            });
        }
Exemplo n.º 2
0
        public void MatchmakingServersFromMasterServer(string masterServerHost,
                                                       ushort masterServerPort,
                                                       int elo,
                                                       System.Action <MasterServerResponse> callback = null,
                                                       string gameId   = "myGame",
                                                       string gameType = "any",
                                                       string gameMode = "all")
        {
            // The Master Server communicates over TCP
            TCPMasterClient client = new TCPMasterClient();

            // Once this client has been accepted by the master server it should send it's get request
            client.serverAccepted += (sender) =>
            {
                try
                {
                    // Create the get request with the desired filters
                    JSONNode  sendData = JSONNode.Parse("{}");
                    JSONClass getData  = new JSONClass();
                    getData.Add("id", gameId);
                    getData.Add("type", gameType);
                    getData.Add("mode", gameMode);
                    getData.Add("elo", new JSONData(elo));

                    sendData.Add("get", getData);

                    // Send the request to the server
                    client.Send(Text.CreateFromString(client.Time.Timestep, sendData.ToString(), true, Receivers.Server, MessageGroupIds.MASTER_SERVER_GET, true));
                }
                catch
                {
                    // If anything fails, then this client needs to be disconnected
                    client.Disconnect(true);
                    client = null;

                    MainThreadManager.Run(() =>
                    {
                        if (callback != null)
                        {
                            callback(null);
                        }
                    });
                }
            };

            // An event that is raised when the server responds with hosts
            client.textMessageReceived += (player, frame, sender) =>
            {
                try
                {
                    // Get the list of hosts to iterate through from the frame payload
                    JSONNode data = JSONNode.Parse(frame.ToString());
                    MainThreadManager.Run(() =>
                    {
                        if (data["hosts"] != null)
                        {
                            MasterServerResponse response = new MasterServerResponse(data["hosts"].AsArray);
                            if (callback != null)
                            {
                                callback(response);
                            }
                        }
                        else
                        {
                            if (callback != null)
                            {
                                callback(null);
                            }
                        }
                    });
                }
                finally
                {
                    if (client != null)
                    {
                        // If we succeed or fail the client needs to disconnect from the Master Server
                        client.Disconnect(true);
                        client = null;
                    }
                }
            };

            try
            {
                client.Connect(masterServerHost, masterServerPort);
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.Message);
                MainThreadManager.Run(() =>
                {
                    if (callback != null)
                    {
                        callback(null);
                    }
                });
            }
        }
Exemplo n.º 3
0
        private void ReadBinary(NetworkingPlayer player, Binary frame, NetWorker sender)
        {
            if (frame.GroupId == MessageGroupIds.VIEW_INITIALIZE)
            {
                if (Networker is IServer)
                {
                    return;
                }

                int count = frame.StreamData.GetBasicType <int>();

                loadedScenes.Clear();
                for (int i = 0; i < count; i++)
                {
                    loadedScenes.Add(frame.StreamData.GetBasicType <int>());
                }

                MainThreadManager.Run(() =>
                {
                    if (loadedScenes.Count == 0)
                    {
                        return;
                    }

                    SceneManager.LoadScene(loadedScenes[0], LoadSceneMode.Single);

                    for (int i = 1; i < loadedScenes.Count; i++)
                    {
                        SceneManager.LoadSceneAsync(loadedScenes[i], LoadSceneMode.Additive);
                    }
                });

                return;
            }

            if (frame.GroupId != MessageGroupIds.VIEW_CHANGE)
            {
                return;
            }

            if (Networker.IsServer)
            {
                // The client has loaded the scene
                if (playerLoadedScene != null)
                {
                    playerLoadedScene(player, Networker);
                }

                return;
            }

            // We need to halt the creation of network objects until we load the scene
            Networker.PendCreates = true;

            // Get the scene index that the server loaded
            int sceneIndex = frame.StreamData.GetBasicType <int>();

            // Get the mode in which the server loaded the scene
            int modeIndex = frame.StreamData.GetBasicType <int>();

            // Convert the int mode to the enum mode
            LoadSceneMode mode = (LoadSceneMode)modeIndex;

            if (networkSceneChanging != null)
            {
                networkSceneChanging(sceneIndex, mode);
            }

            MainThreadManager.Run(() =>
            {
                // Load the scene that the server loaded in the same LoadSceneMode
                if (mode == LoadSceneMode.Additive)
                {
                    SceneManager.LoadSceneAsync(sceneIndex, LoadSceneMode.Additive);
                }
                else if (mode == LoadSceneMode.Single)
                {
                    SceneManager.LoadScene(sceneIndex, LoadSceneMode.Single);
                }
            });
        }
Exemplo n.º 4
0
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is ChatManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ChatManagerNetworkObject.Length > 0 && ChatManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ChatManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ChatManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is CubeForgeGameNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (CubeForgeGameNetworkObject.Length > 0 && CubeForgeGameNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(CubeForgeGameNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <CubeForgeGameBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ExampleProximityPlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ExampleProximityPlayerNetworkObject.Length > 0 && ExampleProximityPlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ExampleProximityPlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ExampleProximityPlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is MovementHeadNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (MovementHeadNetworkObject.Length > 0 && MovementHeadNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(MovementHeadNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <MovementHeadBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is NetworkCameraNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (NetworkCameraNetworkObject.Length > 0 && NetworkCameraNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(NetworkCameraNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkCameraBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerNetworkObject.Length > 0 && PlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is TestNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (TestNetworkObject.Length > 0 && TestNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(TestNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <TestBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Exemplo n.º 5
0
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is ChatManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ChatManagerNetworkObject.Length > 0 && ChatManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ChatManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is CubeForgeGameNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (CubeForgeGameNetworkObject.Length > 0 && CubeForgeGameNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(CubeForgeGameNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ExampleProximityPlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ExampleProximityPlayerNetworkObject.Length > 0 && ExampleProximityPlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ExampleProximityPlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is GameStateManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GameStateManagerNetworkObject.Length > 0 && GameStateManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GameStateManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is GuyWithMovementNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GuyWithMovementNetworkObject.Length > 0 && GuyWithMovementNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GuyWithMovementNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is InputListenerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (InputListenerNetworkObject.Length > 0 && InputListenerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(InputListenerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is NetworkCameraNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (NetworkCameraNetworkObject.Length > 0 && NetworkCameraNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(NetworkCameraNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Exemplo n.º 6
0
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is GameManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GameManagerNetworkObject.Length > 0 && GameManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GameManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <GameManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is InputListenerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (InputListenerNetworkObject.Length > 0 && InputListenerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(InputListenerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <InputListenerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerNetworkObject.Length > 0 && PlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Exemplo n.º 7
0
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is AnimTestObjNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (AnimTestObjNetworkObject.Length > 0 && AnimTestObjNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(AnimTestObjNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <AnimTestObjBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ChatManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ChatManagerNetworkObject.Length > 0 && ChatManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ChatManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ChatManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ExampleProximityPlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ExampleProximityPlayerNetworkObject.Length > 0 && ExampleProximityPlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ExampleProximityPlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ExampleProximityPlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is FlameAttacckNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (FlameAttacckNetworkObject.Length > 0 && FlameAttacckNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(FlameAttacckNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <FlameAttacckBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is GameModeNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GameModeNetworkObject.Length > 0 && GameModeNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GameModeNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <GameModeBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerNetworkObject.Length > 0 && PlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is TestNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (TestNetworkObject.Length > 0 && TestNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(TestNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <TestBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ThrowObjNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ThrowObjNetworkObject.Length > 0 && ThrowObjNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ThrowObjNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ThrowObjBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Exemplo n.º 8
0
        private void Start()
        {
            NetworkObject.objectCreated += (obj) =>
            {
                if (obj.CreateCode < 0)
                {
                    return;
                }

                if (obj is ChatManagerNetworkObject)
                {
                    MainThreadManager.Run(() =>
                    {
                        NetworkBehavior newObj = null;
                        if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                        {
                            if (ChatManagerNetworkObject.Length > 0 && ChatManagerNetworkObject[obj.CreateCode] != null)
                            {
                                var go = Instantiate(ChatManagerNetworkObject[obj.CreateCode]);
                                newObj = go.GetComponent <NetworkBehavior>();
                            }
                        }

                        if (newObj == null)
                        {
                            return;
                        }

                        newObj.Initialize(obj);

                        if (objectInitialized != null)
                        {
                            objectInitialized(newObj, obj);
                        }
                    });
                }
                else if (obj is CubeForgeGameNetworkObject)
                {
                    MainThreadManager.Run(() =>
                    {
                        NetworkBehavior newObj = null;
                        if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                        {
                            if (CubeForgeGameNetworkObject.Length > 0 && CubeForgeGameNetworkObject[obj.CreateCode] != null)
                            {
                                var go = Instantiate(CubeForgeGameNetworkObject[obj.CreateCode]);
                                newObj = go.GetComponent <NetworkBehavior>();
                            }
                        }

                        if (newObj == null)
                        {
                            return;
                        }

                        newObj.Initialize(obj);

                        if (objectInitialized != null)
                        {
                            objectInitialized(newObj, obj);
                        }
                    });
                }
                else if (obj is ExampleProximityPlayerNetworkObject)
                {
                    MainThreadManager.Run(() =>
                    {
                        NetworkBehavior newObj = null;
                        if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                        {
                            if (ExampleProximityPlayerNetworkObject.Length > 0 && ExampleProximityPlayerNetworkObject[obj.CreateCode] != null)
                            {
                                var go = Instantiate(ExampleProximityPlayerNetworkObject[obj.CreateCode]);
                                newObj = go.GetComponent <NetworkBehavior>();
                            }
                        }

                        if (newObj == null)
                        {
                            return;
                        }

                        newObj.Initialize(obj);

                        if (objectInitialized != null)
                        {
                            objectInitialized(newObj, obj);
                        }
                    });
                }
                else if (obj is NetworkCameraNetworkObject)
                {
                    MainThreadManager.Run(() =>
                    {
                        NetworkBehavior newObj = null;
                        if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                        {
                            if (NetworkCameraNetworkObject.Length > 0 && NetworkCameraNetworkObject[obj.CreateCode] != null)
                            {
                                var go = Instantiate(NetworkCameraNetworkObject[obj.CreateCode]);
                                newObj = go.GetComponent <NetworkBehavior>();
                            }
                        }

                        if (newObj == null)
                        {
                            return;
                        }

                        newObj.Initialize(obj);

                        if (objectInitialized != null)
                        {
                            objectInitialized(newObj, obj);
                        }
                    });
                }
            };
        }