コード例 #1
0
 /// <summary>
 /// 显示游戏结束UI
 /// </summary>
 public void ShowGameOver()
 {
     img_GameOver.gameObject.SetActive(true);
     if (GameManager.curGameModel != GameModel.Game)
     {
         img_GameOver.GetComponent <Animator>().enabled = true;
         img_GameOver.GetComponent <Animator>().SetTrigger("isGameOver");
     }
     else
     {
         img_GameOver.GetComponent <Animator>().enabled = false;
         img_GameOver.transform.localPosition           = new Vector3(snakeMoveScript.transform.localPosition.x, snakeMoveScript.transform.localPosition.y, 0);
     }
     //写入数据 数据持久化
     StartScene.WriteDataToRegister(SnakeHead.curSnakeLength, int.Parse(txt_Score.text), int.Parse(txt_Kiss.text));
 }
コード例 #2
0
    public void Start()
    {
        #region 初始化数据
        txt_Length.text = "1";
        txt_Score.text  = "0";
        txt_Kiss.text   = "0";
        img_GameOver.gameObject.SetActive(false);
        img_AudioVolume.gameObject.SetActive(false);
        img_Win.gameObject.SetActive(false);

        //隐藏杀敌数UI
        if (GameManager.curGameModel != GameModel.Game)
        {
            title_KissContainer.gameObject.SetActive(false);
        }
        //隐藏边框
        if (GameManager.curGameModel == GameModel.Normal)
        {
            GameObject[] borders = GameObject.FindGameObjectsWithTag("Wall");
            foreach (var item in borders)
            {
                item.GetComponent <Image>().enabled = false;
            }
        }

        //根据游戏的模式  更新UI模式
        SetUIBySelectModel();

        if (GameManager.curGameModel != GameModel.Game)
        {
            GameObject.Find("Canvas_Enemy").SetActive(false);
        }
        #endregion

        #region 右上角功能按钮
        btn_Enum.onClick.AddListener(() =>
        {
            //切换菜单界面
            SceneManager.LoadScene("StartScene");
        });
        btn_Parse.onClick.AddListener(() =>
        {
            //暂停
            if (Time.timeScale == 1)
            {
                Time.timeScale = 0;
                btn_Parse.GetComponent <Button>().image.sprite = spr_Play;
                btn_Parse.GetComponent <Button>().image.color  = Color.red;
            }
            //播放
            else if (Time.timeScale == 0)
            {
                Time.timeScale = 1;
                btn_Parse.GetComponent <Button>().image.sprite = spr_Parse;
                btn_Parse.GetComponent <Button>().image.color  = Color.black;
            }
        });

        //切换旋转方式
        btn_ChangeTurn.onClick.AddListener(() =>
        {
            snakeMoveScript.ChangeTurnType();
        });
        #endregion

        #region 重启游戏逻辑
        //重启游戏
        btn_AgainGame.onClick.AddListener(() =>
        {
            //TODO
            txt_Length.text = "1";
            txt_Score.text  = "0";
            txt_Kiss.text   = "0";
            img_GameOver.GetComponent <Animator>().SetTrigger("isGameOver");
            img_GameOver.GetComponent <Animator>().SetTrigger("isRestartGame");
            StartCoroutine("WaitHide");
            snakeMoveScript.ReStartGame();
            GameObject.Find("AudioManager").GetComponent <AudioManager>().PlayAudio(0);
            if (GameManager.curGameModel == GameModel.Game)
            {
                GameObject.FindGameObjectWithTag("EnemyHead").GetComponent <EnemyAI>().ReStartGame();
            }
        });
        //返回主菜单
        btn_ReturnStartScene.onClick.AddListener(() =>
        {
            //切换菜单界面
            SceneManager.LoadScene("StartScene");
            img_GameOver.gameObject.SetActive(false);
            Time.timeScale = 1;
        });
        #endregion

        #region  一关卡
        btn_Next.onClick.AddListener(() =>
        {
            //TODO
            txt_Length.text = "1";
            txt_Score.text  = "0";
            img_Win.gameObject.SetActive(false);
            snakeMoveScript.ReStartGame();
            GameObject.Find("AudioManager").GetComponent <AudioManager>().PlayAudio(0);
            if (GameManager.curGameModel == GameModel.Game)
            {
                //GameObject.FindGameObjectWithTag("EnemyHead").GetComponent<EnemyAI>().PlayerWinNextLevel();
                GameObject.FindGameObjectWithTag("EnemyHead").GetComponent <EnemyAI>().ReStartGame();
            }
        });
        btn_BackStartScene.onClick.AddListener(() =>
        {
            //写入数据 数据持久化
            StartScene.WriteDataToRegister(SnakeHead.curSnakeLength, int.Parse(txt_Score.text), int.Parse(txt_Kiss.text));
            //切换菜单界面
            SceneManager.LoadScene("StartScene");
            img_Win.gameObject.SetActive(false);
            Time.timeScale = 1;
        });
        #endregion

        #region 小地图交互
        btn_MiniMapAdd.onClick.AddListener(() =>
        {
            GameObject.FindGameObjectWithTag("MainCamera").GetComponent <ExampleInteractions>().MiniMapInteraction(true);
        });
        btn_MiniMapSub.onClick.AddListener(() =>
        {
            GameObject.FindGameObjectWithTag("MainCamera").GetComponent <ExampleInteractions>().MiniMapInteraction(false);
        });
        #endregion

        #region 音量调节事件
        //打开/关闭 画布
        btn_Audio.onClick.AddListener(() =>
        {
            if (img_AudioVolume.IsActive())
            {
                img_AudioVolume.gameObject.SetActive(false);
            }
            else
            {
                img_AudioVolume.gameObject.SetActive(true);
            }
        });
        //关闭画布
        btn_ExitAudioVolume.onClick.AddListener(() =>
        {
            if (img_AudioVolume.IsActive())
            {
                img_AudioVolume.gameObject.SetActive(false);
            }
        });

        #endregion
    }