Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Alex on April 14, 2012, 10:16:44 AM

Title: UISlider
Post by: Alex on April 14, 2012, 10:16:44 AM
Hi,
I still need to use ForceUpdate in order to update the UISlider.
please add it to your fix list.

Thanks
Title: Re: UISlider
Post by: ArenMook on April 14, 2012, 01:57:10 PM
A small reproduceable example would help a lot because I couldn't reproduce the problem when I tried.
Title: Re: UISlider
Post by: Alex on April 15, 2012, 04:48:23 AM
  1.  using UnityEngine;
  2.  
  3.  
  4.     public class CSoundControl : MonoBehaviour
  5.     {
  6.         public UISlider musicSlider;
  7.         public UISlider soundSlider;
  8.  
  9.  
  10.  
  11.         void Start()
  12.         {
  13.  
  14.  
  15.             UIEventListener.Get(soundSlider.gameObject).onPress += OnSoundReleased;
  16.             UIEventListener.Get(musicSlider.gameObject).onPress += OnMusicReleased;
  17.  
  18.             if (musicSlider != null)
  19.             {
  20.                 musicSlider.sliderValue = GenericService.GetMusicVolume();
  21.                 if(CMusic.instance!=null){
  22.                         CMusic.instance.Play(MusicType.Game,musicSlider.sliderValue);
  23.                 }
  24.             }
  25.  
  26.             if (soundSlider != null)
  27.             {
  28.                 soundSlider.sliderValue = GenericService.GetSoundVolume();
  29.             }
  30.  
  31.             musicSlider.ForceUpdate();
  32.         }
  33.  
  34.  
  35.  
  36.         void OnMusicVolume()    //musicSlider function - event
  37.         {
  38.             if (CMusic.instance != null && musicSlider != null)
  39.                 CMusic.instance.SetVolume(musicSlider.sliderValue);
  40.         }
  41.  
  42.         void OnSoundVolume() { }    //soundSlider function - event
  43.        
  44.  
  45.         void OnSoundReleased(GameObject go, bool pSet)
  46.         {
  47.             if (pSet != true)
  48.             {
  49.                 if (CSound.instance != null)
  50.                 {
  51.                     CSound.instance.SetVolume(soundSlider.sliderValue);
  52.                     CSound.instance.Play(soundSlider.sliderValue);
  53.                 }
  54.  
  55.                 GenericService.SetSoundVolume(soundSlider.sliderValue);
  56.  
  57.             }
  58.         }
  59.  
  60.         void OnMusicReleased(GameObject go, bool pSet)
  61.         {
  62.  
  63.                         if( pSet!=true ){
  64.                                 GenericService.SetMusicVolume( musicSlider.sliderValue );
  65.                                 if(CMusic.instance!=null )
  66.                                         if( !CMusic.instance.IsPlayaing() )
  67.                             CMusic.instance.Play(MusicType.Menu,GenericService.GetMusicVolume() );
  68.                         }
  69.         }
  70.  
  71.  
  72.  
  73.  
  74.     }
Title: Re: UISlider
Post by: ArenMook on April 15, 2012, 05:01:15 AM
Thanks, but CMusic, CSound, GenericService, etc... You're using classes here that don't exist in the NGUI's package, therefore I can't run it.
Title: Re: UISlider
Post by: Alex on April 15, 2012, 05:24:49 AM
 using UnityEngine;


    public class CSoundControl : MonoBehaviour
    {
        public UISlider musicSlider;
        public UISlider soundSlider;

        void Start()
        {
            UIEventListener.Get(soundSlider.gameObject).onPress += OnSoundReleased;
            UIEventListener.Get(musicSlider.gameObject).onPress += OnMusicReleased;

         
            musicSlider.sliderValue = 1f;
            soundSlider.sliderValue = 1f;

            //musicSlider.ForceUpdate();
        }



        void OnMusicVolume()
        {

         
        }

        void OnSoundVolume() { }

        void OnSoundReleased(GameObject go, bool pSet)
        {
         
        }

        void OnMusicReleased(GameObject go, bool pSet)
        {

         
        }




    }
Title: Re: UISlider
Post by: Alex on April 15, 2012, 04:54:15 PM
Hi,
I wonder if my code helped you reproduce the problem with UISlider.
Title: Re: UISlider
Post by: ArenMook on April 15, 2012, 07:39:26 PM
Hey Alex, yes it has, thank you. Line 136 of UISlider.cs, change it from:
  1. Set(rawValue, false);
to:
  1. Set(rawValue, true);
Title: Re: UISlider
Post by: ArenMook on April 15, 2012, 07:42:13 PM
Btw, if you don't want to modify the code, simply set your sliders to start at 1.0 by adjusting the "Value" in the inspector. Same effect.
Title: Re: UISlider
Post by: Alex on April 16, 2012, 02:41:16 AM
Thanks Aren, that's solved the problem,hope to see the fix in the next version or else
i'll forget i made changes to UISlider in line 136 when new version will come. :)
Title: Re: UISlider
Post by: ArenMook on April 16, 2012, 09:14:41 AM
It's already fixed in 2.0.1