加入我们的逻辑代码是以dll的方式,放到unity项目中如下:
namespace CSharpDll
{
public class Utils
{
public int Add(int a, int b)
{
int c = a + b;
return c;
}
public string SayHello()
{
return "helloworld";
}
public string SayNihao()
{
return "nihao";
}
}
}
生成的dll为:
我们拷贝到:
这里拷贝的是两个文件:CSharpDll.dll和CSharpDll.pdb
然后出pc的包:
这两个要勾选上:Development Build和Script Debugging两个选项。
然后在vs中:
unity的测试代码:
using UnityEngine;
using UnityEngine.UI;
public class Demo : MonoBehaviour
{
public GameObject m_go;
public Text m_text;
private AudioComponent m_audio;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
Utils t = new Utils();
int total = t.Add(1, 2);
string name = t.SayHello();
m_text.text = total + ":" + name;
}
}
}
按A键,即可落入断点:
这里没有走额外的操作,没有生成mdb文件,也可调试。