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?