Unity3DはDLL動的リンクライブラリを呼び出します

1. vs2017を開いて、新しいプロジェクトを作成します

2.Windowsデスクトップ>ダイナミックリンクライブラリ(DLL)を選択します

3. C ++追加関数を定義します

4.DLL動的リンクライブラリを生成します

5. UnityのAssetsの下にpluginsフォルダーを作成し、その中にDLLを配置します(pluginsの下に配置する必要があります。そうしないと、Unityはそれを認識しません)

6.単一性の下で新しいTest.csスクリプトを作成します

using UnityEngine;
using System.Runtime.InteropServices;

public class Test : MonoBehaviour
{
    [DllImport("Dll1")]
    public static extern int add(int a, int b);
    void Start()
    {
        print(add(10, 20));
    }
}

7.Test.csスクリプトをメインカメラにドラッグアンドドロップします

8.実行結果

おすすめ

転載: blog.csdn.net/zhunju0089/article/details/103458855