我使用的是Unity 2017.2。Infer.Net框架需要Unity4.0,并且.NET只能使用面向.NET 3.5的程序集。我该怎么做?
发布于 2017-12-11 07:51:37
在Unity 2017.2中,您可以转到:
编辑->项目设置-> Player ->其他设置-> Configuration -> API兼容级别
并切换到“实验.NET 4.6”。
这是你的测试代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Text;
using MicrosoftResearch.Infer.Models;
using MicrosoftResearch.Infer;
public class TestInferNet : MonoBehaviour {
// Use this for initialization
void Start () {
Debug.Log("Start Infer.net");
Variable<bool> firstCoin = Variable.Bernoulli(0.5).Named("firstCoin");
Variable<bool> secondCoin = Variable.Bernoulli(0.5).Named("secondCoin");
Variable<bool> bothHeads = (firstCoin & secondCoin).Named("bothHeads");
InferenceEngine ie = new InferenceEngine();
if (!(ie.Algorithm is VariationalMessagePassing))
{
Debug.Log("Probability both coins are heads: "+ie.Infer(bothHeads));
bothHeads.ObservedValue=false;
Debug.Log("Probability distribution over firstCoin: " + ie.Infer(firstCoin));
}
else
Debug.Log("This example does not run with Variational Message Passing");
Debug.Log("Done start");
}
// Update is called once per frame
void Update () {
}
} 您只需要将Infer.Compiler.dll和FSharp.Core 4.3.0添加到Unity的Assembly-CSharp项目中。对于FSharp程序集,请在Visual Studio中安装F#语言包。然后从以下位置复制程序集:
C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.0.0添加到您的Assets文件夹,并在C#项目中引用它。将上面的脚本添加到您选择的游戏对象中。
检查Unity中的控制台,查看上面程序的输出消息。
https://stackoverflow.com/questions/47744737
复制相似问题