private void OnDisable() { foreach (var button in _currentHovers.Values) { GameManager.Game.ReleasedButton(button, 2f); } _currentHovers.Clear(); if(_currentMouseHover) GameManager.Game.ReleasedButton(_currentMouseHover, 2f); _currentMouseHover = null; }
public void MuteButtonMutesTheAudio() { AudioListener.volume = 1; GameObject gameObject = new GameObject(); gameObject.AddComponent <SoundButtonController>(); SoundButtonController muteButton = gameObject.GetComponent <SoundButtonController>(); Assert.IsNotNull(muteButton); Assert.NotZero(AudioListener.volume); muteButton.muteAndUnmute(); Assert.Zero(AudioListener.volume); muteButton.muteAndUnmute(); Assert.NotZero(AudioListener.volume); }
private static bool IsPointInButton(Vector3 pos, SoundButtonController button) { return RectTransformUtility.RectangleContainsScreenPoint(button.GetComponent<RectTransform>(), pos); }
private void HandleMouse() { if (!Input.GetMouseButton(0)) { if (!_currentMouseHover) return; GameManager.Game.ReleasedButton(_currentMouseHover); _currentMouseHover = null; } else { if (_currentMouseHover) { if (!IsPointInButton(Input.mousePosition, _currentMouseHover)) { GameManager.Game.ReleasedButton(_currentMouseHover); _currentMouseHover = null; } else { return; } } var button = GetHoveredButton(Input.mousePosition); if (!button) return; GameManager.Game.PressedButton(button); _currentMouseHover = button; _lastInput = Time.time; } }
private static IEnumerator DelayedRelease(SoundButtonController button, float delay) { yield return new WaitForSeconds(delay); button.Deactivate(); }
public void ReleasedButton(SoundButtonController button, float delay = 0) { if (delay > 0) StartCoroutine(DelayedRelease(button, delay)); else button.Deactivate(); }
public void PressedButton(SoundButtonController button) { button.Activate(); }