BZ易风

导航

 

1.拼UI,挂载对应控件

2.脚本GameSetting.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum GameGrade
{
    ESAY,
    NORMAL,
    DIFFCULTY
}
public enum ControlType
{
    KEYBOARD,
    TOUCH,
    MOUSE
}
public class GameSetting : MonoBehaviour
{
    public  float soundVolume = 1;                          //声音
    public  GameGrade grade = GameGrade.NORMAL;             //游戏难度
    public  ControlType controller = ControlType.KEYBOARD;  //操作方式
    public  bool isFullScreen = false;                      //是否全屏

    public TweenPosition startTween;                        //开始界面移出动画
    public TweenPosition optionTween;                       //设置界面移入动画

    //监听声音设置
    public void OnSoundChange()
    {
        soundVolume = UISlider.current.value;   // 固定格式 :脚本名.current.value   获取监听的值 
    }

    //监听难度控制
    public void OnGradeChange()
    {
        switch(UIPopupList.current.value.Trim())   //PopupList监听属性值的时候,会把换行符一并取到,所以要用Trim()去除两边换行符、制表符、空格等无效字符
        {
            case "容易":
                grade = GameGrade.ESAY;
                break;
            case "NORMAL":
                grade = GameGrade.NORMAL;
                break;
            case "DEFFICULTY":
                grade = GameGrade.DIFFCULTY;
                break;
        }
    }

    //监听操作方式
    public void OnCtrlTypeChange()
    {
        switch (UIPopupList.current.value.Trim())   //PopupList监听属性值的时候,会把换行符一并取到,所以要用Trim()去除两边换行符、制表符、空格等无效字符
        {
            case "KEYBOARD":
                controller = ControlType.KEYBOARD;
                break;
            case "MOUSE":
                controller = ControlType.MOUSE;
                break;
            case "TOUCH":
                controller = ControlType.TOUCH;
                break;
        }
    }
    //监听是否全屏
    public void OnToggleChange()
    {
        isFullScreen = UIToggle.current.value;
    }
    //点击设置
    public void SettingButtonClick()
    {
        startTween.PlayForward();           //正常播放start界面移出场景动画                    PlayForward() 正常播放
        optionTween.PlayForward();          //播放设置界面进入场景动画
    }
    //点击完成设置,回到开始界面
    public void SettingEndButtonClick()
    {
        optionTween.PlayReverse();          //倒序播放设置界面进入场景动画,即设置界面移出场景  PlayReverse() 反向播放
        startTween.PlayReverse();           //倒叙播放开始界面移出场景动画,即开始界面返回场景
    }
}

 

posted on 2021-11-03 23:46  BZ易风  阅读(71)  评论(0编辑  收藏  举报