예제 #1
0
 public void Set(LobbyModificationSetPermissionLevelOptions other)
 {
     if (other != null)
     {
         m_ApiVersion    = LobbyModification.LobbymodificationSetpermissionlevelApiLatest;
         PermissionLevel = other.PermissionLevel;
     }
 }
예제 #2
0
    /// <summary>
    /// Creates a lobby based on given parameters using Epic Online Services.
    /// <para>You can get the data that was added to the lobby by subscribing to the <see cref="CreateLobbySucceeded"/> event which gives you a list of <see cref="Attribute"/>.</para>
    /// <para>This process may throw errors. You can get errors by subscribing to the <see cref="CreateLobbyFailed"/> event.</para>
    /// </summary>
    /// <param name="maxConnections">The maximum amount of connections the lobby allows.</param>
    /// <param name="permissionLevel">The restriction on the lobby to prevent unwanted people from joining.</param>
    /// <param name="presenceEnabled">Use Epic's overlay to display information to others.</param>
    /// <param name="lobbyData">Optional data that you can to the lobby. By default, there is an empty attribute for searching and an attribute which holds the host's network address.</param>
    public virtual void CreateLobby(uint maxConnections, LobbyPermissionLevel permissionLevel, bool presenceEnabled, AttributeData[] lobbyData = null)
    {
        EOSSDKComponent.GetLobbyInterface().CreateLobby(new CreateLobbyOptions {
            //lobby options
            LocalUserId     = EOSSDKComponent.LocalUserProductId,
            MaxLobbyMembers = maxConnections,
            PermissionLevel = permissionLevel,
            PresenceEnabled = presenceEnabled,
        }, null, (CreateLobbyCallbackInfo callback) => {
            List <Attribute> lobbyReturnData = new List <Attribute>();

            //if the result of CreateLobby is not successful, invoke an error event and return
            if (callback.ResultCode != Result.Success)
            {
                CreateLobbyFailed?.Invoke("There was an error while creating a lobby. Error: " + callback.ResultCode);
                return;
            }

            //create mod handle and lobby data
            LobbyModification modHandle = new LobbyModification();
            AttributeData defaultData   = new AttributeData {
                Key = DefaultAttributeKey, Value = DefaultAttributeKey
            };
            AttributeData hostAddressData = new AttributeData {
                Key = hostAddressKey, Value = EOSSDKComponent.LocalUserProductIdString
            };

            //set the mod handle
            EOSSDKComponent.GetLobbyInterface().UpdateLobbyModification(new UpdateLobbyModificationOptions {
                LobbyId = callback.LobbyId, LocalUserId = EOSSDKComponent.LocalUserProductId
            }, out modHandle);

            //add attributes
            modHandle.AddAttribute(new LobbyModificationAddAttributeOptions {
                Attribute = defaultData, Visibility = LobbyAttributeVisibility.Public
            });
            modHandle.AddAttribute(new LobbyModificationAddAttributeOptions {
                Attribute = hostAddressData, Visibility = LobbyAttributeVisibility.Public
            });

            //add user attributes
            if (lobbyData != null)
            {
                foreach (AttributeData data in lobbyData)
                {
                    modHandle.AddAttribute(new LobbyModificationAddAttributeOptions {
                        Attribute = data, Visibility = LobbyAttributeVisibility.Public
                    });
                    lobbyReturnData.Add(new Attribute {
                        Data = data, Visibility = LobbyAttributeVisibility.Public
                    });
                }
            }

            //update the lobby
            EOSSDKComponent.GetLobbyInterface().UpdateLobby(new UpdateLobbyOptions {
                LobbyModificationHandle = modHandle
            }, null, (UpdateLobbyCallbackInfo updateCallback) => {
                //if there was an error while updating the lobby, invoke an error event and return
                if (updateCallback.ResultCode != Result.Success)
                {
                    CreateLobbyFailed?.Invoke("There was an error while updating the lobby. Error: " + updateCallback.ResultCode);
                    return;
                }

                LobbyDetails details;
                EOSSDKComponent.GetLobbyInterface().CopyLobbyDetailsHandle(new CopyLobbyDetailsHandleOptions {
                    LobbyId = callback.LobbyId, LocalUserId = EOSSDKComponent.LocalUserProductId
                }, out details);

                ConnectedLobbyDetails = details;
                isLobbyOwner          = true;
                ConnectedToLobby      = true;
                currentLobbyId        = callback.LobbyId;

                //invoke event
                CreateLobbySucceeded?.Invoke(lobbyReturnData);
            });
        });
    }
        /// <summary>
        /// Async CreateLobby
        /// </summary>
        /// <param name="lobby">LobbyInterface</param>
        /// <param name="localUserId">Login user id</param>
        /// <param name="maxLobbyMembers">Max member count</param>
        /// <param name="permissionLevel">Public settings, etc.</param>
        /// <returns>Task</returns>
        public static async UniTask <CreateLobbyCallbackInfo> CreateLobby(this LobbyInterface lobby, ProductUserId localUserId, uint maxLobbyMembers, LobbyPermissionLevel permissionLevel)
        {
            var lobbyOp = new CreateLobbyOptions
            {
                LocalUserId     = localUserId,
                MaxLobbyMembers = maxLobbyMembers,
                PermissionLevel = permissionLevel,
            };
            CreateLobbyCallbackInfo info = null;

            lobby.CreateLobby(lobbyOp, null, e =>
            {
                info = e;
            });
            while (info == null)
            {
                await UniTask.NextFrame();
            }

            if (info.ResultCode == Result.Success)
            {
                return(info);
            }
            Debug.LogError($"error {DebugTools.GetClassMethodName()}:{info.ResultCode}");
            return(null);
        }