예제 #1
0
    static string m_BGMName = "";                  //背景因为的名字
    void ChangeBG(MenuInfo menu, int up_count = 0) //切换背景
    {
        string spriteName = "";

        switch (menu.menu)
        {
        case GameMenu.MainMenu:
            m_BGMName = "Main";
            break;

        case GameMenu.Boss:
        case GameMenu.Dungeon:
        case GameMenu.PVP:
            m_BGMName = "Adventure";
            break;
        }

        SoundManager.Instance.PlayBGM(m_BGMName); //播放背景音乐

        switch (menu.menu)
        {
        case GameMenu.MainMenu:
            spriteName = "000_main";
            m_BG.material.SetColor("_GrayColor", colorZero);
            break;

        case GameMenu.HeroInfoDetail:
            spriteName = "000_heroinfo";
            m_BG.material.SetColor("_GrayColor", colorZero);
            break;

        case GameMenu.Dungeon:
            spriteName = menu.GetComponent <Dungeon>().MapInfo.ID + "_map";
            break;

        case GameMenu.DungeonInfo:
        {
            MapStageDifficulty stage_info = menu.GetComponent <DungeonInfoMenu>().StageInfo;
            if (stage_info.MapInfo.MapType == "boss")
            {
                spriteName = stage_info.BG_ID + "_D";
            }
            else
            {
                ChangeBG(GetParentMenu(up_count + 1), up_count + 1);
            }
        }
        break;

        case GameMenu.WorldBossInfo:
            ChangeBG(GetParentMenu(up_count + 1), up_count + 1);
            break;

        case GameMenu.PVP:
        case GameMenu.PVPDeckInfo:
            spriteName = "000_pvp";
            m_BG.material.SetColor("_GrayColor", colorZero);
            break;

        case GameMenu.HeroesEval:
            spriteName = "000_hero_loot";
            m_BG.material.SetColor("_GrayColor", colorZero);
            break;

        case GameMenu.Inventory:
        case GameMenu.HeroesInfo:
        case GameMenu.Mission:
        case GameMenu.Store:
            ChangeBG(GetParentMenu(up_count + 1), up_count + 1);
            return;

        case GameMenu.Boss:
            spriteName = "000_boss_map";
            m_BG.material.SetColor("_GrayColor", colorZero);
            break;

        case GameMenu.Training:
            spriteName = "000_training";
            m_BG.material.SetColor("_GrayColor", colorZero);
            break;

        case GameMenu.Community:
        case GameMenu.Friends:
            spriteName = "000_community";
            m_BG.material.SetColor("_GrayColor", colorZero);
            break;
        }

        if (string.IsNullOrEmpty(spriteName) == false)
        {
            Texture2D sp = AssetManager.LoadBG(spriteName);
            m_BG.material.mainTexture = sp;
            if (sp != null)
            {
                if (spriteName == "000_main")
                {
                    if (m_BGAdd.material.mainTexture == null)
                    {
                        m_BGAdd.material.mainTexture = AssetManager.LoadBG(spriteName + "_add");
                    }
                    m_BGAdd.gameObject.SetActive(true);
                }
                else
                {
                    m_BGAdd.gameObject.SetActive(false);
                }
            }
        }
    }