UnityEditor.GenericMenu.GetItemCount C# (CSharp) Method

GetItemCount() public method

public GetItemCount ( ) : int
return int
        public int GetItemCount()
        {
            return this.menuItems.Count;
        }

Usage Example

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var left  = position; left.xMax -= 40;
            var right = position; right.xMin = left.xMax + 2;

            EditorGUI.PropertyField(left, property);

            if (GUI.Button(right, "List") == true)
            {
                var menu = new GenericMenu();

                if (LeanLocalization.Instance != null)
                {
                    for (var j = 0; j < LeanLocalization.Instance.Languages.Count; j++)
                    {
                        var language = LeanLocalization.Instance.Languages[j];

                        menu.AddItem(new GUIContent(language), property.stringValue == language, () => { property.stringValue = language; property.serializedObject.ApplyModifiedProperties(); });
                    }
                }

                if (menu.GetItemCount() > 0)
                {
                    menu.DropDown(right);
                }
                else
                {
                    Debug.LogWarning("Your scene doesn't contain any languages, so the language name list couldn't be created.");
                }
            }
        }
All Usage Examples Of UnityEditor.GenericMenu::GetItemCount