private static AddComponentMenuItem GetOrCreateRootItem(string label, Type type)
        {
            for (int n = rootGroups.Length - 1; n >= 0; n--)
            {
                var test = rootGroups[n];
                if (test.type == type)
                {
                    return(test);
                }
            }

            //create the item if it didn't exist
            var newItem = AddComponentMenuItem.Item(type, label, null);

            ArrayExtensions.Add(ref rootGroups, newItem);

            return(newItem);
        }
        private static AddComponentMenuItem GetOrCreateGroup(ref List <string> groupsLabels, AddComponentMenuItem parent, ref AddComponentMenuItem[] options, Texture icon)
        {
            //first try to find an existing group with given group labels
            string rootGroup = groupsLabels[0];

            for (int i = options.Length - 1; i >= 0; i--)
            {
                var group = options[i];
                if (string.Equals(group.label, rootGroup))
                {
                    groupsLabels.RemoveAt(0);
                    if (groupsLabels.Count > 0)
                    {
                        var result = GetOrCreateGroup(ref groupsLabels, group, ref group.children, icon);
                        groupsLabels.Clear();
                        return(result);
                    }
                    groupsLabels.Clear();
                    return(group);
                }
            }

            //create the group if it didn't exist
            var newGroup = AddComponentMenuItem.Group(rootGroup, parent, icon);

                        #if DEV_MODE
            int countBeforeAdd = options.Length;
                        #endif

            ArrayExtensions.Add(ref options, newGroup);

                        #if DEV_MODE
            Debug.Assert(options.Length == countBeforeAdd + 1);
                        #endif

            if (groupsLabels.Count > 1)
            {
                groupsLabels.RemoveAt(0);
                newGroup = GetOrCreateGroup(ref groupsLabels, parent, ref newGroup.children, icon);
            }
            groupsLabels.Clear();
            return(newGroup);
        }
        public void AddChild(string classLabel, Type setType)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            if (string.Equals(label, "Unity Engine"))
            {
                Debug.LogError("AddComponentMenu Item \"" + classLabel + "\" being created under \"Unity Engine\" group. Type should be added under a more descriptive Group in InspectorPreferences.addComponentMenuConfig.");
            }
                        #endif

                        #if DEV_MODE && PI_ASSERTATIONS
            int countBeforeAdd = children.Length;
                        #endif

            var addItem = Item(setType, classLabel, this);
            ArrayExtensions.Add(ref children, addItem);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(children.Length == countBeforeAdd + 1);
                        #endif
        }