Exemple #1
0
        public void Lock(MyEntityIdentifier entityId, bool enable)
        {
            if (IsHost)
            {
                // Host just sends lock to all
                bool success = TryLockEntity(entityId.NumericValue, MyEntityIdentifier.CurrentPlayerId, enable);

                if (success)
                {
                    LogDevelop(MyEntities.GetEntityById(entityId).Name + " " + (enable ? "LOCKED" : "UNLOCKED"));
                }

                MyEntity entity;
                if (enable && MyEntities.TryGetEntityById(entityId, out entity))
                {
                    RaiseLockResponse(entity, success);
                }
            }
            else
            {
                // Send request to host
                MyEventLock msg = new MyEventLock();
                msg.EntityId = entityId.NumericValue;
                msg.LockType = enable ? MyLockEnum.LOCK : MyLockEnum.UNLOCK;

                // Sometimes can be called after host already disconnected (closing screens etc)
                Peers.TrySendHost(ref msg);
            }
        }