Unity3d ingame插件无法加载system32 dll

时间:2014-07-24 10:30:59

标签: c# dll mono unity3d zeroconf

我正在为Kerbal Space Program(Windows 8.1)开发插件,所以我可以在游戏中使用zeroconf networking(bonjour)。我正在使用Mono.Zeroconf包装,Bonjour已安装并正常工作。简单的控制台应用程序工作正常,服务在网络上可见。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mono.Zeroconf;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            RegisterService service = new RegisterService();
            service.Name = "test server";
            service.RegType = "_daap._tcp";
            service.ReplyDomain = "local.";
            service.Port = 6060;

            // TxtRecords are optional
            TxtRecord txt_record = new TxtRecord();
            txt_record.Add("Password", "false");
            service.TxtRecord = txt_record;

            service.Register();
            Console.WriteLine("Service registered!");
            Console.ReadLine();
        }
    }
}

但是当我将代码和dll复制到Unity3d插件时,它无法加载Bonjour提供程序。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using KSP;
using UnityEngine;
using Mono.Zeroconf;

namespace KSP_dnssdServer
{
    [KSPAddon(KSPAddon.Startup.EveryScene, true)]
    class dnssdServer: MonoBehaviour
    {
        private float lastUpdate = 0.0f;
        private float lastFixedUpdate = 0.0f;
        private float logInterval = 5.0f;

        public RegisterService service;


        public dnssdServer()
        {

            if (instance == null) {
                instance = this;
                Debug.Log("dnssdServer Started");  
            } else {
                Debug.Log("dnssdServer already running, marking this instance as stale");
            }

            service = new RegisterService();
            service.Name = "TestService";
            service.RegType = "_ksp_dnssd._tcp";
            service.ReplyDomain = "local.";
            service.Port = 24321;

            // TxtRecords are optional
            TxtRecord txt_record = new TxtRecord();
            txt_record.Add("Password", "false");
            service.TxtRecord = txt_record;

            service.Register();

            Debug.Log("Service registered!");

            GameObject.DontDestroyOnLoad(this);
        }

        /*
         * Called after the scene is loaded.
         */
        void Awake()
        {
        }

        /*
         * Called next.
         */
        void Start()
        {
        }

        /*
         * Called every frame
         */
        void Update()
        {
        }

        /*
         * Called at a fixed time interval determined by the physics time step.
         */
        void FixedUpdate()
        {
            if ((Time.time - lastFixedUpdate) > logInterval)
            {
                lastFixedUpdate = Time.time;
                Debug.Log(instance.GetInstanceID().ToString("X"));
            }
        }

        void OnDestroy()
        {
            service.Dispose();
        }


    }
}

我假设从插件级别加载system32 dll时出现问题。知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

答案是...... Mono.Zeroconf dll不应该放在子文件夹中,就像我在项目中使用它们一样。在这种情况下,Windows上的Mono.Zeroconf文件需要在您的插件dll旁边。