答案 0 :(得分:0)
您可以像这样访问java.lang.Class和java.lang.Object。
AndroidJavaClass unityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic< AndroidJavaObject > ("currentActivity");
从这里你应该能够设置GUI组件,按钮和点击监听器来模仿警报对话框
有关进一步理解,请参阅this post
答案 1 :(得分:0)
我为你做了一个小例子
这就是我想的全部(我试着对代码进行评论 参考),Reference
public class QuitHandler : MonoBehaviour {
public CanvasGroup uiCanvasGroup;
public CanvasGroup confirmQuitCanvasGroup;
// Use this for initialization
private void Awake()
{
//disable the quit confirmation panel
DoConfirmQuitNo();
}
/// <summary>
/// Called if clicked on No (confirmation)
/// </summary>
public void DoConfirmQuitNo()
{
Debug.Log("Back to the game");
//enable the normal ui
uiCanvasGroup.alpha = 1;
uiCanvasGroup.interactable = true;
uiCanvasGroup.blocksRaycasts = true;
//disable the confirmation quit ui
confirmQuitCanvasGroup.alpha = 0;
confirmQuitCanvasGroup.interactable = false;
confirmQuitCanvasGroup.blocksRaycasts = false;
}
/// <summary>
/// Called if clicked on Yes (confirmation)
/// </summary>
public void DoConfirmQuitYes()
{
Debug.Log("Ok bye bye");
Application.Quit();
}
/// <summary>
/// Called if clicked on Quit
/// </summary>
public void DoQuit()
{
Debug.Log("Check form quit confirmation");
//reduce the visibility of normal UI, and disable all interraction
uiCanvasGroup.alpha = 0.5f;
uiCanvasGroup.interactable = false;
uiCanvasGroup.blocksRaycasts = false;
//enable interraction with confirmation gui and make visible
confirmQuitCanvasGroup.alpha = 1;
confirmQuitCanvasGroup.interactable = true;
confirmQuitCanvasGroup.blocksRaycasts = true;
}
/// <summary>
/// Called if clicked on new game (example)
/// </summary>
public void DoNewGame()
{
Debug.Log("Launch a new game");
}