void OnDisable()
        {
            // When object is deselected in Edit Mode then we stop listening.
            if (!Application.isPlaying && _oscIn.isOpen)
            {
                _oscIn.Close();
            }

            // Unsubscribe from messsages.
            OscEditorUI.RemoveInspectorMessageListener(_oscIn, OnOSCMessage, ref _inspectorMessageEventObject);
        }
        void OnEnable()
        {
            _oscIn = target as OscIn;

            _openOnAwake                  = serializedObject.FindProperty("_openOnAwake");
            _port                         = serializedObject.FindProperty("_port");
            _mode                         = serializedObject.FindProperty("_mode");
            _multicastAddress             = serializedObject.FindProperty("_multicastAddress");
            _filterDuplicates             = serializedObject.FindProperty("_filterDuplicates");
            _addTimeTagsToBundledMessages = serializedObject.FindProperty("_addTimeTagsToBundledMessages");
            _mappings                     = serializedObject.FindProperty("_mappings");
            _dirtyMappings                = serializedObject.FindProperty("_dirtyMappings");
            _udpBufferSize                = serializedObject.FindProperty("_udpBufferSize");
            _settingsFoldout              = serializedObject.FindProperty("_settingsFoldout");
            _mappingsFoldout              = serializedObject.FindProperty("_mappingsFoldout");
            _messagesFoldout              = serializedObject.FindProperty("_messagesFoldout");

            // Store socket info for change check workaround.
            _tempPort             = _port.intValue;
            _tempMulticastAddress = _multicastAddress.stringValue;

            // Ensure that OscIn scripts will be executed early, so it can deliver messages before we compute anything.
            MonoScript script = MonoScript.FromMonoBehaviour(target as MonoBehaviour);

            if (MonoImporter.GetExecutionOrder(script) != -5000)
            {
                MonoImporter.SetExecutionOrder(script, -5000);
            }

            // When object is selected in Edit Mode then we start listening.
            if (_oscIn.enabled && !Application.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode && !_oscIn.isOpen)
            {
                if (_oscIn.mode == OscReceiveMode.UnicastBroadcast)
                {
                    _oscIn.Open(_oscIn.port);
                }
                else
                {
                    _oscIn.Open(_oscIn.port, _oscIn.multicastAddress);
                }
            }

            // Subscribe to messages.
            OscEditorUI.AddInspectorMessageListener(_oscIn, OnOSCMessage, ref _inspectorMessageEventObject);
        }
Пример #3
0
        void OnEnable()
        {
            _oscOut = target as OscOut;

            // Get serialized properties.
            _openOnAwake                        = serializedObject.FindProperty("_openOnAwake");
            _remoteIpAddress                    = serializedObject.FindProperty("_remoteIpAddress");
            _port                               = serializedObject.FindProperty("_port");
            _multicastLoopback                  = serializedObject.FindProperty("_multicastLoopback");
            _bundleMessagesOnEndOfFrame         = serializedObject.FindProperty("_bundleMessagesOnEndOfFrame");
            _splitBundlesAvoidingBufferOverflow = serializedObject.FindProperty("_splitBundlesAvoidingBufferOverflow");
            _udpBufferSize                      = serializedObject.FindProperty("_udpBufferSize");
            _settingsFoldout                    = serializedObject.FindProperty("_settingsFoldout");
            _messagesFoldout                    = serializedObject.FindProperty("_messagesFoldout");

            // Store socket info for change check workaround.
            _tempIPAddress = _remoteIpAddress.stringValue;
            _tempPort      = _port.intValue;

            // Ensure that OscOut scripts will be executed early, so that if Open On Awake is enabled the socket will open before other scripts are called.
            MonoScript script = MonoScript.FromMonoBehaviour(target as MonoBehaviour);

            if (MonoImporter.GetExecutionOrder(script) != executionOrderNum)
            {
                MonoImporter.SetExecutionOrder(script, executionOrderNum);
            }

            // When object is selected in Edit Mode then we start listening.
            if (_oscOut.enabled && !Application.isPlaying && !_oscOut.isOpen)
            {
                _oscOut.Open(_oscOut.port, _oscOut.remoteIpAddress);
                _statusInEditMode = _oscOut.mode == OscSendMode.UnicastToSelf ? OscRemoteStatus.Connected : OscRemoteStatus.Unknown;
            }

            // Subscribe to OSC messages
            OscEditorUI.AddInspectorMessageListener(_oscOut, OnOSCMessage, ref _inspectorMessageEventObject);

            // If in Edit Mode, then start a coroutine that will update the connection status. Unity can't start coroutines in Runtime.
            if (!Application.isPlaying && _oscOut.mode == OscSendMode.Unicast)
            {
                _pingEnumerator = OscHelper.StartCoroutineInEditMode(PingCoroutine(), ref _lastPingTime);
            }
        }