0
\$\begingroup\$

I'm basically having a large amount of code for UI, and it seems to be making my animation freezeup for a bit. I can't write paste the whole code here, but, here's an explanation of what's going on:

  1. PanRot is a panel that has an animator component attached to it, and all it does it play's the infinite rotation animation. It rotates 360 deg on it's z axis, it's basically a loading animation.
  2. MainUI is the class that builds all the list and components for my app
  3. Main is the parent class, where both these components come together for the app.

So, basically what I want to do is, play the loading animation, while the MainUI is building the main ui. Considering the large amount of lists that I have, and some fancy button, it takes about 2 seconds for the UI to build. (It also has some network requests), so, I have the pseudocode here that shows it:

Main {
   Instantiate(PanRot, gameObject.transform);
   StartBuilding(MainUI);
   DisableLoadingAnimation(PanRot);
}

Since the animator is attached to PanRot, the animation panel appears and starts playing the animation immediately. The problem is, while the UI is building, the rotation animation freezes. It almost looks as if, the UI stuff is all done in a single thread. So, I need to run the animation in a parallel thread if it is possible. How to handle this for unity? (Also, the StartBuilding(MainUI) isn't a code I can do in a coroutine, if that at all is a possible solution). Thanks in advance, please let me know what can I do about this.

EDIT: more detail on the code:

Main{
  //Instantiate PanRot UI component and play the animator associated animation
   
  //Main UI building process
  - Construct main parent(Instantiate Panel with width and size dynamically calculated - 80% width and 90% height)
  - make network request to fetch player data
  - wait for network response
  - got about 10K user data
  - parse JSON data into a data structure
  - Instantiate(RowPrefab for each data, into earlier constructed parent)
  - configure the instance for width and height,and onClick attributes)
  - the instance is kept on a vertically scrollable list, so, height of their direct parent is also calculated dynamically.
  - finally stop the loading animation using Destroy(PanRot)
 
}
\$\endgroup\$
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.