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 RedSuinit · Jul 30, 2016 at 08:08 PM · c#callback

Waiting for User Response for Pop-up window.

Ok, so this is a bit complex.

I am trying to complete a pup-up manager that I can use to process ALL of my pop-up messages that I could incur, and include the potential for user response at the same time. Here is what I have right now. This is the full code to my pop-up manager, and I am trying to develop a callback method for the user responses. I may be going about this all wrong, and I am hoping that someone will be able to help me out. I can't find anything on this particular subject, so I am struggling a bit with this, and I may be attempting to use callbacks for something that they can't really be used for. Here is the Pop-Up Manager code:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System;
 
 public class PopUpManager : MonoBehaviour{
 
     public void NewInterPopUp(string titleString, string messageString, Action<WaitForUserResponse> callback)
     {
         StartCoroutine(ShowNewInterPopUp(titleString, messageString));
     }
 
     public IEnumerator ShowNewPopUp(string titleString, string messageString)
     {
         //Do stuff.
     }
 
     public IEnumerator ShowNewInterPopUp(string titleString, string messageString)
     {
        //Do Stuff.
     }
 
     public void HidePopUp()
     {
         //Do Stuff.
     }
 
     public void Yes()
     {
         WaitForUserResponse response;
         response = new WaitForUserResponse(true);
     }
 
     public void No()
     {
         WaitForUserResponse response;
         response = new WaitForUserResponse(false);
     }
 
     public IEnumerator AnimateText(string strComplete)
     {
         \\Do Stuff
     }
 }
 
 public class WaitForUserResponse : ProcessResponse
 {
     public bool userResponse;
 
     public WaitForUserResponse(bool response)
     {
         userResponse = response;
     }
 
     public bool response
     {
         get
         {
             return userResponse;
         }
         set
         {
             userResponse = value;
         }
     }
 }
 
 public interface ProcessResponse
 {
     bool response
     {
         get;
         set;
     }
 }

Here is where I am generating a Pop-Up from another script.

     public void LoginToServices()
     {
         Social.localUser.Authenticate((bool success) =>
         {
             if (success)
             {
                 OpenSavedGame("SavedGame");
             }
             else
             {
                 PopUpManager.instance.NewInterPopUp("Error!", "Google Play services could not login, try again?", OnLoginFailed);
             }
         });
     }
 
     public void OnLoginFailed(WaitForUserResponse ans)
     {
         if (ans.response == true)
         {
             LoginToServices();
         }
         else
         {
             PopUpManager.instance.ShowNewPopUp("", "Using local data. Next time you are connected cloud data will update with local progress.");
         }
     }

I have a yes button and a no button that correspond to;

 public void Yes()
     {
         WaitForUserResponse response;
         response = new WaitForUserResponse(true);
     }
 
     public void No()
     {
         WaitForUserResponse response;
         response = new WaitForUserResponse(false);
     }

In the Pop-Up Manager code. This however does not seem to send the callback to the function where I am calling for the callback.

What am I doing wrong here?

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 Spykill · Jul 30, 2016 at 11:12 PM

In your Yes and No methods, you have a LOCAL variable called "responses". You then instantiate that local variable to be "new WaitForUserResponse(" and either true or false depending on whether you pressed Yes or No. But then you don't do anything with this local variable. What you need to do is call the Action callback, which you have in your NewInterPopUp. What you could do is store this callback as a variable in PopUpManager, and then in your Yes and No function do "callback(response);". Unfortunately this means you can only have one pop up at a time, since the callback variable will be overwritten. There are ways to have multiple pop ups at once, but that depends on how you implement your pop up. So for the callback variable:

  public class PopUpManager : MonoBehaviour{
     Action<WaitForUserResponse> callback;

For setting it:

 public void NewInterPopUp(string titleString, string messageString, Action<WaitForUserResponse> callback)
 {
     this.callback = callback;

And for calling it (this one applies to both Yes and No, just change up the method name and the bool):

  public void Yes()
  {
     WaitForUserResponse response;
     response = new WaitForUserResponse(true);
     callback(response);
  }

Good luck!

Comment
Add comment · Show 1 · 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 RedSuinit · Jul 30, 2016 at 11:57 PM 0
Share

Thank you for your help. I've been working on this for so long I had blinders on, and didn't even see that.

Thanks.

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

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

Unity Custom Editor - Lauch callback at the end of the SerializeField. 0 Answers

Callback when vuforia AR camera finishes loading 0 Answers

UI Text is not being rebuilt/updated in edit mode, when changing text from OnInspectorGUI 1 Answer

How to call a non-static method from another class without using an instance 1 Answer

What is a Callback? 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