Unity3d 开发平台问题:'NatUtility' 不包含 'DeviceLost' 的定义

Question for Unity3d Developement platform:'NatUtility' does not contain a definition for 'DeviceLost'

我已经添加了 using Mono.Nat; 但显然 Unity 说

'NatUtility' does not contain a definition for 'DeviceLost'"

这让我很困惑。到了我用 API 参考字面复制 1:1 的地步。我很困惑。

代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mono.Nat;

public class UPnP_PortForwardingBS : MonoBehaviour
{
    public void Start()
    {
        // Hook into the events so you know when a router has been detected or has gone offline
        NatUtility.DeviceFound += DeviceFound;
        NatUtility.DeviceLost += DeviceLost;

        // Start searching for upnp enabled routers
        NatUtility.StartDiscovery();
    }

    void DeviceFound(object sender, DeviceEventArgs args)
    {
        // This is the upnp enabled router
        INatDevice device = args.Device;

        // Create a mapping to forward external port 3000 to local port 1500
        device.CreatePortMap(new Mapping(Protocol.Tcp, 1500, 3000));

        // Retrieve the details for the port map for external port 3000
        Mapping m = device.GetSpecificMapping(Protocol.Tcp, 3000);

        // Get all the port mappings on the device and delete them
        foreach (Mapping mp in device.GetAllMappings())
            device.DeletePortMap(mp);

        // Get the external IP address
        var externalIP = device.GetExternalIP();
    }

    private void DeviceLost(object sender, DeviceEventArgs args)
    {
        INatDevice device = args.Device;

        //Debug.Log("Device Lost");
        //Debug.Log("Type: {0}", device.GetType().Name);
    }
}

请参阅Mono.NatGitHubrelease页面:

  • Removed NatUtility.DeviceLost as it was never a usable event.
  • Added the ability to manually pass messages into Mono.Nat if another part of the application has already bound to the normal upnp listening port.
  • Improved logging via Logger.Factory
  • Searchers are disposed when NatUtility.StopDiscovery is invoked, and (re-)created when NatUtility.StartDiscovery is invoked. In addition any previously detected devices are cleared when StopDiscovery is invoked.