Version: 2020.1

Mathf.ClosestPowerOfTwo

切换到手册
public static int ClosestPowerOfTwo (int value);

描述

返回最接近的 2 的幂值。

using UnityEngine;

public class Example : MonoBehaviour { void Start() { // prints 8 Debug.Log(Mathf.ClosestPowerOfTwo(7));

// prints 16 Debug.Log(Mathf.ClosestPowerOfTwo(19)); } }