• [3D跑酷] UI事件处理系统


    在我们的Unity游戏项目中,GUI的表现采用NGUI。记录一下我们的处理方式:

    需要解决的问题

    1、需要处理大量按钮的点击事件

    2、需要处理界面跳转事件

    3、需要处理界面元素更新事件

    解决方案

    GUIClickEventReceiver

    解决按钮点击事件

    GUIManager

    管理GUI的跳转与更新

    具体实现

    Inspector选择事件

    在编辑器中为按钮选择点击事件

    imageimage

    事件代码结构

    image

    主要逻辑

    public void OnClick ()
        {
            bool playSoundEffect = true;
            switch (clickType) {
            case ClickType.StartGame:
                GameManager.instance.startGame ();
                break;
            case ClickType.Store:
                GUIManager.instance.showGUI (GUIState.Store);
                break;
            case ClickType.Stats:
                GUIManager.instance.showGUI (GUIState.Stats);
                break;
            case ClickType.DoubleCoinUpgrade:
                GameManager.instance.upgradePowerUp (PowerUpTypes.DoubleCoin);
                break;
            case ClickType.CoinMagnetUpgrade:
                GameManager.instance.upgradePowerUp (PowerUpTypes.CoinMagnet);
                break;
            case ClickType.InvincibilityUpgrade:
                GameManager.instance.upgradePowerUp (PowerUpTypes.Invincibility);
                break;
            case ClickType.AddSpeedUpgrade:
                GameManager.instance.upgradePowerUp (PowerUpTypes.AddSpeed);
                break;
            case ClickType.ProtectionCoverUpgrade:
                GameManager.instance.upgradePowerUp(PowerUpTypes.ProtectionCover);
                break;
            case ClickType.AttackGunUpgrade:
                GameManager.instance.upgradePowerUp(PowerUpTypes.AttackGun);
                break;
            case ClickType.EndGame:
                GUIManager.instance.showGUI (GUIState.EndGame);
                break;
            case ClickType.Restart:
                GameManager.instance.restartGame (true);
                break;
            case ClickType.MainMenu:
                GameManager.instance.backToMainMenu (false);
                break;
            case ClickType.MainMenuRestart:
                GameManager.instance.backToMainMenu (true);
                break;
            case ClickType.Pause:
                GameManager.instance.pauseGame (true);
                playSoundEffect = false;
                break;
            case ClickType.Resume:
                GameManager.instance.pauseGame (false);
                break;
            case ClickType.ToggleTutorial:
                GameManager.instance.toggleTutorial ();
                break;
            case ClickType.Missions:
                GUIManager.instance.showGUI (GUIState.Missions);
                break;
            }
    
            if (playSoundEffect)
                AudioManager.instance.playSoundEffect (SoundEffects.GUITapSoundEffect);
        }
  • 相关阅读:
    枚举-完美立方
    list
    undefined reference to `typeinfo for xxx 报错
    bubble排序
    Iframe跨域传值
    Iframe------父子页面传值
    LDAP 概念
    覆盖equals()要覆盖HashCode()
    HashSet和TreeSet的实现与原理
    jvm调优
  • 原文地址:https://www.cnblogs.com/zhaoqingqing/p/3398791.html
Copyright © 2020-2023  润新知