• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
Question by Hamsterlings · Apr 03, 2015 at 02:46 AM · user interface

Is it possible to pick up "mouse up" on value changed ?

I generate slider and I assign function using Delegate to control slider and other UI elements/data.

I don't feel like making another function for mouse up though, because my function already does some a bit more complex logic, new function would just be a mess.

Can I somehow find out did the user stop sliding slider (released mouse button) from inside of OnValueChanged ?

 FooSlider.onValueChanged.AddListener(delegate { sliderMgr(someinteger, someObject2, sliderval); });
 
 void sliderMgr(int one, myEnum, float val)
 {
   // Can I find out if user released mouse or slider here?
 }

I generate a lot of sliders by the way, and all are controlled by one function.

Once user leaves the slider I would need to store value, an index for an array, then type of that slider and so on.

If there is a way to figure out if user released slider in that function above, onValueChanged, it would be amazing!

P.S. I'm using UGUI.

Thanks.

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Huacanacha · Apr 03, 2015 at 04:00 AM

OnValueChanged is unlikely to be triggered when the slider is released. You can check this by running a small test in the editor... Input.GetMouseButtonUp() is not set when OnValueChanged occurs, and in fact for me seems to always occur at least 2 frames later.

Can you explain more exactly what you are trying to do? If I know your intent it's easier to help.

If you just want to re-use your logic except know if the slider has been released, then just re-use your function:

  • Add EventTrigger to the slider, add an PointerUp callback to for when the slider is released.

  • Add a parameter ( bool mouseUp) to the callback function. Set it always false for OnValueChanged, always true for PointerUp.

That way you call the same code but also pickup the end of sliding event.

Comment
Hamsterlings

People who like this

1 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hamsterlings · Apr 03, 2015 at 02:26 PM 0
Share

Thanks for reply.

As for suggested solution, if I understood you correctly :

1.Add event trigger to slider gameObject 2. Add pointerUp listener to that component 3. Assign it to public function in script that changes state of an boolean to true 4. In my scroll function check if that bool is true and set it to false once function runs, and make changes accordingly.

It doesn't work - because I can't pick up value until I scroll next time and even then I get wrong value.

As for clarification what I need exactly : - I have a lot of sliders that I generate and use same function to control onvaluechanged - Imagine an integer that has value of 200, and that integer is stored in a list - When you scroll the slider, I basically do : integer - slider.value and show this data on UI. However I don't make that change permanent - Once user stops scrolling ( ex. releases slider ) I need to make permanent change to that integer (integer - slider.value), refresh UI, return slider value to 0 and slider.maxVal to integer value.

Either way, onvaluechanged function does a lot of logic currently, it recognizes type of slider, it gets index of list where integer is stored at, it gets whole slider and UI element to change things around them.

If I wanted to implement onMouseUp, I would have to store all those values somewhere and then re-use them in onMouseUp function and I'm just looking for better way to do that.

avatar image Huacanacha · Apr 04, 2015 at 12:38 AM 0
Share

You can get the slider value directly using GetComponent().value. Does this not work in the PointerUp event?

For your function I'm saying you do NOT need to write the same logic again. I'm saying to call the same function from both OnValueChanged and PointerUp with a flag to indicate the difference. Something like this:

  1. FooSlider.onValueChanged.AddListener(delegate { sliderMgr(someinteger, someObject2, sliderval, false); });

  2. Same thing for PointerUp via EventTrigger except last parameter is true: callbackEntry.callback.AddListener(delegate { sliderMgr(someinteger, someObject2, sliderval, true); });

  3. Add parameter to function:

    void sliderMgr(int one, myEnum, float val, bool isFinal) { .... if (isFinal) { // Do final processing } }

Adding a listener to EventTrigger is a little more complicated. See the answer here for a guide.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UI System for Non-minimal User Interfaces 0 Answers

Simple UI not appearing once deployed to iOS (4.6.2) 1 Answer

Universal Method of finding pixel dimensions of UI elements 1 Answer

Set InputField non-interactable without clearing text 1 Answer

Slider and Input Field Value Updates 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges