//use to retrive the available matches //@param 1: the game type to search //@param 2: the result to be called once the gamelist connected //@param 3: the search time public static void RetrieveAvailableMatches( string pGameType, OnFoundMatches pResult, float pSearchTime) { if( mResultMatches == null ) GameController.mUpdateDelegate += SearchUpdate; mResultMatches = pResult; mElapsedTime = Time.time; mSearchTime = pSearchTime; MasterServer.ClearHostList(); MasterServer.RequestHostList( pGameType); }
//use to search any avaiable game //@paramL the ucrrent time static void SearchUpdate( float pCurrentTime ) { if( MasterServer.PollHostList().Length == 0 ) { //Debug.Log(pCurrentTime - mElapsedTime); //check if done searching if( mSearchTime > -1 && pCurrentTime - mElapsedTime > mSearchTime ) { GameController.mUpdateDelegate -= SearchUpdate; mResultMatches( null); mResultMatches = null; } } else { GameController.mUpdateDelegate -= SearchUpdate; mResultMatches( MasterServer.PollHostList()); mResultMatches = null; } }