在虚幻4中加载ice库

我使用的是vs2015,x86

配置方式参照

https://forums.unrealengine.com/showthread.php?65944-c-Mysql-database-error&highlight=mysql

首先是我的文件夹结构

主要展示下我的IceSupport.Build.cs文件


using UnrealBuildTool;
using System.IO;

public class IceSupport : ModuleRules
{
    public IceSupport(TargetInfo Target)
    {

        PublicDependencyModuleNames.AddRange(
            new string[] {
                "Core"
            });
        //string ice_home = "E:/Program Files (x86)/ZeroC/Ice-3.6.1/";
        //PublicIncludePaths.Add(ice_home + "include");
        //PublicLibraryPaths.Add(ice_home + "lib/vc140");
        //PublicAdditionalLibraries.Add("iced.lib");
        //PublicAdditionalLibraries.Add("iceutild.lib");
        // PublicDelayLoadDLLs.Add("ice36d.dll");
        //PublicDelayLoadDLLs.Add("iceutil36d.dll");
        bUseRTTI = true;
        UEBuildConfiguration.bForceEnableExceptions = true;


        string ModulePath = Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name));
        string ThirdPartyPath = Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/"));
        string IcePath = ThirdPartyPath + "Ice-3.6.1/";
        string IceLibraryPath = IcePath + "vc140/";
        string IceIncludePath = IcePath + "include/";
        PublicLibraryPaths.Add(IceLibraryPath);//添加ICE库目录 vs2015使用vc140目录,同时在系统环境变量PATH中配置%ICE_HOME%\bin\vc140    确保能正确加载dll
        PublicIncludePaths.Add(IceIncludePath);//添加ICEinclude目录
        PublicIncludePaths.Add(IcePath + "my/"); //使用slice(*.ice)文件生成c++代码的目录
        PublicAdditionalLibraries.Add(Path.Combine(IceLibraryPath, "ice.lib"));//这里不要使用debug版库,不管是debug模式
        PublicAdditionalLibraries.Add(Path.Combine(IceLibraryPath, "iceutil.lib"));
    }
}



同时修改(Your Game).Build.cs



// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.


using UnrealBuildTool;


public class myGame3 : ModuleRules
{
 public myGame3(TargetInfo Target)
 {
 //添加ICE模块
 PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","IceSupport" });
        bUseRTTI = true;//这个很重要
    }
}


 

 

  
  


然后打开虚幻编辑器,点击菜单,点击刷新VS项目,然后点击为windows烘焙内容,用于能在vs中调试使用,否则vs中运行会提示找不到文件的一个提示


接下来就是测试ICE,我是在GameMode里面测试

myGame3GameModel.h


// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/GameMode.h"
#include "myGame3GameMode.generated.h"

UCLASS(minimalapi)
class AmyGame3GameMode : public AGameMode
{
	GENERATED_BODY()
public:
	AmyGame3GameMode();
	virtual void BeginPlay() override;
};



myGame3GameMode.cpp


// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#include "myGame3.h"
#include "myGame3GameMode.h"
#include "myGame3Character.h"

//#pragma comment(lib, "iced.lib")
//#pragma comment(lib, "iceutild.lib")


//由于ICE中和虚幻中定义了相同的宏先取消宏定义
#pragma push_macro("check")
#pragma push_macro("verify")
#undef check
#undef verify
//加入虚幻的头文件
#include "AllowWindowsPlatformTypes.h"
#include <IceSupport.h>
#include <Ice/Ice.h>

#include "HideWindowsPlatformTypes.h"
//恢复虚幻的宏定义
#pragma pop_macro("verify")
#pragma pop_macro("check")

#include <Printer.h>
#include <iostream>
using namespace std;
using namespace Demo;

class PrinterI : public Printer {
public:
	virtual void printString(const string& s, const Ice::Current&);
};

AmyGame3GameMode::AmyGame3GameMode()
{
	// set default pawn class to our Blueprinted character
	static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/ThirdPersonCPP/Blueprints/ThirdPersonCharacter"));
	if (PlayerPawnBPClass.Class != NULL)
	{
		DefaultPawnClass = PlayerPawnBPClass.Class;
	}
	
}
void AmyGame3GameMode::BeginPlay()

{
	Ice::CommunicatorPtr ic;
	UE_LOG(LogTemp, Error, TEXT("this startedaaaaaaaaaa"));
	ic = Ice::initialize();
	Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints("aaaaaaaaaaaaaaaa", "default -p 20001 -h 127.0.0.1");
	Ice::ObjectPtr object = new PrinterI;
	adapter->add(object, ic->stringToIdentity("SimplePrinter"));
	adapter->activate();
}

void PrinterI::printString(const string & s, const Ice::Current &)
{
	UE_LOG(LogTemp, Error, TEXT("hahahah "));
}



注意 

我的使用slice(*.ice)文件生成c++代码的头文件放在 项目文件夹\ThirdParty\Ice-3.6.1\my   你也可以放在Source\IceSupport\Public目录

cpp文件放在Source\IceSupport\Private目录

OK 现在就可以测试运行了


转载于:https://my.oschina.net/microxdd/blog/603034

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值