コード例 #1
0
        private void OnInspectorUpdate()
        {
            UpdateCurrentValues();
            if (_currentButtonEvent == null)
            {
                if (_elapsedTime != 0)
                {
                    Repaint();
                }
                _elapsedTime = 0;
                _longPressed = false;
                return;
            }

            _elapsedTime += EditorApplication.timeSinceStartup - _currentTime;
            _currentTime  = EditorApplication.timeSinceStartup;

            if (!_longPressed && _elapsedTime >= _targetLongPressTime)
            {
                _longPressed        = true;
                _currentButtonEvent = new MetaButton(_currentButtonEvent.Type, ButtonState.ButtonLongPress, _currentButtonEvent.Timestamp);
                EditorButtonPlugin.ButtonEvents.Enqueue(_currentButtonEvent);
            }
            Repaint();
        }
コード例 #2
0
        /// <summary>
        /// Process the Meta Button Event
        /// </summary>
        /// <param name="button">Button Message</param>
        public override void OnMetaButtonEvent(MetaButton button)
        {
            Color targetColor = Color.white;

            switch (button.State)
            {
            case ButtonState.ButtonRelease:
                targetColor = _defaultColor;
                break;

            case ButtonState.ButtonShortPress:
                targetColor = Color.green;
                break;

            case ButtonState.ButtonLongPress:
                targetColor = Color.yellow;
                break;
            }

            for (int i = 0; i < _materials.Length; ++i)
            {
                var material = _materials[i];
                material.color = targetColor;
            }
        }
        /// <summary>
        /// Upon a Meta button press, initiate a snapshot.  Can call this with null to also take a snapshot.
        /// </summary>
        /// <param name="button">Button Message</param>
        public void OnMetaButtonEvent(MetaButton button)
        {
            // If we received a button event, ensure it's the correct type of button press.
            if (button != null)
            {
                if (button.Type != ButtonType.ButtonCamera)
                {
                    return;
                }

                if (button.State != ButtonState.ButtonShortPress)
                {
                    return;
                }
            }

            if (!this.enabled)
            {
                Debug.LogWarning("Script is not enabled");
                return;
            }
            if (!CreateWebCamTexture())
            {
                Debug.LogWarning("Could not create Webcam Texture");
                return;
            }
            if (_isProcessing)
            {
                Debug.LogWarning("Still processing data");
                return;
            }

            StartCoroutine(TakeStill());
        }
コード例 #4
0
        /// <summary>
        /// Process the Meta Button Event
        /// </summary>
        /// <param name="button">Button Message</param>
        public void OnMetaButtonEvent(MetaButton button)
        {
            if (button.Type != ButtonType.ButtonCamera)
            {
                return;
            }
            if (button.State != ButtonState.ButtonShortPress)
            {
                return;
            }
            if (!this.enabled)
            {
                Debug.LogWarning("Script is not enabled");
                return;
            }
            if (!CreateWebCamTexture())
            {
                Debug.LogWarning("Could not create Webcam Texture");
                return;
            }
            if (_isProcessing)
            {
                Debug.LogWarning("Still processing data");
                return;
            }

            StartCoroutine(TakeStill());
        }
コード例 #5
0
 /// <summary>
 /// Send the event
 /// </summary>
 /// <param name="button">Button event</param>
 private void SendEvent(MetaButton button)
 {
     if (_mainEvent != null)
     {
         _mainEvent.Invoke(button);
     }
 }
 /// <summary>
 /// Process the button events
 /// </summary>
 /// <param name="button">Button event</param>
 protected override void ProcessButtonEvents(MetaButton button)
 {
     if (_mainEvent == null)
     {
         return;
     }
     _mainEvent.Invoke(button);
 }
コード例 #7
0
        /// <summary>
        /// Broadcast to the children of the current GameObject
        /// </summary>
        /// <param name="button">Button event</param>
        private void BroadcastChildren(MetaButton button)
        {
            var objects = GetComponentsInChildren <IOnMetaButtonEvent>();

            for (int i = 0; i < objects.Length; ++i)
            {
                objects[i].OnMetaButtonEvent(button);
            }
        }
コード例 #8
0
        /// <summary>
        /// Broadcast to all GameObjects in the scene
        /// </summary>
        /// <param name="button">Button event</param>
        private void BroadcastToAll(MetaButton button)
        {
            var objects = GameObject.FindObjectsOfType <BaseMetaButtonInteractionObject>();

            for (int i = 0; i < objects.Length; ++i)
            {
                objects[i].OnMetaButtonEvent(button);
            }
        }
コード例 #9
0
 /// <summary>
 /// Raise the Volume Up Button Event
 /// </summary>
 /// <param name="button">Button message</param>
 private void RaiseVolumeUpEvent(MetaButton button)
 {
     if (!_enableVolumeUpEvents)
     {
         return;
     }
     if (_volumeUpEvent == null)
     {
         return;
     }
     _volumeUpEvent.Invoke(button);
 }
コード例 #10
0
 /// <summary>
 /// Raise the Camera Button Event
 /// </summary>
 /// <param name="button">Button message</param>
 private void RaiseCameraEvent(MetaButton button)
 {
     if (!_enableCameraEvents)
     {
         return;
     }
     if (_cameraEvent == null)
     {
         return;
     }
     _cameraEvent.Invoke(button);
 }
