public static void ShowAsDropDown(Rect buttonRect, int mask, Action<int> onClose) { window = ScriptableObject.CreateInstance<LayerMaskWindow>(); window.wantsMouseMove = true; LayerMaskWindow.mask = mask; LayerMaskWindow.onClose = onClose; layerNames.SetValues(null); hover = -1; int count = 0; string name; for(int i=0; i<32; i++) { name = LayerMask.LayerToName(i); if(!string.IsNullOrEmpty(name)) { layerNames[i] = ' ' + name; count++; } } size.x = buttonRect.x; size.y = buttonRect.y; size = EditorGUIUtility.GUIToScreenPoint(size); buttonRect.x = size.x; buttonRect.y = size.y; size.x = windowWidth; size.y = buttonHeight + lineHeight * count + 4 * interval; window.ShowAsDropDown(buttonRect, size); }
public static void ShowAsDropDown(Rect buttonRect, int mask, Action <int> onClose) { window = ScriptableObject.CreateInstance <LayerMaskWindow>(); window.wantsMouseMove = true; LayerMaskWindow.mask = mask; LayerMaskWindow.onClose = onClose; layerNames.SetValues(null); hover = -1; int count = 0; string name; for (int i = 0; i < 32; i++) { name = LayerMask.LayerToName(i); if (!string.IsNullOrEmpty(name)) { layerNames[i] = ' ' + name; count++; } } size.x = buttonRect.x; size.y = buttonRect.y; size = EditorGUIUtility.GUIToScreenPoint(size); buttonRect.x = size.x; buttonRect.y = size.y; size.x = windowWidth; size.y = buttonHeight + lineHeight * count + 4 * interval; window.ShowAsDropDown(buttonRect, size); }
// 层掩码绘制 public static void LayerMaskField(Rect rect, GUIContent label, int mask, Action <int> onClose) { string text = null; if (mask == 0) { text = "Nothing"; } else if (mask == (~0)) { text = "Everything"; } else { for (int i = 0; i < 32; i++) { if (mask.GetBit(i)) { text = LayerMask.LayerToName(i); if (string.IsNullOrEmpty(text)) { text = "Mixed..."; } else if (mask.SetBit0(i) != 0) { text += ", ..."; } break; } } } if (GUI.Button(rect = EditorGUI.PrefixLabel(rect, label), text)) { LayerMaskWindow.ShowAsDropDown(rect, mask, onClose); } }