示例#1
0
        private void AutoDiscoverInit()
        {
            discoveryClientAdapter = new DiscoveryClientAdapter();
            discoveryClientAdapter.DiscoveredEvent += OnSystemDiscovered;

            discoveryClient = DiscoveryClient.Create();
            discoveryClient.AddListener(discoveryClientAdapter);

            //Start Finding Server
            isTryingToFindServer = true;
        }
示例#2
0
        protected void OnDestroy()
        {
            if (discoveryClient != null)
            {
                discoveryClient.RemoveListener(discoveryClientAdapter);
                discoveryClient.Dispose();
                discoveryClient = null;

                if (discoveryClientAdapter != null)
                {
                    discoveryClientAdapter.Dispose();
                    discoveryClientAdapter = null;
                }
            }

            if (networkConnection != null)
            {
                networkConnection.RemoveListener((byte)MessageID.StatusOnly, networkConnectionAdapter);
                networkConnection.Dispose();
                networkConnection = null;

                if (networkConnectionAdapter != null)
                {
                    networkConnectionAdapter.Dispose();
                    networkConnectionAdapter = null;
                }
            }

            if (sharingMgr != null)
            {
                // Force a disconnection so that we can stop and start Unity without connections hanging around
                sharingMgr.GetPairedConnection().Disconnect();
                sharingMgr.GetServerConnection().Disconnect();

                // Release the XTools manager so that it cleans up the C++ copy
                sharingMgr.Dispose();
                sharingMgr = null;
            }

            // Forces a garbage collection to try to clean up any additional reference to SWIG-wrapped objects
            GC.Collect();
        }