首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何调试dll (统一)?

如何调试dll (统一)?
EN

Stack Overflow用户
提问于 2020-09-13 10:21:40
回答 1查看 1K关注 0票数 1

我有一个使用dll的统一项目。

这是我尝试使用的一个示例:https://www.youtube.com/watch?v=C6V1f86x058

为了使它发挥作用,我:

  1. 创建了C#脚本
  2. 在资产文件夹

下添加了dll

我的剧本是

代码语言:javascript
复制
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Rendering;

public class TestScript : MonoBehaviour
{
    //the name of the DLL you want to load stuff from
    private const string pluginName = "AndroidNativeLib";
    //native interface
    [DllImport(pluginName)]
    private static extern IntPtr getEventFunction();

    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate void DebugDelegate(string str);

    static void CallBackFunction(string str) { Debug.Log(str); }

    [DllImport(pluginName)]
    public static extern void SetDebugFunction(IntPtr fp);


    private CommandBuffer cmd;
    // Start is called before the first frame update
    void Start()
    {
        DebugDelegate callback_delegate = new DebugDelegate(CallBackFunction);
        // Convert callback_delegate into a function pointer that can be
        // used in unmanaged code.
        IntPtr intptr_delegate =
            Marshal.GetFunctionPointerForDelegate(callback_delegate);
        // Call the API passing along the function pointer.
        SetDebugFunction(intptr_delegate);

        //crating the command buffer and attaching it to camera
        cmd = new CommandBuffer();
        cmd.name = pluginName;
        var camera = Camera.main;
        camera.AddCommandBuffer(CameraEvent.AfterGBuffer, cmd);
    }

    // Update is called once per frame
    void Update()
    {
        cmd.IssuePluginEvent(getEventFunction(), 0);
    }
}

我的dll是:

代码语言:javascript
复制
#include "stdafx.h"
#include "IUnityGraphics.h"

//make sure this appears before IUnityGraphicsD3D11
#include "d3d11.h"

#include "IUnityGraphicsD3D11.h"


// debug event
typedef void(*FuncPtr)(const char *);
FuncPtr Debug;

namespace globals {
    ID3D11Device *device = nullptr;
    ID3D11DeviceContext *context = nullptr;
} // namespace globals

extern "C" {

    UNITY_INTERFACE_EXPORT void SetDebugFunction(FuncPtr fp) { Debug = fp; }

    // Plugin function to handle a specific rendering event
    static void UNITY_INTERFACE_API  UNITY_INTERFACE_API OnRenderEvent(int eventID) {
        Debug("Hello world");
    }


    // Unity plugin load event
    void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
        UnityPluginLoad(IUnityInterfaces *unityInterfaces) {
        auto s_UnityInterfaces = unityInterfaces;
        IUnityGraphicsD3D11 *d3d11 = unityInterfaces->Get<IUnityGraphicsD3D11>();
        globals::device = d3d11->GetDevice();
        globals::device->GetImmediateContext(&globals::context);
    }

    // Unity plugin unload event
    void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload() {}

    // Freely defined function to pass a callback to plugin-specific scripts
    UnityRenderingEvent UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
        getEventFunction() {
        return OnRenderEvent;
    }
}

当我运行这个例子时,我看不到任何输出,它看起来也不工作。所以,我试着调试它。我可以在C#脚本中获得调试点,但是如果我试图从dll代码中达到调试点,就会注意到这一点。

那么,问题是-如何调试dll代码?

EN

回答 1

Stack Overflow用户

发布于 2020-09-13 10:30:58

这有帮助吗:https://forum.unity.com/threads/how-to-build-and-debug-external-dlls.161685/

normal

  • source

  • 创建一个.csproj文件,该文件使用通配符查找所有源代码

  • ,将此C#项目添加到Visual解决方案

  • 中使用MSBuild后构建目标将Visual的PDB符号转换为Mono的MDB格式

  • ,并使用来自统一的MonoDevelop进行调试,因为代码不应该在资产文件夹中,但是生成的DLL应该是< code >g 214
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63869641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档