退出确认屏幕为Android游戏统一

时间:2016-01-29 13:31:57

标签: java c# unity3d

我正在使用统一制作自己的安卓游戏,我想像这样制作退出确认屏幕:

enter image description here

如何使用c#进行制作?

2 个答案:

答案 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)

我为你做了一个小例子

  1. 将以下脚本附加到游戏对象(例如画布)
  2. 添加到普通用户的根(例如面板)a CanvasGroup组件
  3. 添加到退出确认ui的根目​​录(例如面板)a CanvasGroup组件
  4. 将两个画布组链接到放置脚本的游戏对象
  5. 对于每个按钮(退出,确认是,确认否)添加检查器 一个onclick事件到脚本对应的方法
  6. 这就是我想的全部(我试着对代码进行评论 参考),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");
     }