コード例 #11
0
        /// <summary>
        /// Process the Meta Button Event
        /// </summary>
        /// <param name="button">Button Message</param>
        public void OnMetaButtonEvent(MetaButton button)
        {
            if (button.Type != _buttonType)
            {
                return;
            }
            if (button.State != _buttonState)
            {
                return;
            }

            _source.PlayOneShot(_clip);
        }
コード例 #12
0
 public override void OnMetaButtonEvent(MetaButton button)
 {
     if (button.State == ButtonState.ButtonRelease)
     {
         button_pushed = false;
     }
     else if (button.State == ButtonState.ButtonShortPress || button.State == ButtonState.ButtonLongPress)
     {
         button_pushed = true;
     }
     else
     {
         throw new System.Exception(System.String.Format("button in unknown state {0}", (int)button.State));
     }
 }
コード例 #13
0
        /// <summary>
        /// Process the button events
        /// </summary>
        /// <param name="button">Button event</param>
        protected override void ProcessButtonEvents(MetaButton button)
        {
            switch (button.Type)
            {
            case ButtonType.ButtonCamera:
                RaiseCameraEvent(button);
                break;

            case ButtonType.ButtonVolumeDown:
                RaiseVolumeDownEvent(button);
                break;

            case ButtonType.ButtonVolumeUp:
                RaiseVolumeUpEvent(button);
                break;
            }
        }
        public void ProcessButtonEvent(MetaButton button)
        {
            if (button.Type == ButtonType.ButtonCamera)
            {
                return;
            }

            switch (button.State)
            {
            case ButtonState.ButtonRelease:
                _update = false;
                break;

            case ButtonState.ButtonLongPress:
                _update = true;
                break;
            }
            _uiText.text = string.Format("Volume: {0:0.00}", AudioListener.volume);
        }
コード例 #15
0
        /// <summary>
        /// Calls the update loop to get new values from the localizer.
        /// </summary>
        private void Update()
        {
            MetaButton buttonEvent = null;

            // Pull buttons until button queue is exhausted for this update.
            while ((buttonEvent = _interop.GetButtonEvent()) != null)
            {
                // Make sure we send a Release event
                if (buttonEvent.Type != _lastType && _lastState != ButtonState.ButtonRelease)
                {
                    var forceRelease = new MetaButton(_lastType, ButtonState.ButtonRelease, buttonEvent.Timestamp);
                    SendEvent(forceRelease);
                }
                SendEvent(buttonEvent);

                _lastType  = buttonEvent.Type;
                _lastState = buttonEvent.State;
            }
        }
コード例 #16
0
        /// <summary>
        /// Process the button events
        /// </summary>
        /// <param name="button">Button event</param>
        protected override void ProcessButtonEvents(MetaButton button)
        {
            switch (_broadcastType)
            {
            case ButtonBroadcastType.None:
                break;

            case ButtonBroadcastType.Scene:
                BroadcastToAll(button);
                break;

            case ButtonBroadcastType.Children:
                BroadcastChildren(button);
                break;

            case ButtonBroadcastType.Parents:
                BroadcastParent(button);
                break;
            }
        }
コード例 #17
0
        /// <summary>
        /// Handles the current button pressed
        /// </summary>
        /// <param name="name">name of the button</param>
        /// <param name="type">Type of the button</param>
        private void HandleButton(string name, ButtonType type)
        {
            bool buttonIsPressed = GUILayout.RepeatButton(name);

            if (!Application.isPlaying)
            {
                return;
            }
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (buttonIsPressed)
            {
                // Create a button if the current event is null
                if (_currentButtonEvent == null)
                {
                    _currentTime        = EditorApplication.timeSinceStartup;
                    _currentButtonEvent = new MetaButton(type, ButtonState.ButtonShortPress, 0);
                    EditorButtonPlugin.ButtonEvents.Enqueue(_currentButtonEvent);
                    return;
                }
            }
            else
            {
                if (_currentButtonEvent == null)
                {
                    return;
                }
                if (_currentButtonEvent.Type != type)
                {
                    return;
                }

                // Release Button
                _currentButtonEvent = new MetaButton(_currentButtonEvent.Type, ButtonState.ButtonRelease, _currentButtonEvent.Timestamp);
                EditorButtonPlugin.ButtonEvents.Enqueue(_currentButtonEvent);
                _currentButtonEvent = null;
            }
        }
        /// <summary>
        /// Process the Meta Button Event
        /// </summary>
        /// <param name="button">Button Message</param>
        public void OnMetaButtonEvent(MetaButton button)
        {
            if (button.Type == ButtonType.ButtonCamera)
            {
                return;
            }
            if (!this.enabled)
            {
                Debug.LogWarning("Script is not enabled");
                return;
            }
            if (button.Type == ButtonType.ButtonVolumeUp)
            {
                _currentDelta = _delta;
            }
            if (button.Type == ButtonType.ButtonVolumeDown)
            {
                _currentDelta = _delta * -1f;
            }


            switch (button.State)
            {
            case ButtonState.ButtonShortPress:
                UpdateVolume();
                break;

            case ButtonState.ButtonLongPress:
                _volumeCoroutine = StartCoroutine(UpdateRoutine());
                break;

            case ButtonState.ButtonRelease:
                if (_volumeCoroutine != null)
                {
                    StopCoroutine(_volumeCoroutine);
                    _volumeCoroutine = null;
                }
                break;
            }
        }
 /// <summary>
 /// Process the button events
 /// </summary>
 /// <param name="button">Button event</param>
 protected abstract void ProcessButtonEvents(MetaButton button);