今天在编写工具时发现了一个有趣的Unity方法叫MaskField.但是在查看原文档的时候发现没有如何判断自己选了哪几个选项的方法,所以自己通过试验写了个判定的方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
using UnityEngine; using UnityEditor;
public class MaskFieldExample : EditorWindow { static int flags = 0; static string[] options = new string[] {"CanJump", "CanShoot", "CanSwim"};
[MenuItem("Examples/Mask Field usage")] static void Init() { MaskFieldExample window = (MaskFieldExample)GetWindow(typeof(MaskFieldExample)); window.Show(); }
void OnGUI() { flags = EditorGUILayout.MaskField("Player Flags", flags, options); if (GUILayout.Button("Log options")) { for (int i = 0; i < options.Length; i++) { if ((flags & 1 << i) != 0) { Debug.Log(options[i]); } } } }
}
|
近期评论