public override void OnPointerUp(UnityEngine.EventSystems.PointerEventData eventData) { base.OnPointerUp(eventData); State = SliderState.Up; Debug.LogError("松开"); Debug.LogError("松开的时间---》" + AudioManager.Instance.BackgroundAudioSource.time); }
public static void Initialize() { Command command = Command.Create(commandName); command.ControlState = SliderState.Create(1, 1, sliderTicks); Value = startRadius; }
private void Update() { var yPosition = rectTransform.anchoredPosition3D.y; if (yPosition < goal) { if (Mathf.Abs(yPosition - minStart) < 20 && state == SliderState.Idle) { EventManager.TriggerEvent("OnViewportGoal", 1f); state = SliderState.Sliding; } Slide(1); } else if (goal < yPosition) { if (Mathf.Abs(yPosition - maxStart) < 20 && state == SliderState.Idle) { EventManager.TriggerEvent("OnViewportGoal", 0f); state = SliderState.Sliding; } Slide(-1); } }
protected override bool DoMouseDrag(MouseEventArgs args) { bool result; if (GUIUtility.hotControl != base.id) { result = false; } else { SliderState sliderState = this.SliderState(); if (!sliderState.isDragging) { result = false; } else { GUI.changed = true; float num = this.MousePosition(args.mousePosition) - sliderState.dragStartPos; float val = sliderState.dragStartValue + num / this.ValuesPerPixel(); this.value = this.Clamp(val); result = true; } } return(result); }
public MenuSlider(int segments, ApplySlider sliderAction, float sliderMin, float sliderMax, float sliderInitialValue) { Vector2i componentSize = new Vector2i(32 * segments, 32); Initialize(componentSize); this.sliderMin = sliderMin; this.sliderMax = sliderMax; sliderValue = ((sliderInitialValue) / (sliderMax - sliderMin) * size.X / 2); sliderState = SliderState.Normal; collisionBox = new BoundingBox(componentSize); this.sliderAction = sliderAction; sliderArrays = new VertexArray[segments]; for (int i = 0; i < segments; i++) { if (i == 0) { sliderArrays[i] = CreateMenuGraphic(new FloatRect(0, 96, 32, 32), new Vector2i(32, 32)); } else if (i == segments - 1) { sliderArrays[i] = CreateMenuGraphic(new FloatRect(64, 96, 32, 32), new Vector2i(32, 32)); } else { sliderArrays[i] = CreateMenuGraphic(new FloatRect(32, 96, 32, 32), new Vector2i(32, 32)); } } sliderArray = CreateMenuGraphic(new FloatRect(96, 96, 32, 32), new Vector2i(32, 32)); sliderArrayHover = CreateMenuGraphic(new FloatRect(96, 96, 32, 32), new Vector2i(32, 32), new Color(192, 255, 192, 255)); sliderArraySliding = CreateMenuGraphic(new FloatRect(96, 96, 32, 32), new Vector2i(32, 32), new Color(128, 255, 128, 255)); }
private void Start() { health = INITIALVITALITY / 2; beardLength = INITIALVITALITY / 2; //getting health ui var slider = GameObject.Find("Canvas/HealthBar"); healthBeardUI = slider.GetComponent <SliderState>(); healthBeardUI.InitializeSegments(); healthBeardUI.UpdateSlider(health, beardLength); animator = transform.GetComponentInChildren <Animator>(); animator.SetFloat("Health", health); //Audio things var beardman = GameObject.Find("Beard Man/MusicMaker"); var b2 = GameObject.Find("Beard Man/BackgroundMusicSource"); musicSource = beardman.GetComponents <AudioSource>()[0]; backgroundSource = b2.GetComponents <AudioSource>()[0]; AudioClip[] beardSounds = Resources.LoadAll <AudioClip>("Sound/BeardNoise"); AudioClip[] beardManSounds = Resources.LoadAll <AudioClip>("Sound/BeardManSounds"); beardGrow = beardSounds[4]; beardShrink = beardSounds[3]; beardManDeath = beardManSounds[1]; beardManHurt = beardManSounds[0]; }
private void StartDraggingWithValue(float dragStartValue) { SliderState sliderState = SliderState(); sliderState.dragStartPos = MousePosition(); sliderState.dragStartValue = dragStartValue; sliderState.isDragging = true; }
private void StartDraggingWithValue(float dragStartValue, Vector2 currentMousePos) { SliderState sliderState = this.SliderState(); sliderState.dragStartPos = this.MousePosition(currentMousePos); sliderState.dragStartValue = dragStartValue; sliderState.isDragging = true; }
void Update() { HandleSlider(); if (Input.GetKeyDown(KeyCode.Space) && ballScript.canHit) { switch (curState) { // Swing is disabled case (SliderState.OFF): break; // Start the swing sequence case (SliderState.WAITING): curState = SliderState.LEFT; break; // Value is chosen, switch to right case (SliderState.LEFT): curPower = PowerSlider.value; curState = SliderState.RIGHT; break; // Accuracy chosen, or slider ran off edge. Swing. case (SliderState.RIGHT): if (curPower == 0.0F) { curPower = PowerSlider.value; } else { ballScript.HitBall(curPower); curPower = 0.0F; } break; } } // Move to next or prev club if (Input.GetKeyDown(KeyCode.E)) { clubName.text = ballScript.NextClub(); } if (Input.GetKeyDown(KeyCode.Q)) { clubName.text = ballScript.PrevClub(); } // Aim further left or right if (Input.GetKey(KeyCode.LeftArrow)) { ballScript.RotateLeft(rotateSpeed); } if (Input.GetKey(KeyCode.RightArrow)) { ballScript.RotateRight(rotateSpeed); } }
public static void Update(double value) { var state = (SliderState)SliderCommand.ControlState; int v = (int)Math.Round(value * sliderLength); v = Math.Max(v, sliderStart); v = Math.Min(v, sliderEnd); SliderCommand.ControlState = SliderState.Create(v, sliderStart, sliderEnd); LabelCommand.Text = AnimationTool.Time.ToString("F3"); }
protected internal override void OnMouseUp(int X, int Y, MouseButtons mb) { if (this._state == SliderState.Seek && Gumps.Capture == this) { int trackSize = this.GetTrackSize(); int thumbSize = this.GetThumbSize(); this.Value = this.GetValue(this.GetPosition(X, Y) - this._seekOffset, trackSize - thumbSize); } this._state = SliderState.Idle; Gumps.Capture = (Gump)null; }
public override int Select(Vector2 uiPosition, Rectangle extents, int order, Action <int, object> registerHitFunc) { if (!extents.Contains((int)uiPosition.X, (int)uiPosition.Y)) { return(order); } var thumbExtents = ThumbExtents(extents); int value = _getter(); switch (_state) { case SliderState.Normal: case SliderState.ClickHandled: break; // Nothing to be done case SliderState.Clicked: if (thumbExtents.Contains((int)uiPosition.X, (int)uiPosition.Y)) { // Not sure why the -1 is necessary, can't be bothered investigating further as it works well enough. _clickPosition = uiPosition.X - thumbExtents.X - 1; _state = SliderState.DraggingThumb; } else if (uiPosition.X < thumbExtents.X) { value -= Math.Max(1, (_max - _min) / 10); Raise(new SliderMovedEvent(_id, value)); _state = SliderState.ClickHandled; } else { value += Math.Max(1, (_max - _min) / 10); Raise(new SliderMovedEvent(_id, value)); _state = SliderState.ClickHandled; } break; case SliderState.DraggingThumb: float equivalentThumbPosition = uiPosition.X - _clickPosition; int spareWidth = extents.Width - thumbExtents.Width; int newValue = (int)((_max - _min) * (equivalentThumbPosition - extents.X) / spareWidth) + _min; if (newValue != value) { Raise(new SliderMovedEvent(_id, newValue)); } break; } var maxOrder = _thumb.Select(uiPosition, thumbExtents, order + 1, registerHitFunc); registerHitFunc(order, this); return(maxOrder); }
protected override GUIFSM <ScrollBase> CreateFSM() { var idle = new SliderState(); idle.AddTransition(GUIEventID.FocusGained, 1); var focused = new FocusedState(); focused.AddTransition(GUIEventID.FocusLost, 0); focused.AddTransition(GUIEventID.LeftMouseDown, 2); var mouseMove = new MouseMoveState(); mouseMove.AddTransition(GUIEventID.LeftMouseUp, 1); mouseMove.AddTransition(GUIEventID.FocusLost, 0); return(new GUIFSM <ScrollBase>(this, new GUIState <ScrollBase>[] { idle, focused, mouseMove })); }
public override int Select(Vector2 uiPosition, Rectangle extents, int order, Action <int, object> registerHitFunc) { if (!extents.Contains((int)uiPosition.X, (int)uiPosition.Y)) { return(order); } _lastExtents = extents; var thumbExtents = ThumbExtents(extents); int value = _getter(); switch (_state) { case SliderState.Normal: case SliderState.ClickHandled: break; // Nothing to be done case SliderState.Clicked: if (thumbExtents.Contains((int)uiPosition.X, (int)uiPosition.Y)) { // Not sure why the -1 is necessary, can't be bothered investigating further as it works well enough. _clickPosition = uiPosition.X - thumbExtents.X - 1; _state = SliderState.DraggingThumb; } else if (uiPosition.X < thumbExtents.X) { value -= Math.Max(1, (_max - _min) / 10); _setter(value); _state = SliderState.ClickHandled; } else { value += Math.Max(1, (_max - _min) / 10); _setter(value); _state = SliderState.ClickHandled; } break; case SliderState.DraggingThumb: break; } var maxOrder = _thumb.Select(uiPosition, thumbExtents, order + 1, registerHitFunc); registerHitFunc(order, this); return(maxOrder); }
public Color GetSliderColor(SliderState state) { switch (state) { case SliderState.Background: return(_sliderBackgroundColor); case SliderState.Foreground: return(_sliderForegroundColor); case SliderState.Handle: return(_sliderHandleColor); default: return(Color.black); } }
public Sprite GetSliderSprite(SliderState state) { switch (state) { case SliderState.Background: return(_sliderBackgroundSprite); case SliderState.Foreground: return(_sliderForegroundSprite); case SliderState.Handle: return(_sliderHandleSprite); default: return(null); } }
private float OnMouseDrag() { if (GUIUtility.hotControl != this.id) { return(this.currentValue); } SliderState sliderState = this.SliderState(); if (!sliderState.isDragging) { return(this.currentValue); } GUI.changed = true; this.CurrentEvent().Use(); float num = this.MousePosition() - sliderState.dragStartPos; return(this.Clamp(sliderState.dragStartValue + num / this.ValuesPerPixel())); }
private void Slide(int direction) { var step = Time.deltaTime * (maxStart - minStart) * 2.5f; rectTransform.anchoredPosition3D = new Vector3(rectTransform.anchoredPosition3D.x, rectTransform.anchoredPosition3D.y + direction * step, rectTransform.anchoredPosition3D.z); if (Mathf.Abs(goal - rectTransform.anchoredPosition3D.y) < step) { rectTransform.anchoredPosition3D = new Vector3(rectTransform.anchoredPosition3D.x, goal, rectTransform.anchoredPosition3D.z); EventManager.TriggerEvent("EndTransgression"); state = SliderState.Idle; } // } }
public void transition(SliderState direction) { if (direction == SliderState.transitionToOpen) { // Move slider. slider.X -= slideSpeed; partXPos -= slideSpeed; sliderFrame.X = slider.X + ContentLoader.Textures[ContentLoader.TextureNames.slideOut].Width; // Check if done. // For half way use: if (slider.X == ((Game1.screenWidth / 2) - ContentManager.rectangles[ContentManager.TextureNames.slideOut].Width)) if (slider.X <= ((Game1.screenWidth - ContentLoader.rectangles[ContentLoader.TextureNames.sliderFrame].Width) - ContentLoader.rectangles[ContentLoader.TextureNames.slideOut].Width)) { slideState = SliderState.open; Builder.sliderArrowVisible = false; } } else { // Move slider. slider.X += slideSpeed; partXPos += slideSpeed; sliderFrame.X = slider.X + ContentLoader.Textures[ContentLoader.TextureNames.slideOut].Width; // Check if done. if (slider.X >= (Game1.screenWidth - ContentLoader.Textures[ContentLoader.TextureNames.slideOut].Width)) { slider.X = ContentLoader.rectangles[ContentLoader.TextureNames.slideOut].X; sliderFrame.X = ContentLoader.rectangles[ContentLoader.TextureNames.sliderFrame].X; slideState = SliderState.closed; Builder.sliderArrowVisible = true; } } foreach (KeyValuePair <ContentLoader.TextureNames, Part> entry in parts) { // Update rectangle location for the items. partsHitList[entry.Key] = new Rectangle(partXPos, entry.Value.partPosition.Y, entry.Value.partPosition.Width, entry.Value.partPosition.Height); } // For halfway use: slider.X = (int)MathHelper.Clamp(slider.X, ((Game1.screenWidth / 2) - ContentManager.rectangles[ContentManager.TextureNames.slideOut].Width), (Game1.screenWidth - ContentManager.Textures[ContentManager.TextureNames.slideOut].Width)); slider.X = (int)MathHelper.Clamp(slider.X, ((Game1.screenWidth - ContentLoader.rectangles[ContentLoader.TextureNames.sliderFrame].Width) - ContentLoader.rectangles[ContentLoader.TextureNames.slideOut].Width), (Game1.screenWidth - ContentLoader.Textures[ContentLoader.TextureNames.slideOut].Width)); sliderFrame.X = (int)MathHelper.Clamp(sliderFrame.X, (slider.X + ContentLoader.rectangles[ContentLoader.TextureNames.slideOut].Width), Game1.screenWidth); }
public void update() { transparancy -= transparancyIncrement; transparancy = MathHelper.Clamp(transparancy, 0f, 1f); if (slideState == SliderState.transitionToClosed || slideState == SliderState.transitionToOpen) { transition(slideState); } currentTouches = TouchPanel.GetState(); if (currentTouches.Count > 0) { if (slider.Contains(new Point((int)currentTouches[0].Position.X, (int)currentTouches[0].Position.Y))) { // Fold out the harmonicatab. if (slideState == SliderState.open || slideState == SliderState.closed && Builder.sliderArrowVisible) { // Allowed movment. if (slideState == SliderState.open) { // Builder.sliderVisible = false; slideState = SliderState.transitionToClosed; } else { Builder.sliderArrowVisible = false; slideState = SliderState.transitionToOpen; } } } // Check parts for being "clicked", sounds less perferted then touched... foreach (KeyValuePair <ContentLoader.TextureNames, Rectangle> entry in partsHitList) { //Console.WriteLine("position on: " + entry.Value); if (entry.Value.Contains(new Point((int)currentTouches[0].Position.X, (int)currentTouches[0].Position.Y))) { // Handle the click. Builder.setMovingstate(entry.Key); } } } }
private float OnMouseDrag() { if (GUIUtility.hotControl != id) { return(currentValue); } SliderState sliderState = SliderState(); if (!sliderState.isDragging) { return(currentValue); } GUI.changed = true; CurrentEvent().Use(); float num = MousePosition() - sliderState.dragStartPos; float value = sliderState.dragStartValue + num / ValuesPerPixel(); return(Clamp(value)); }
private void Awake() { var canvas = FindObjectOfType <Canvas>().GetComponent <CanvasScaler>(); realHeight = canvas.referenceResolution.y; minStart = 0f; maxStart = realHeight; min = -250f; max = realHeight + 250f; rectTransform = GetComponent <RectTransform>(); goal = min; rectTransform.anchoredPosition3D = new Vector3(rectTransform.anchoredPosition3D.x, goal, rectTransform.anchoredPosition3D.z); summary = 0f; state = SliderState.Idle; }
protected internal override void Draw(int X, int Y) { base.Draw(X, Y); int trackSize = this.GetTrackSize(); int thumbSize = this.GetThumbSize(); int position1 = this.GetPosition(trackSize - thumbSize); switch (this._state) { case SliderState.SmallUp: this.Value -= this.SmallOffset; break; case SliderState.SmallDown: this.Value += this.SmallOffset; break; case SliderState.LargeUp: Point client1 = this.PointToClient(new Point(Engine.m_xMouse, Engine.m_yMouse)); int position2 = this.GetPosition(client1.X, client1.Y); if (position1 > position2) { this.Value -= this.LargeOffset; break; } this._state = SliderState.Idle; break; case SliderState.LargeDown: Point client2 = this.PointToClient(new Point(Engine.m_xMouse, Engine.m_yMouse)); int position3 = this.GetPosition(client2.X, client2.Y); if (position1 + thumbSize < position3) { this.Value += this.LargeOffset; break; } this._state = SliderState.Idle; break; } this.DrawThumb(X, Y, position1); }
public override void HandleInput(InputManager input) { base.HandleInput(input); Vector2f mousePos; bool mouse = input.GetMousePosition(out mousePos); Vector2i origin = new Vector2i(0, 0); MenuComponent bubble = parent; while (bubble != null) { origin += bubble.position; bubble = bubble.parent; } Vector2f pos = new Vector2f((position + origin).X, (origin + position).Y); if (mouse && sliderState != SliderState.Sliding && BoundingBox.CheckPointMenuCollision(mousePos.X, mousePos.Y, collisionBox, (pos))) { sliderState = SliderState.Hover; } else if (sliderState != SliderState.Sliding) { sliderState = SliderState.Normal; } if (sliderState == SliderState.Hover && input.GetMouseClicked(InputBindings.primary, true)) { sliderState = SliderState.Sliding; } if (sliderState == SliderState.Sliding && input.GetMouseReleased(InputBindings.primary, true)) { sliderState = SliderState.Released; sliderAction?.Invoke(tag, sliderMax * sliderValue / size.X + sliderMin); } if (sliderState == SliderState.Sliding) { sliderValue = mousePos.X - origin.X - position.X; sliderValue = sliderValue < 0 ? 0 : sliderValue; sliderValue = sliderValue > size.X ? size.X : sliderValue; } }
/** * void HandleSlider(): Defines what the slider should do on each update, based on curState. */ public void HandleSlider() { switch (curState) { case (SliderState.OFF): break; case (SliderState.WAITING): break; case (SliderState.LEFT): PowerSlider.value += Time.deltaTime; if (PowerSlider.value >= 1.0F) { curState = SliderState.RIGHT; } break; case (SliderState.RIGHT): PowerSlider.value -= Time.deltaTime; if (PowerSlider.value <= 0.0F) { curState = SliderState.OFF; PowerSlider.value = sliderZero; curState = SliderState.COMPLETE; } break; case (SliderState.COMPLETE): if (ballBody.velocity.magnitude <= 0.1f) { curState = SliderState.WAITING; } break; } }
void Start() { GameObject[] UIObjs; ballScript = golfball.GetComponent <GolfBallScript>(); ballBody = golfball.GetComponent <Rigidbody>(); curState = SliderState.WAITING; UIObjs = GameObject.FindGameObjectsWithTag("UI"); for (int i = 0; i < UIObjs.Length; i++) { if (UIObjs[i].name == "PowerSlider") { PowerSlider = UIObjs[i].GetComponent <Slider>(); } if (UIObjs[i].name == "ClubName") { clubName = UIObjs[i].GetComponent <Text>(); } } }
public SliderTrack(Func <int> getter, Action <int> setter, int min, int max, Func <int, string> format = null) { On <UiLeftClickEvent>(e => { _thumb.State = ButtonState.Clicked; _state = SliderState.Clicked; e.Propagating = false; // Raise(new SetExclusiveMouseModeEvent(this)); }); On <UiLeftReleaseEvent>(e => { _state = SliderState.Normal; _thumb.State = ButtonState.Normal; }); On <UiMouseMoveEvent>(e => { if (_state != SliderState.DraggingThumb) { return; } var thumbExtents = ThumbExtents(_lastExtents); float equivalentThumbPosition = e.X - _clickPosition; int spareWidth = _lastExtents.Width - thumbExtents.Width; int newValue = (int)((_max - _min) * (equivalentThumbPosition - _lastExtents.X) / spareWidth) + _min; if (newValue != _getter()) { _setter(newValue); } }); _getter = getter; _setter = setter; _min = min; _max = max; _thumb = new SliderThumb(getter, format); AttachChild(_thumb); }
protected internal override void OnMouseDown(int X, int Y, MouseButtons mb) { int trackSize = this.GetTrackSize(); int thumbSize = this.GetThumbSize(); int position = this.GetPosition(trackSize - thumbSize); int num = this.GetPosition(X, Y) - position; SliderState sliderState; if (num < 0) { sliderState = SliderState.LargeUp; } else if (num >= thumbSize) { sliderState = SliderState.LargeDown; } else { sliderState = SliderState.Seek; this._seekOffset = num; } this.State = sliderState; Gumps.Capture = (Gump)this; }
public void Reset() { State = SliderState.Normal; }
public override void OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData) { base.OnPointerDown(eventData); State = SliderState.Down; Debug.LogError("按下"); }