Exemplo n.º 1
0
        protected override void NetworkStart()
        {
            base.NetworkStart();

            OwningNetWorker.AddCustomDataReadEvent(WriteCustomMapping.NETWORKING_MANAGER_PLAYER_LOADED_LEVEL, PlayerLoadedLevel, true);
            OwningNetWorker.AddCustomDataReadEvent(WriteCustomMapping.NETWORKED_MONO_BEHAVIOR_MANUAL_PROPERTIES, DeserializeManualProperties, true);
            OwningNetWorker.AddCustomDataReadEvent(WriteCustomMapping.TRANSPORT_OBJECT, ReadTransportObject, true);

            if (loadLevelFireOnConnect != null)
            {
                loadLevelFireOnConnect();
                loadLevelFireOnConnect = null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method is used to do all of the initial setup of objects
        /// </summary>
        public bool Populate(NetWorker socket)
        {
            List <SimpleNetworkedMonoBehavior> allBehaviors = new List <SimpleNetworkedMonoBehavior>(startNetworkedSceneBehaviors);

            // Find all objects in the scene that have SNMB
            SimpleNetworkedMonoBehavior[] behaviors = FindObjectsOfType <SimpleNetworkedMonoBehavior>();

            foreach (SimpleNetworkedMonoBehavior behavior in behaviors)
            {
                if (!allBehaviors.Contains(behavior))
                {
                    allBehaviors.Add(behavior);
                }
            }

            if (Networking.Sockets == null)
            {
                Debug.LogWarning("No connection has been established for this network scene, preparing offline play...");
                IsSetup = true;

                foreach (Action execute in setupActions)
                {
                    execute();
                }

                return(false);
            }

            ControllingSocket = socket;
            OwningNetWorker   = ControllingSocket;

            if (!OwningNetWorker.Connected)
            {
                NetWorker.BasicEvent handler = null;

                handler = () =>
                {
                    SetupObjects(allBehaviors.ToArray(), OwningNetWorker);

                    foreach (Action execute in setupActions)
                    {
                        execute();
                    }

                    OwningNetWorker.connected -= handler;
                };

                OwningNetWorker.connected += handler;
            }
            else
            {
                SetupObjects(allBehaviors.ToArray(), OwningNetWorker);

                foreach (Action execute in setupActions)
                {
                    execute();
                }
            }

            OwningNetWorker.AddCustomDataReadEvent(WriteCustomMapping.NETWORKING_MANAGER_POLL_PLAYERS, PollPlayersResponse, true);

            return(true);
        }