private void CloseTradeScene() { StopSceneLogic(); GameSceneManager.CloseTradeScene(); }
private IEnumerator MainTradeSceneCoroutine() { #region Initial Setup waitingForPlayerChoice = false; tradeReadyToExecute = false; //Check arguments are set if (!TradeEntranceArguments.argumentsSet) { Debug.LogError("Trade entrance arguments not set"); GameSceneManager.CloseTradeScene(); yield break; } //Set up trade stage tradeStage = 0; //Read entrance arguments networkStream = TradeEntranceArguments.networkStream; otherUserName = TradeEntranceArguments.otherUserName; disallowedSendPokemonGuids = TradeEntranceArguments.disallowedSendPokemonGuids; //Set the other user's displayed name according to newly-read-from-entrance-arguments name tradeUIController.RefreshOtherUserName(); //Initialise offered pokemon playerOfferedPokemonLocator = null; otherUserOfferedPokemon = null; //Create comms manager commsManager = new Connection.NetworkTradeCommsManager( stream: networkStream, serializer: Serialize.DefaultSerializer); //Start listening commsManager.StartListening(); #endregion #region Trade Decision Loop tradeUIController.SetInteractionEnabled(true); while (true) { #region Comm Receiving Connection.NetworkCommsManager.Comm comm = commsManager.GetNextComm(); if (comm != null) { yield return(StartCoroutine(HandleTradeComm(comm))); } #endregion #region Actions Needing To Be Taken if (locatorToBeConfirmed != null) { if (tradeStage != TradeStage.ChoosingOffer && tradeStage != TradeStage.ConfirmingOfferChoice) { Debug.LogError("Locator to be confirmed has been set when not in correct trade stage"); } else if (tradeStage == TradeStage.ChoosingOffer) { yield return(StartCoroutine(SetTradeStage(TradeStage.ConfirmingOfferChoice))); } } else if (tryingToConfirmCloseTrade) { if (tradeStage != TradeStage.ChoosingOffer) { Debug.LogError("Trying to close trade when not in correct trade stage"); } else { tryingToConfirmCloseTrade = false; yield return(StartCoroutine(SetTradeStage(TradeStage.ConfirmingCancelTrade))); } } else if (needToNotifyPlayerDisallowedTrade) { if (tradeStage != TradeStage.ChoosingOffer && tradeStage != TradeStage.ConfirmingOfferChoice) { Debug.LogError("Trying to notify player of disallowed offer when not choosing offer pokemon"); } else { needToNotifyPlayerDisallowedTrade = false; textBoxController.Show(); yield return(StartCoroutine( textBoxController.RevealText(otherUserName + disallowedOfferPokemonMessageSuffix, true) )); textBoxController.Hide(); } } #endregion #region Other user making decision being waited for //Waiting for other user's offer and other user's offer has been set if (tradeStage == TradeStage.WaitingForOtherUserOffer && otherUserOfferedPokemon != null) { yield return(StartCoroutine(SetTradeStage(TradeStage.DecidingOnOffer))); } //Waiting for other user decision on offer and other user has accepted trade if (tradeStage == TradeStage.WaitingForOtherUserDecisionOnOffer && otherUserAcceptedTrade) { tradeReadyToExecute = true; break; //Break loop to execute trade } #endregion #region User Making Choices during Trade Stages if (waitingForPlayerChoice) { if (textBoxController.userChoiceIndexSelected >= 0) //If choice has been made { switch (tradeStage) { case TradeStage.ConfirmingOfferChoice: yield return(StartCoroutine(ConfirmOfferChoiceMade())); break; case TradeStage.WaitingForOtherUserOffer: yield return(StartCoroutine(CancelOfferedPokemon())); break; case TradeStage.DecidingOnOffer: yield return(StartCoroutine(DecisionOnOfferChoiceMade())); break; case TradeStage.ConfirmingCancelTrade: yield return(StartCoroutine(ConfirmCancelTradeChoiceMade())); break; default: Debug.LogError("Text box waiting for user choice when not on selection trade stage"); break; } } } #endregion if (commsManager.CommsConnErrorOccured) { break; } yield return(new WaitForFixedUpdate()); } #endregion #region Dealing with Circumstances of Loop Breaking if (tradeReadyToExecute) //Trade decided successfully { CloseNetworking(); tradeUIController.Hide(); yield return(StartCoroutine(ExecuteTrade())); CloseTradeScene(); } else if (commsManager.CommsConnErrorOccured) //Connection error occured { yield return(StartCoroutine( textBoxController.RevealText(connErrorOccuredMessage, true) )); CloseTradeScene(); } else //Unknown reason { Debug.LogError("Main trade scene loop closed for unknown reason"); GameSceneManager.CloseTradeScene(); } #endregion }