当从 python 调用时,c# 需要额外的参数(.net 和 ironpython)

标签 c# python unity3d ironpython

我在 C# 中有这个(游戏对象来自 unity3d)

namespace DLLTest
{
    public class buttong : MonoBehaviour
    {

        public GameObject BButtn([ParamDictionary] IDictionary kwargs)

这在 python 初始化中:

engine.Runtime.LoadAssembly(System.Reflection.Assembly.GetAssembly(typeof(DLLTest.buttong)));

在 Python 中:

from DLLTest.buttong import BButtn
def BButton(**kwargs):
    BButtn(kwargs)

我不断得到

TypeError: expected buttong, got dict

当我从 C# 调用它时,它只需要字典(我认为),但是从 Python 调用它时,它需要 2 个参数和一个额外的 buttong 类型,我想知道为什么以及如何提供一个 buttong 类型。

最佳答案

你的方法 BButtn 不是静态的。所以你需要用一个 buttong 的实例来调用它(或者让它成为静态的)

尝试做

from DLLTest import buttong
def BButton(**kwargs):
    b= buttong()
    b.BButtn(kwargs)

关于当从 python 调用时,c# 需要额外的参数(.net 和 ironpython),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32652953/

相关文章:

c# - 创建CollectionViewSource

c# - OnTriggerEnter 调用两次

c# - stringBuilder碎片化如何解决?

c# - 有没有办法强制 NHTMLUNIT 忽略页面 JavaScript 错误并继续执行脚本?

python - 我如何在 django Rest 框架中的查询参数中创建 OR 运算符

python - 如何将本地 conda env 中的 python 脚本转换为 Linux 中的 systemd 服务?

python - 如何使用python从json文件打印

c# - 调用 ReadPixels 以从系统帧缓冲区读取像素,而不是在绘图帧内。 UnityEngine.Texture2D :ReadPixels

git - 建立Git存储库后Unity项目不再打开

c# - 如何使用 C# 删除 "In Use"的 SQl Server 数据库?