枚举的使用

其实概念我都懂但是就是不知道咋用

枚举我懂得用过一次
就是在我想在inspector面板上的时候我如果想有下拉框,就需要

[SerializeField]
private DotweenType _dotweenType = DotweenType.MovementOneWay;
private enum DotweenType
{
    MovementOneWay,
    MovementTwoWay,
    MovementOneWayColorChange,
    MovementTwoWayWithSequence,
    MovementOneWayColorChangeWithScale
}

这是一次使用
还有一次使用是在kinect中获得相应关节的位置的时候

leftHandPos = kinectManager.GetJointPosition(primaryUserID, (int)KinectInterop.JointType.HandLeft);

public enum JointType : int
    {
		SpineBase = 0,
		SpineMid = 1,
        Neck = 2,
        Head = 3,
        ShoulderLeft = 4,
    }

刚刚看到的一个是使用枚举来简化游戏开发

要求是:如果用户按下向上的箭头,剑图标就会淡入淡出,显示它被选中。此时,如果用户再次按下按钮,将执行与up按钮相关的命令。

void Update()
    {
        //Standard input calls.
        if (Input.GetButtonDown("Up"))
        {
            if (currentSel == Selection.Up)
            {
                //Executes if we already have up selected and user presses up again
                buttonUp.onClick.Invoke(); //Call up button's OnClick() function
                currentSel = Selection.None; //set currentSel back to None
            }
            else
            {
                currentSel = Selection.Up; // changes currentSel to Up.
                StartCoroutine(FadeIcon(imgUp, currentSel)); //Begins fading the icon
            }
        }
        //The same code pattern from above is repeated for the rest of the inputs
        else if (Input.GetButtonDown("Down"))
        {
            if (currentSel == Selection.Down)
            {
                buttonDown.onClick.Invoke();
                currentSel = Selection.None;
            }
            else
            {
                currentSel = Selection.Down;
                StartCoroutine(FadeIcon(imgDown, currentSel));
            }
        }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值