1

我正在尝试在 Unity 上使用我的 C++ dll,因此我将它复制到 Assets/Plugins 和项目的根目录中,但是当我使用 Play 按钮或运行构建生成的 .exe 文件时出现 DllFoundException。当我在 DllImport 中使用 dll 文件的绝对路径时,它甚至不起作用。

但是,当我构建和运行项目时它工作正常。

统一代码

using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using Dummiesman;

public class morph_face : MonoBehaviour
{
    bool morphed;


    [DllImport(@"facemorph", CallingConvention=CallingConvention.Cdecl)]
    static extern void morphModelsPoints(string src_model, string src_csv,
            string dst_csv, string output_path);


    public GameObject model;

    // Start is called before the first frame update
    void Start()
    {
        morphed = false;
    }

    // Update is called once per frame
    void Update()
    {
        if (!morphed && Input.GetKeyDown("space")) {
            Debug.Log("SpaceBar pressed the model will be modified.");
            morphModelsPoints("Data/src.obj", "Data/src.csv", "Data/dst.csv",
                "Data/res.obj");

            //disable old mesh
            model.SetActive(false);

            OBJLoader obj = new OBJLoader();
            model = obj.Load("Data/res.obj");

            //displays new mesh
            model.SetActive(true);

            morphed = true;
        }
    }
}

Dll 是使用以下配置构建的:Release/Win32。

这是 dll 导入设置: 在此处输入图像描述

4

1 回答 1

1

※如有错误请指正

如果我没记错的话,你不能在编辑器中使用 32 个 dll,因为 UNITY 是 64 位的。如果您可以将您的dll重建为64位。如果您构建一个独立的,那么您必须在构建设置中将您的架构设置为 x86 而不是 x86_64。

于 2020-10-13T08:12:03.550 回答