当前位置: 首页 > news >正文

wordpress 小工具插件网站建设快照优化

wordpress 小工具插件,网站建设快照优化,企业建设微网站的重要性,重庆网站建设招聘信息p22 这节课把创建,查找,加入游戏房间的菜单类,以及插件内的系统类给补完了.说实话这节课有点绕,因为需要一直使用委托进行传值,先由菜单类Menu向系统类Subsystem发送函数传值请求,然后监听Subsystem的委托回调,同时系统类Subsystem向Session的工具发送请求,监听回调,再返回给M…p22 这节课把创建,查找,加入游戏房间的菜单类,以及插件内的系统类给补完了.说实话这节课有点绕,因为需要一直使用委托进行传值,先由菜单类Menu向系统类Subsystem发送函数传值请求,然后监听Subsystem的委托回调,同时系统类Subsystem向Session的工具发送请求,监听回调,再返回给Menu类进行传值. MultiPlayerSessionSubsystem.h // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include CoreMinimal.h #include Subsystems/GameInstanceSubsystem.h #include Interfaces/OnlineSessionInterface.h #include MultiPlayerSessionSubsystem.generated.h /** * 这里是我们自定义的委托 */ DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiPlayerOnCreateSessionComplete ,bool, bWasSuccessful); DECLARE_MULTICAST_DELEGATE_TwoParams(FMultiPlayerOnFindSessionComplete, const TArrayFOnlineSessionSearchResult SessionSearchResult , bool bWasSuccessful); DECLARE_MULTICAST_DELEGATE_OneParam(FMultiPlayerOnJoinSessionComplete, EOnJoinSessionCompleteResult::Type Result); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiPlayerOnDestroySessionComplete ,bool, bWasSuccessful); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMultiPlayerOnStartSessionComplete ,bool, bWasSuccessful); UCLASS() class UMultiPlayerSessionSubsystem : public UGameInstanceSubsystem { GENERATED_BODY() public: UMultiPlayerSessionSubsystem(); /* * 这里是一个句柄,让菜单类可以访问Subsystem */ void CreateSession(int32 NumPublicConnections,FString MatchType); void FindSession(int32 MaxSearchResults); void JoinSession(const FOnlineSessionSearchResult SessionResults); void DestroySession(); void StartSession(); /* * 这是给菜单类做的回调委托 */ FMultiPlayerOnCreateSessionComplete MultiPlayerOnCreateSessionComplete; FMultiPlayerOnFindSessionComplete MultiPlayerOnFindSessionComplete; FMultiPlayerOnJoinSessionComplete MultiPlayerOnJoinSessionComplete; FMultiPlayerOnDestroySessionComplete MultiPlayerOnDestroySessionComplete; FMultiPlayerOnStartSessionComplete MultiPlayerOnStartSessionComplete; protected: /* * 这里是委托 */ void CreateSessionComplete(FName SessionName, bool bWasSuccessful); void FindSessionsComplete(bool bWasSuccessful); void JoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result); void DestroySessionComplete(FName SessionName, bool bWasSuccessful); void StartSessionComplete(FName SessionName, bool bWasSuccessful); private: //查找会话设置 TSharedPtrFOnlineSessionSearch LastSessionSearch; IOnlineSessionPtr OnlineSessionInterface; TSharedPtrFOnlineSessionSettings LastSessionSettings; /* * 添加OnlineSession委托到列表内 * 我们的游玩系统内部回调绑定到这里 * */ FOnCreateSessionCompleteDelegate CreateSessionCompleteDelegate; FDelegateHandle CreateSessionCompleteDelegate_Handle; FOnFindSessionsCompleteDelegate FindSessionsCompleteDelegate; FDelegateHandle FindSessionsCompleteDelegate_Handle; FOnJoinSessionCompleteDelegate JoinSessionCompleteDelegate; FDelegateHandle JoinSessionCompleteDelegate_Handle; FOnDestroySessionCompleteDelegate DestroySessionCompleteDelegate; FDelegateHandle DestroySessionCompleteDelegate_Handle; FOnStartSessionCompleteDelegate StartSessionCompleteDelegate; FDelegateHandle StartSessionCompleteDelegate_Handle; }; MultiPlayerSessionSubsystem.cpp // Fill out your copyright notice in the Description page of Project Settings. #include MultiPlayerSessionSubsystem.h #include OnlineSessionSettings.h #include OnlineSubsystem.h #include Online/OnlineSessionNames.h UMultiPlayerSessionSubsystem::UMultiPlayerSessionSubsystem(): CreateSessionCompleteDelegate(FOnCreateSessionCompleteDelegate::CreateUObject(this,ThisClass::CreateSessionComplete)), FindSessionsCompleteDelegate(FOnFindSessionsCompleteDelegate::CreateUObject(this,ThisClass::FindSessionsComplete)), JoinSessionCompleteDelegate(FOnJoinSessionCompleteDelegate::CreateUObject(this,ThisClass::JoinSessionComplete)), DestroySessionCompleteDelegate(FOnDestroySessionCompleteDelegate::CreateUObject(this,ThisClass::DestroySessionComplete)), StartSessionCompleteDelegate(FOnStartSessionCompleteDelegate::CreateUObject(this,ThisClass::StartSessionComplete)) { IOnlineSubsystem* OnlineSubsystem IOnlineSubsystem::Get(); if(OnlineSubsystem) { OnlineSessionInterface OnlineSubsystem-GetSessionInterface(); } } void UMultiPlayerSessionSubsystem::CreateSession(int32 NumPublicConnections, FString MatchType) { if(!OnlineSessionInterface.IsValid()) { return; } auto ExistingSession OnlineSessionInterface-GetNamedSession(NAME_GameSession); if(ExistingSession ! nullptr) { OnlineSessionInterface-DestroySession(NAME_GameSession); } //存放创建委托 CreateSessionCompleteDelegate_Handle OnlineSessionInterface-AddOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegate); LastSessionSettings MakeShareable(new FOnlineSessionSettings()); LastSessionSettings-bIsLANMatch IOnlineSubsystem::Get()-GetSubsystemName() NULL ? true:false; //最多4人 LastSessionSettings-NumPublicConnections NumPublicConnections; //允许其他玩家加入 LastSessionSettings-bAllowJoinInProgress true; //允许好友加入 LastSessionSettings-bAllowJoinViaPresence true; //线上公开 LastSessionSettings-bShouldAdvertise true; //显示用户状态 LastSessionSettings-bUsesPresence true; //使用第三方平台 LastSessionSettings-bUseLobbiesIfAvailable true; LastSessionSettings-Set(FName(MatchType),MatchType,EOnlineDataAdvertisementType::ViaOnlineServiceAndPing); const ULocalPlayer* LocalPlayer GetWorld()-GetFirstLocalPlayerFromController(); if(OnlineSessionInterface-CreateSession(*LocalPlayer-GetPreferredUniqueNetId(), NAME_GameSession , *LastSessionSettings)) { /*这里是创建失败*/ OnlineSessionInterface-ClearOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegate_Handle); /*在这里广播*/ MultiPlayerOnCreateSessionComplete.Broadcast(false); } } void UMultiPlayerSessionSubsystem::FindSession(int32 MaxSearchResults) { if(!OnlineSessionInterface.IsValid()) { return; } //这里将我们的委托设置成SessionInterface的句柄使用 FindSessionsCompleteDelegate_Handle OnlineSessionInterface-AddOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegate); //添加查询委托 OnlineSessionInterface-AddOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegate); //设置查找 LastSessionSearch MakeShareable(new FOnlineSessionSearch()); LastSessionSearch-MaxSearchResults 10000; LastSessionSearch-bIsLanQuery LastSessionSettings-bIsLANMatch IOnlineSubsystem::Get()-GetSubsystemName() NULL ? true:false; //设置查询设置 LastSessionSearch-QuerySettings.Set(SEARCH_PRESENCE,true,EOnlineComparisonOp::Equals); //获得本地的第一个玩家 const ULocalPlayer* LocalPlayer GetWorld()-GetFirstLocalPlayerFromController(); //使用本地的第一个玩家的URL和查找设置进行查找,当查找为false或者空的时候删除句柄 if(!OnlineSessionInterface-FindSessions(*LocalPlayer-GetPreferredUniqueNetId(),LastSessionSearch.ToSharedRef())) { //删除掉句柄 OnlineSessionInterface-ClearOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegate_Handle); MultiPlayerOnFindSessionComplete.Broadcast(TArrayFOnlineSessionSearchResult(),false); } } void UMultiPlayerSessionSubsystem::JoinSession(const FOnlineSessionSearchResult SessionResults) { if(!OnlineSessionInterface.IsValid()) { MultiPlayerOnJoinSessionComplete.Broadcast(EOnJoinSessionCompleteResult::UnknownError); return; } JoinSessionCompleteDelegate_Handle OnlineSessionInterface-AddOnJoinSessionCompleteDelegate_Handle(JoinSessionCompleteDelegate); //获得本地的第一个玩家 const ULocalPlayer* LocalPlayer GetWorld()-GetFirstLocalPlayerFromController(); //调用JoinSession,并且加入的时候调用OnJoinSessionCompleteDelegate这个委托 if(!OnlineSessionInterface-JoinSession(*LocalPlayer-GetPreferredUniqueNetId(),NAME_GameSession,SessionResults)) { MultiPlayerOnJoinSessionComplete.Broadcast(EOnJoinSessionCompleteResult::UnknownError); } } void UMultiPlayerSessionSubsystem::DestroySession() { } void UMultiPlayerSessionSubsystem::StartSession() { } void UMultiPlayerSessionSubsystem::CreateSessionComplete(FName SessionName, bool bWasSuccessful) { /*当成功创建房间的时候,删除创建房间的句柄*/ if(OnlineSessionInterface) { OnlineSessionInterface-ClearOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegate_Handle); } MultiPlayerOnCreateSessionComplete.Broadcast(bWasSuccessful); } void UMultiPlayerSessionSubsystem::FindSessionsComplete(bool bWasSuccessful) { if(OnlineSessionInterface) { OnlineSessionInterface-ClearOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegate_Handle); } if(LastSessionSearch-SearchResults.Num()0) { //找到了玩家后删除掉句柄 OnlineSessionInterface-ClearOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegate_Handle); return; } MultiPlayerOnFindSessionComplete.Broadcast(LastSessionSearch-SearchResults,bWasSuccessful); } void UMultiPlayerSessionSubsystem::JoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result) { if(OnlineSessionInterface) { OnlineSessionInterface-ClearOnJoinSessionCompleteDelegate_Handle(JoinSessionCompleteDelegate_Handle); } MultiPlayerOnJoinSessionComplete.Broadcast(Result); } void UMultiPlayerSessionSubsystem::DestroySessionComplete(FName SessionName, bool bWasSuccessful) { } void UMultiPlayerSessionSubsystem::StartSessionComplete(FName SessionName, bool bWasSuccessful) { } BaseMenu.h // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include CoreMinimal.h #include Blueprint/UserWidget.h #include Interfaces/OnlineSessionInterface.h #include BaseMenu.generated.h /** * */ class UButton; UCLASS() class MULTIPLAYERSESSION_API UBaseMenu : public UUserWidget { GENERATED_BODY() protected: virtual bool Initialize() override; virtual void NativeDestruct() override; /*这里创建用来对应MultiPlayerOnCreateSessionComplete的函数*/ UFUNCTION() void OnCreateSession(bool bWasSuccessful); void OnFindSession(const TArrayFOnlineSessionSearchResult SessionSearchResult , bool bWasSuccessful); void OnJoinSession(EOnJoinSessionCompleteResult::Type Result); UFUNCTION() void OnDestroySession(bool bWasSuccessful); UFUNCTION() void OnStartSession(bool bWasSuccessful); public: UFUNCTION(BlueprintCallable) void MenuSetup(int SetupNumPublicConnections 4,FString SetupMatchType TEXT(FreeForAll)); void _DebugLog(FColor DisplayColor, const FString DebugMessage); private: //将指针与按钮绑定起来,这里的绑定必须要指针变量名称和UMG的名称完全一样 UPROPERTY(meta(BindWidget)) UButton* HostButton; UPROPERTY(meta(BindWidget)) UButton* JoinButton; UFUNCTION() void HostButtonClicked(); UFUNCTION() void JoinButtonClincked(); UFUNCTION() void MenuTearDown(); class UMultiPlayerSessionSubsystem* MultiPlayerSessionSubsystem; int32 NumPublicConnections{4}; FString MatchType{TEXT(FreeForAll)}; }; .cpp // Fill out your copyright notice in the Description page of Project Settings. #include BaseMenu.h #include OnlineSessionSettings.h #include MultiPlayerSession/Public/MultiPlayerSessionSubsystem.h #include Components/Button.h bool UBaseMenu::Initialize() { if(!Super::Initialize()) { return false; } if(HostButton) { HostButton-OnClicked.AddDynamic(this,UBaseMenu::HostButtonClicked); } if(JoinButton) { JoinButton-OnClicked.AddDynamic(this,UBaseMenu::JoinButtonClincked); } return true; } void UBaseMenu::NativeDestruct() { Super::NativeDestruct(); } void UBaseMenu::OnCreateSession(bool bWasSuccessful) { if(bWasSuccessful) { _DebugLog(FColor::Green,TEXT(CreateSession Successful)); } UWorld* World GetWorld(); if(World) { World-ServerTravel(/Game/ThirdPerson/Maps/Lobby?listen); } } void UBaseMenu::OnFindSession(const TArrayFOnlineSessionSearchResult SessionSearchResult, bool bWasSuccessful) { if(MultiPlayerSessionSubsystemnullptr) { return; } for(auto Result : SessionSearchResult) { FString SettingValue; Result.Session.SessionSettings.Get(FName(MatchType),SettingValue); if(SettingValue MatchType) { MultiPlayerSessionSubsystem-JoinSession(Result); return; } } } void UBaseMenu::OnJoinSession(EOnJoinSessionCompleteResult::Type Result) { //加入游戏 IOnlineSubsystem* OnlineSubsystem IOnlineSubsystem::Get(); if(OnlineSubsystem) { IOnlineSessionPtr OnlineSessionInterface OnlineSubsystem-GetSessionInterface(); if(OnlineSessionInterface.IsValid()) { FString Address; // if(OnlineSessionInterface-GetResolvedConnectString(NAME_GameSession,Address)) { APlayerController* PlayerController GetGameInstance()-GetFirstLocalPlayerController(); if(PlayerController) { PlayerController-ClientTravel(Address,ETravelType::TRAVEL_Absolute); } } } } } void UBaseMenu::OnDestroySession(bool bWasSuccessful) { } void UBaseMenu::OnStartSession(bool bWasSuccessful) { } void UBaseMenu::MenuSetup(int SetupNumPublicConnections ,FString SetupMatchType) { NumPublicConnections SetupNumPublicConnections; MatchType SetupMatchType; AddToViewport(); SetVisibility(ESlateVisibility::Visible); bIsFocusable true; UWorld* World GetWorld(); if(World) { APlayerController* PlayerController World-GetFirstPlayerController(); if(PlayerController) { FInputModeUIOnly InputModeUIOnly; InputModeUIOnly.SetWidgetToFocus(TakeWidget()); InputModeUIOnly.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock); PlayerController-SetInputMode(InputModeUIOnly); PlayerController-SetShowMouseCursor(true); } } UGameInstance* GameInstance GetGameInstance(); if(GameInstance) { MultiPlayerSessionSubsystem GameInstance-GetSubsystemUMultiPlayerSessionSubsystem(); } if(MultiPlayerSessionSubsystem) { MultiPlayerSessionSubsystem-MultiPlayerOnCreateSessionComplete.AddDynamic(this,ThisClass::OnCreateSession); /*当委托是静态的时候需要使用 AddUObject */ MultiPlayerSessionSubsystem-MultiPlayerOnFindSessionComplete.AddUObject(this,ThisClass::OnFindSession); MultiPlayerSessionSubsystem-MultiPlayerOnJoinSessionComplete.AddUObject(this,ThisClass::OnJoinSession); MultiPlayerSessionSubsystem-MultiPlayerOnDestroySessionComplete.AddDynamic(this,ThisClass::OnDestroySession); MultiPlayerSessionSubsystem-MultiPlayerOnStartSessionComplete.AddDynamic(this,ThisClass::OnStartSession); } } void UBaseMenu::_DebugLog(FColor DisplayColor, const FString DebugMessage) { if(GEngine) { GEngine-AddOnScreenDebugMessage(-1,15.f,DisplayColor,DebugMessage); } } void UBaseMenu::HostButtonClicked() { if(MultiPlayerSessionSubsystem) { MultiPlayerSessionSubsystem-CreateSession(NumPublicConnections,MatchType); } _DebugLog(FColor::Blue,FString::Printf(TEXT(Create Session Success))); } void UBaseMenu::JoinButtonClincked() { //点击加入按钮 if(MultiPlayerSessionSubsystem) { MultiPlayerSessionSubsystem-FindSession(10000); } } void UBaseMenu::MenuTearDown() { UWorld* World GetWorld(); RemoveFromParent(); APlayerController* PlayerController World-GetFirstPlayerController(); FInputModeGameAndUI InputModeGameAndUI; PlayerController-SetInputMode(InputModeGameAndUI); PlayerController-SetShowMouseCursor(false); }
http://www.w-s-a.com/news/109154/

