private void FillRadarList()
        {
            radars = BDAEditorCategory.getRadars().ToArray();

            // first pass, then sort
            for (int i = 0; i < radars.Length; i++)
            {
                if (string.IsNullOrEmpty(radars[i].radarName))
                {
                    radars[i].radarName = radars[i].part?.partInfo?.title;
                }
                GUIContent gui = new GUIContent(radars[i].radarName);
            }
            Array.Sort(radars, delegate(ModuleRadar r1, ModuleRadar r2) { return(r1.radarName.CompareTo(r2.radarName)); });

            // second pass to copy
            radarsGUI = new GUIContent[radars.Length];
            for (int i = 0; i < radars.Length; i++)
            {
                GUIContent gui = new GUIContent(radars[i].radarName);
                radarsGUI[i] = gui;
            }

            radarBoxText      = new GUIContent();
            radarBoxText.text = "Select Radar... **";
        }
        private void Awake()
        {
            Instance = this;
            bool partsDetected = false;

            using (var parts = PartLoader.LoadedPartsList.GetEnumerator())
                while (parts.MoveNext())
                {
                    if (parts.Current == null || !parts.Current.partPrefab || parts.Current.partConfig == null)
                    {
                        continue;
                    }
                    if (parts.Current.partConfig.HasValue(BDACategoryKey) || parts.Current.manufacturer == Misc.BDAEditorTools.Manufacturer)
                    {
                        partsDetected = true;
                        GameEvents.onGUIEditorToolbarReady.Add(LoadBDArmoryCategory);
                        break;
                    }
                }
            // Part autocategorization
            if (partsDetected)
            {
                using (var parts = PartLoader.LoadedPartsList.GetEnumerator())
                    while (parts.MoveNext())
                    {
                        if (parts.Current.partConfig == null || parts.Current.partPrefab == null)
                        {
                            continue;
                        }
                        if (parts.Current.partConfig.HasValue(BDACategoryKey))
                        {
                            parts.Current.partConfig.AddValue(AutoBDACategoryKey, parts.Current.partConfig.GetValue(BDACategoryKey));
                        }
                        else
                        {
                            ModuleWeapon    moduleWeapon;
                            MissileLauncher missileLauncher;
                            if ((moduleWeapon = parts.Current.partPrefab.FindModuleImplementing <ModuleWeapon>()) != null)
                            {
                                if (moduleWeapon.weaponType == "laser")
                                {
                                    if (parts.Current.partPrefab.FindModuleImplementing <ModuleTurret>())
                                    {
                                        parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Laser turrets");
                                    }
                                    else
                                    {
                                        parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Lasers");
                                    }
                                }
                                if (moduleWeapon.weaponType == "rocket")
                                {
                                    if (parts.Current.partPrefab.FindModuleImplementing <ModuleTurret>())
                                    {
                                        parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Rocket turrets");
                                    }
                                    else
                                    {
                                        parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Rocketlaunchers");
                                    }
                                }
                                else
                                {
                                    if (parts.Current.partPrefab.FindModuleImplementing <ModuleTurret>())
                                    {
                                        parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Gun turrets");
                                    }
                                    else
                                    {
                                        parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Guns");
                                    }
                                }
                            }
                            else if ((missileLauncher = parts.Current.partPrefab.FindModuleImplementing <MissileLauncher>()) != null)
                            {
                                // weapon class is not parsed when in editor, so using missileType
                                if (missileLauncher.missileType.ToLower() == "bomb")
                                {
                                    parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Bombs");
                                }
                                else if (missileLauncher.missileType.ToLower() == "torpedo" || missileLauncher.missileType.ToLower() == "depthcharge")
                                {
                                    parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Torpedoes");
                                }
                                else
                                {
                                    parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Missiles");
                                }
                            }
                            else if (parts.Current.partPrefab.FindModuleImplementing <MissileTurret>() != null)
                            {
                                parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Missile turrets");
                            }
                            else if (parts.Current.partPrefab.FindModuleImplementing <ModuleRadar>() != null)
                            {
                                parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Radars");
                            }
                            else if (parts.Current.partPrefab.FindModuleImplementing <ModuleTargetingCamera>() != null)
                            {
                                parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Targeting");
                            }
                            else if (parts.Current.partPrefab.FindModuleImplementing <MissileFire>() != null ||
                                     parts.Current.partPrefab.FindModuleImplementing <IBDAIControl>() != null)
                            {
                                parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Control");
                            }
                            else if (parts.Current.partPrefab.FindModuleImplementing <ModuleECMJammer>() != null ||
                                     parts.Current.partPrefab.FindModuleImplementing <CMDropper>() != null)
                            {
                                parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Countermeasures");
                            }
                            else
                            {
                                using (var resource = parts.Current.partPrefab.Resources.GetEnumerator())
                                    while (resource.MoveNext())
                                    {
                                        // Very dumb check, but right now too lazy to implement a better one
                                        if (resource.Current.resourceName.Contains("Ammo"))
                                        {
                                            parts.Current.partConfig.AddValue(AutoBDACategoryKey, "Ammo");
                                        }
                                    }
                            }
                        }
                    }
            }
        }