Beispiel #1
0
    public override void OnCreate()
    {
        base.OnCreate();
        m_mainMenuExtend = UIWindowManager.Singleton.CreateWindow <UIWindow>("UIMainMenuExtend", UIWindowManager.Anchor.Left);

        m_quitBtn  = m_mainMenuExtend.GetChildComponent <UIButton>("QuitBtn");
        m_soundBtn = m_mainMenuExtend.GetChildComponent <UIButton>("SoundBtn");
        m_musicBtn = m_mainMenuExtend.GetChildComponent <UIButton>("MusicBtn");

        m_soundIcon = m_mainMenuExtend.GetChildComponent <UISprite>("SoundIcon");
        m_musicIcon = m_mainMenuExtend.GetChildComponent <UISprite>("MusicIcon");

        m_mainMenuBtnText = m_mainMenuExtend.GetChildComponent <UISprite>("QuitBtnText");

        m_mainMenuExtend.AddChildComponentMouseClick("QuitBtn", OnQuitClicked);
        m_mainMenuExtend.AddChildComponentMouseClick("HelpBtn", delegate()
        {
            UIWindowManager.Singleton.GetUIWindow <UIHowToPlay>().ShowWindow();
            m_mainMenuExtend.HideWindow();
        });

        m_mainMenuExtend.AddChildComponentMouseClick("SoundBtn", delegate()
        {
            GlobalVars.UseSFX = !GlobalVars.UseSFX;
            PlayerPrefs.SetInt("SFX", GlobalVars.UseSFX == true ? 1 : 0);
            RefreshIcons();
        });

        m_mainMenuExtend.AddChildComponentMouseClick("MusicBtn", delegate()
        {
            GlobalVars.UseMusic = !GlobalVars.UseMusic;
            PlayerPrefs.SetInt("Music", GlobalVars.UseMusic == true ? 1 : 0);
            if (GlobalVars.UseMusic == false)       //关闭音乐
            {
                UIToolkits.StopMusic();
            }
            else                                    //播放音乐
            {
                if (!UIToolkits.IsPlayingMusic())
                {
                    if (CapsApplication.Singleton.CurStateEnum != StateEnum.Game)
                    {
                        UIToolkits.PlayMusic(CapsConfig.CurAudioList.MapMusic);
                    }
                    else
                    {
                        GameLogic.Singleton.PlayMusic();
                    }
                }
            }
            RefreshIcons();
        });

        m_mainMenuExtend.AddChildComponentMouseClick("MainBtn", HideExtendMainMenu);

        m_mainMenuExtend.AddChildComponentMouseClick("HideBtn", HideExtendMainMenu);



        AddChildComponentMouseClick("MainBtn", delegate()
        {
            m_mainMenuExtend.ShowWindow();
            RefreshIcons();
            if (CapsApplication.Singleton.CurStateEnum != StateEnum.Game && !UIWindowManager.Singleton.GetUIWindow <UIMap>().Visible)        //Login画面
            {
                m_quitBtn.gameObject.SetActive(false);
            }
            else
            {
                m_quitBtn.gameObject.SetActive(true);
            }

            if (CapsApplication.Singleton.CurStateEnum == StateEnum.Game)
            {
                GameLogic.Singleton.PauseGame();
            }

            HideWindow();
        });
    }