Sometimes we need to do processing in a different thread other then Unity Ui Thread. In Unity everything is handled in Ui thread; however you can of course create other treads.
The tricky part here is; when non ui thread completes it's job; it should trigger the "callback method" called by Ui thread instead of calling it self directly. (Otherwise Unity would complain that you were trying to access unity libs from a non ui thread and you would also break single thread mechanism.)
In the following code you can see that, DoJobAsync is called from Ui thread; and we pass a JobResultHandler which should be called from Ui thread when the non-ui thread finishes it's job.
In gistfile1.cs#6 you see that we only create a ThreadAdapter if there is a callback parameter to prevent object creation cost. Of course this can be improved by object pooling etc. ThreadAdapter ia created in Ui thread since it is an Unity game object.
After ThreadAdapter is created; in every frame/in x seconds (it's your decision); it checks a volatile variable named waitCall. waitCall is set to false from non-ui thread when it completes it's job in gistfile1.cs#25.
I think the code is more clear :). Please see it below:
I have no words to appreciate you and you done a great job in your blog.i want you to add more like this.
ReplyDeleteJAVA Training in Chennai
JAVA Training in Tnagar
Selenium Training in Chennai
Digital Marketing Course in Chennai
Python Training in Chennai
Big data training in chennai
JAVA Training in Chennai
Java Training in Velachery
keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
ReplyDeletedigital marketing training in bangalore / https://www.excelr.com/digital-marketing-training-in-bangalore
It is actually a great and helpful piece of information. I am satisfied that you simply shared this helpful information with us. Please stay us informed like this. Thanks for sharing.
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteBig Data Hadoop Training In Chennai | Big Data Hadoop Training In anna nagar | Big Data Hadoop Training In omr | Big Data Hadoop Training In porur | Big Data Hadoop Training In tambaram | Big Data Hadoop Training In velachery
HTML (Hypertext Markup Language) is the code that is used to structure a web page and its content. For example, content could be structured within a set of paragraphs, a list of bulleted points, or using images and data tables...
ReplyDeleteinternship in chennai for mechanical
internship in chennai for cse students
internship in chennai for eee
internship in chennai for ece students
internship in chennai for bcom students
internship in chennai for mechanical engineering students
python internship in chennai
internship in chennai for it students
companies offering internship in chennai
internship in chennai for it
Amazing Article,Really useful information to all So, I hope you will share more information to be check and share here.
ReplyDeleteInplant Training for cse
Inplant Training for IT
Inplant Training for ECE Students
Inplant Training for EEE Students
Inplant Training for Mechanical Students
Inplant Training for CIVIL Students
Inplant Training for Aeronautical Engineering Students
Inplant Training for ICE Students
Inplant Training for BIOMEDICAL Engineering Students
Inplant Training for BBA Students
You have provided finicky information for a new blogger so it has turned out to be really obliging. Keep up the good work!
ReplyDeleteData Science training in Mumbai
Data Science course in Mumbai
SAP training in Mumbai
wonderful article contains lot of valuable information. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
ReplyDeleteThis article resolved my all queries.good luck an best wishes to the team members.continue posting.learn digital marketing use these following link
Digital Marketing Course in Chennai