Skip to content

Instantly share code, notes, and snippets.

@bilke
Last active May 25, 2016 08:22
Show Gist options
  • Select an option

  • Save bilke/05ed33e43cb2cdf5ecbb to your computer and use it in GitHub Desktop.

Select an option

Save bilke/05ed33e43cb2cdf5ecbb to your computer and use it in GitHub Desktop.
Slider Bugfix
diff --git a/Assets/MarkUX/Source/Views/Slider.cs b/Assets/MarkUX/Source/Views/Slider.cs
index c672482..3d8d4dd 100644
--- a/Assets/MarkUX/Source/Views/Slider.cs
+++ b/Assets/MarkUX/Source/Views/Slider.cs
@@ -1,4 +1,4 @@
-#region Using Statements
+#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
@@ -210,19 +210,18 @@ namespace MarkUX.Views
});
Vector2 pos;
- RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, mouseScreenPositionIn, canvas.worldCamera, out pos);
- Vector2 mouseScreenPosition = canvas.transform.TransformPoint(pos);
+ RectTransformUtility.ScreenPointToLocalPointInRectangle(this.transform as RectTransform, mouseScreenPositionIn, canvas.worldCamera, out pos);
// calculate slide percentage (transform.position.x/y is center of fill area)
float p = 0;
float slideAreaLength = transform.rect.width - SliderHandleLength.Pixels;
if (Orientation == Orientation.Horizontal)
{
- p = ((mouseScreenPosition.x - transform.position.x + slideAreaLength / 2f) / slideAreaLength).Clamp(0, 1);
+ p = ((pos.x - transform.localPosition.x + slideAreaLength / 2f) / slideAreaLength).Clamp(0, 1);
}
else
{
- p = ((mouseScreenPosition.y - transform.position.y + slideAreaLength / 2f) / slideAreaLength).Clamp(0, 1);
+ p = ((pos.y - transform.localPosition.y + slideAreaLength / 2f) / slideAreaLength).Clamp(0, 1);
}
// set value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment