Пример #1
0
    void UpdateAsHost()
    {
        Vector3 world = GetMousePoint();

        // move mouse cursor object to that position
        thisMouse.transform.position = world;

        // keep track of my mouse position in the list of mice sent to guests
        miceTracker.Track(playerId, new Vec2d {
            X = world.x, Y = world.y
        });

        // get a list of only mice that have changed position
        Mice mice = miceTracker.BuildMice();

        if (mice != null)
        {
            // send changed mice to guests
            MiceChangeMessage mcm = new MiceChangeMessage
            {
                Payload = mice
            };
            stateFluxClient.SendRequest(mcm);

            // move mouse cursor gameobjects
            foreach (Mouse m in mice.Items)
            {
                SetPlayerMouseDetails(m);
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (stateFluxClient.isHosting)
            {
                SendHostFloobieCommand();
            }
            ChangeTracker changeTracker = CreateJake(world, thisPlayer.Color, circler);
            gameObjectTracker.TrackCreate(changeTracker);
        }
    }
Пример #2
0
        // coroutine that sends out the HostStateChangeMessage messages
        // sends changes to mouse pos and tracked objects to the server, every 50 milliseconds
        public IEnumerator SendStateAsHost()
        {
            while (true)
            {
                List <Change2d> changes   = new List <Change2d>();
                List <string>   removeIds = new List <string>();
                foreach (ChangeTracker changeTracker in trackingMap.Values.Where(t => t.dirty))
                {
                    changeTracker.dirty = false;

                    if (changeTracker.create != null)
                    {
                        //DebugLog($"Adding change tracker for {changeTracker.create.ObjectID}");
                        changes.Add(changeTracker.create);
                        changeTracker.create = null;
                    }
                    else if (changeTracker.destroy != null)
                    {
                        //DebugLog($"Removing change tracker for {changeTracker.destroy.ObjectID}");
                        changes.Add(changeTracker.destroy);
                        removeIds.Add(changeTracker.destroy.ObjectID);
                        changeTracker.destroy = null;
                    }
                    else
                    {
                        //DebugLog($"Updating change tracker for {changeTracker.update.ObjectID}");
                        changes.Add(changeTracker.update);
                    }
                }

                foreach (string objectId in removeIds)
                {
                    trackingMap.Remove(objectId);
                }

                if (changes.Count > 0)
                {
                    // the server forwards host state change messages to all guests
                    Message message = new HostStateChangeMessage()
                    {
                        Payload = new StateChange
                        {
                            Changes = changes
                        }
                    };
                    stateFluxClient.SendRequest(message);
                }

                yield return(new WaitForSeconds(0.1f));
            }
        }