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 Ortaz · Jul 06, 2018 at 10:26 AM · loadinghtmlloading screen

How to check is the game loaded in index.html?

How to check is the gameInstance in index.html is loaded? I have code:

 var gameInstance = UnityLoader.instantiate("gameContainer", "Build/webGLDom.json", {onProgress: UnityProgress});
 
 function SendToPlayer(func,what){
     gameInstance.SendMessage("SocialManager",func,what);
 }
 
 function handleVisibilityChange() {
     if (!document.visibilityState == "hidden") {
         SendToPlayer("OnGameVisible","true");
     }
 }
 document.addEventListener('visibilitychange', handleVisibilityChange, false);

But If I open another tab when the game is loading, I have an error. So I need to except such situation by adding code

 [if(gameinstance.MethodToGetIsTheGameLoaded())...][1]

is there such method?

alt text

безымянныи.png (26.5 kB)
Comment
Add comment
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
0
Best Answer

Answer by Hellium · Jul 06, 2018 at 11:31 AM

1st solution : JS-side only

 var gameIsRunning = false ;
 
 
 var settings =
 {
     onProgress: UnityProgress,
     Module:
     {
         preRun: [ function() { console.log("About to run....") ; } ],
         postRun: [ function() { console.log("The game is running!") ; gameIsRunning = true ; } ],
     }
 };
 var gameInstance = UnityLoader.instantiate("gameContainer", "Build/webGLDom.json", settings ) ;

postRun may be called too soon. You may want the second solution


2nd solution : plugin JS + call function in Awake

 // gameStateController.jslib, in your Unity plugins
 mergeInto(LibraryManager.library,
 {
     OnGameStarted: function ()
     {
           window.gameIsRunning = true ;
     }
 }
 
 // GameStateController.cs, in your Unity scripts
 
 public class GameStateController : MonoBehaviour
 {
     [DllImport("__Internal")]
     private static extern void OnGameStarted();
 
     private void Awake()
     {
         OnGameStarted() ;
     }
 }

 // In your JS code

 window.gameIsRunning = false ;    
 
 var settings =
 {
     onProgress: UnityProgress
 };
 var gameInstance = UnityLoader.instantiate("gameContainer", "Build/webGLDom.json", settings ) ;



Comment
Add comment · Show 4 · 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 Ortaz · Jul 06, 2018 at 12:30 PM 0
Share

Oh, the second solution is obvious, Thank You!

avatar image Hellium Ortaz · Jul 06, 2018 at 12:43 PM 0
Share

If this answer helped you solve your problem, would you please accept it for future readers? (Just click on the "Accept" button at the bottom of the answer). Thanks in advance, and good luck !

avatar image Ortaz Hellium · Jul 06, 2018 at 02:07 PM 0
Share

Sure :) Also It would be very good if you link me some guide how to create .jslib (I wrote my functions in index.html and use Application.ExternalCall() ). I saw that I have to create .jslib, I understand how to call functions by [DllImport("__Internal")] from C#, but don't understand, how to create .jslib file and associate it with my game, with code which is generated in index.html by Unity or with GameInstance and etc. So I need to understand the process of creating such a file and adding it to the project. Somehow can't find a guide on youtube.

Show more comments

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

147 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 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

How to predict/Estimate scene loading time before loading the scene?,A quick and/or reliable way to predict/estimate scene loading time? 0 Answers

Gear VR Loading screen freeze 0 Answers

Delaying WebGL player loading until user input 0 Answers

I'm trying to create a progress loading bar and i keep getting the error message, "NullReferenceException: Object reference not set to an instance of an object". I'm kinda new to Unity, what am i doing wrong, am i missing something? 1 Answer

Loading Bar For Each Canvas in a Scene 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