Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by doraemoe · Apr 09, 2017 at 01:28 PM · buttoneventsystemonclick

Display loading indicator during onClick event?

Hi,

I'm working on a function where user could load a song by clicking a button and the system will generate some data based on the song. Everthing works fine but I found the time takes to generate data from song maybe long. Thus I'm thinking create a "loading indicator" during the data generating process. My current code is as follows:

 public void OpenFile () {
         
         var extensions = new [] {
             new ExtensionFilter("Music Files", "ogg"),
         };
 
         var path = StandaloneFileBrowser.OpenFilePanel(
             "Open File", 
             System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop), 
             extensions, 
             false);
 
         if (path[0].Length != 0) {
             songLocation = new System.Uri(path[0]).AbsolutePath; 
             songLocation = WWW.UnEscapeURL (songLocation);
             StartCoroutine (LoadSongCoroutine (path[0]));
         }
     }
 
 
     IEnumerator LoadSongCoroutine(string path)
     {
         var audioLocation = new WWW (path);
 
         yield return audioLocation;
 
         StartIndicator ();
 
         audioSource.clip = audioLocation.GetAudioClip (false, false);
         GenerateData ();
 
         StopIndicator ();
 
     }

The OpenFile () function is called whenever user clicked a button.

I intend the StartIndicator () function to cover the screen with a blur image and display a spining indicator on it. However, this simply does not work.

I tried to use Debug.Log to see when the two StartIndicator () and StopIndicator () functions work. It turn out they are called only after everything has done. I tried to log something directly after the OpenFile() function, the log only display in the console after file opened and data collected.

I'm thinking this problem maybe related to how Unity handles OnClick event? How can I work this out?

Thank you.

Comment
Add comment · Show 3
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 SohailBukhari · Apr 10, 2017 at 06:45 AM 0
Share

Call StartIndicator () before creating a new object.

 IEnumerator LoadSongCoroutine(string path)
          {
              StartIndicator (); // should be here
              var audioLocation = new WWW (path);
      
              yield return audioLocation;
  
              audioSource.clip = audioLocation.GetAudioClip (false, false);
              GenerateData ();
      
              StopIndicator ();
      
          }

avatar image doraemoe SohailBukhari · Apr 10, 2017 at 12:46 PM 0
Share

Thank you, it works!

Could you please explain why I need to call StartIndicator () before creating a new object?

avatar image SohailBukhari doraemoe · Apr 10, 2017 at 01:33 PM 0
Share

its because when you var audioLocation = new WWW (path); create new object of www request then its response returns after some time not immediately so i said call StartIndicator before creating object.

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

99 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 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 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 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 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 button not working (2D) [Solved] 2 Answers

check if-statement/bool when button is pressed? 1 Answer

Setting button.onClick.AddListener saids: InvalidCastException: Cannot cast from source type to destination type. 1 Answer

Button reacts six times upon one click (undesired) 0 Answers

OnClick() event script from a prefab 0 Answers


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