相关文章:

  • 杨凯做网站网站首页 排版
  • 网站图片标签江苏省建设类高工申报网站
  • 网站建设中的英文什么网站可以做医疗设备的
  • 柳州购物网站开发设计服装网站的建设与管理
  • 做网站的上海市哪家技术好北京百姓网免费发布信息
  • 网站文章排版制作网站软件
  • 云南网站开发公司网站商城定制网站建设
  • 企业网站的新闻资讯版块有哪些肇庆自助建站模板
  • 怎么做平台网站吗为网站做seo需要什么
  • 苏州吴江建设局招标网站海南网站搭建价格
  • 网站建设主要研究内容用哪个程序做网站收录好
  • 网站建设如何开单装修设计图免费
  • 做内容网站赚钱吗seo推广具体做什么
  • 连山区网站建设seo简历
  • 自助建站系统官方版太仓高端网站制作
  • 怎样只做自己的网站建设银行唐山分行网站
  • 咸阳鑫承网站建设软件开发公司网站模板
  • 百度怎么免费做网站网站建设大作业有代码
  • 小说素材网站设计素材网站特点
  • 如何建设一个好的网站WordPress主题设置数据库
  • 网站被模仿十堰网站制作公司
  • 怎么样做免费网站个人网站备案幕布
  • 做ppt的动图下载哪些网站制作一个网站需要多少时间
  • 公司网站开发制作备案中的网站
  • 怎么看网站的收录网站开发先前台和后台
  • 合肥市做网站多少钱wordpress网站布置视频
  • 中国建设人才网信息网站软件外包公司好不好
  • 网站建设与管理 市场分析上海网站建设公司排名
  • 怎么将公司网站设成首页网址关键词查询网站
  • 怎么用ps做网站ui邱县专业做网站