/// <summary>
        /// Registers the a created LaunchSite to the PSystemSetup and LaunchSiteManager
        /// </summary>
        /// <param name="site"></param>
        internal static void RegisterLaunchSite(LaunchSite site)
        {
            if (!string.IsNullOrEmpty(site.LaunchSiteName) && site.parentInstance.gameObject.transform.Find(site.LaunchPadTransform) != null)
            {
                site.parentInstance.gameObject.transform.name = site.LaunchSiteName;
                site.parentInstance.gameObject.name           = site.LaunchSiteName;

                List <PSystemSetup.SpaceCenterFacility> facilities = PSystemSetup.Instance.SpaceCenterFacilities.ToList();

                if (facilities.Where(fac => fac.facilityName == site.LaunchSiteName).FirstOrDefault() == null)
                {
                    //Log.Normal("Registering LaunchSite: " + site.LaunchSiteName);
                    PSystemSetup.SpaceCenterFacility newFacility = new PSystemSetup.SpaceCenterFacility();
                    newFacility.name                  = "";
                    newFacility.facilityName          = site.LaunchSiteName;
                    newFacility.facilityPQS           = site.parentInstance.CelestialBody.pqsController;
                    newFacility.facilityTransformName = site.parentInstance.gameObject.name;
                    // newFacility.facilityTransform = site.lsGameObject.transform.Find(site.LaunchPadTransform);
                    //     newFacility.facilityTransformName = instance.gameObject.transform.name;
                    newFacility.pqsName = site.body.pqsController.name;
                    PSystemSetup.SpaceCenterFacility.SpawnPoint spawnPoint = new PSystemSetup.SpaceCenterFacility.SpawnPoint();
                    spawnPoint.name = site.LaunchSiteName;
                    spawnPoint.spawnTransformURL = site.LaunchPadTransform;
                    newFacility.spawnPoints      = new PSystemSetup.SpaceCenterFacility.SpawnPoint[1];
                    newFacility.spawnPoints[0]   = spawnPoint;

                    facilities.Add(newFacility);
                    PSystemSetup.Instance.SpaceCenterFacilities = facilities.ToArray();

                    site.facility = newFacility;

                    launchSites.Add(site);
                }
                else
                {
                    Log.Error("Launch site " + site.name + " already exists.");
                }
                MethodInfo updateSitesMI = PSystemSetup.Instance.GetType().GetMethod("SetupFacilities", BindingFlags.NonPublic | BindingFlags.Instance);
                if (updateSitesMI == null)
                {
                    Log.UserError("You are screwed. Failed to find SetupFacilities().");
                }
                else
                {
                    updateSitesMI.Invoke(PSystemSetup.Instance, null);
                }

                if (site.parentInstance.gameObject != null)
                {
                    CustomSpaceCenter.CreateFromLaunchsite(site);
                }
            }
            else
            {
                Log.UserWarning("Launch pad transform \"" + site.LaunchPadTransform + "\" missing for " + site.LaunchSiteName);
            }
        }
Example #2
0
        /// <summary>
        /// Registers the a created LaunchSite to the PSystemSetup and LaunchSiteManager
        /// </summary>
        /// <param name="site"></param>
        internal static void RegisterLaunchSite(KKLaunchSite site)
        {
            if (string.IsNullOrEmpty(site.LaunchSiteName))
            {
                Log.UserWarning("No LaunchSiteName specified:" + site);
                return;
            }


            if (site.isSquad)
            {
                if (site.staticInstance.mesh.transform.Find(site.LaunchPadTransform) == null)
                {
                    Log.UserWarning("Launch pad transform \"" + site.LaunchPadTransform + "\" missing for " + site.LaunchSiteName);
                    return;
                }
            }
            else
            {
                if (site.staticInstance.model.prefab.transform.Find(site.LaunchPadTransform) == null)
                {
                    Log.UserWarning("Launch pad transform \"" + site.LaunchPadTransform + "\" missing for " + site.LaunchSiteName);
                    return;
                }
            }

            KKFacilities = PSystemSetup.Instance.SpaceCenterFacilities.ToList();
            if (KKFacilities.Where(fac => fac.facilityName == site.LaunchSiteName).FirstOrDefault() != null)
            {
                Log.Error("Launch site " + site.LaunchSiteName + " already exists.");
            }


            //site.staticInstance.gameObject.transform.name = site.LaunchSiteName;
            //site.staticInstance.gameObject.name = site.LaunchSiteName;
            Log.Normal("Registering LaunchSite: " + site.LaunchSiteName + " isHidden: " + site.LaunchSiteIsHidden);
            PSystemSetup.SpaceCenterFacility spaceCenterFacility = new PSystemSetup.SpaceCenterFacility();
            spaceCenterFacility.name = site.LaunchSiteName;
            spaceCenterFacility.facilityDisplayName = site.LaunchSiteName;
            spaceCenterFacility.facilityName        = site.LaunchSiteName;
            spaceCenterFacility.facilityPQS         = site.staticInstance.CelestialBody.pqsController;
            spaceCenterFacility.hostBody            = site.staticInstance.CelestialBody;
            spaceCenterFacility.facilityTransform   = site.staticInstance.mesh.transform;
            if (site.LaunchSiteType == SiteType.VAB)
            {
                spaceCenterFacility.editorFacility = EditorFacility.VAB;
            }
            else
            {
                spaceCenterFacility.editorFacility = EditorFacility.SPH;
            }
            spaceCenterFacility.pqsName = site.body.pqsController.name;


            //if (site.staticInstance.groupCenter == null)
            //{
            //    spaceCenterFacility.facilityTransformName = site.staticInstance.gameObject.name;
            //}
            //else
            //{
            //    spaceCenterFacility.facilityTransformName = site.staticInstance.groupCenter.gameObject.name + "/" + site.staticInstance.gameObject.name + "/Mesh";
            //}
            // newFacility.facilityTransform = site.lsGameObject.transform.Find(site.LaunchPadTransform);
            //     newFacility.facilityTransformName = instance.gameObject.transform.name;

            PSystemSetup.SpaceCenterFacility.SpawnPoint spawnPoint = new PSystemSetup.SpaceCenterFacility.SpawnPoint
            {
                name = site.LaunchSiteName,
                spawnTransformURL = site.LaunchPadTransform
            };
            spawnPoint.Setup(spaceCenterFacility);
            spawnPoint.SetSpawnPointLatLonAlt();
            spaceCenterFacility.spawnPoints = new PSystemSetup.SpaceCenterFacility.SpawnPoint[] { spawnPoint };

            //spaceCenterFacility.Setup(new PQS[] { site.staticInstance.CelestialBody.pqsController });

            KKFacilities.Add(spaceCenterFacility);
            KKFacilities.Sort(delegate(PSystemSetup.SpaceCenterFacility a, PSystemSetup.SpaceCenterFacility b)
            {
                if (a.editorFacility == EditorFacility.None)
                {
                    return(1);
                }
                return((a.facilityDisplayName).CompareTo(b.facilityDisplayName));
            });

            PSystemSetup.Instance.SpaceCenterFacilities = KKFacilities.ToArray();
            site.spaceCenterFacility = spaceCenterFacility;

            if (site.staticInstance.destructible != null)
            {
                ScenarioDestructibles.RegisterDestructible(site.staticInstance.destructible, site.LaunchSiteName);
            }

            AddLaunchSite(site);

            if (site.staticInstance.gameObject != null)
            {
                CustomSpaceCenter.CreateFromLaunchsite(site);
            }


            //if (PSystemSetup.Instance.SpaceCenterFacilities.ToList().Where(fac => fac.facilityName == site.LaunchSiteName).FirstOrDefault() != null)
            //{
            //    Log.Normal("LaunchSite registered: " + site.LaunchSiteName);
            //}
            //else
            //{
            //    Log.Normal("LaunchSite registration failed: " + site.LaunchSiteName);
            //}
        }
        /// <summary>
        /// Registers the a created LaunchSite to the PSystemSetup and LaunchSiteManager
        /// </summary>
        /// <param name="site"></param>
        internal static void RegisterLaunchSite(KKLaunchSite site, bool isSquad = false)
        {
            if (!string.IsNullOrEmpty(site.LaunchSiteName) && site.lsGameObject.transform.Find(site.LaunchPadTransform) != null)
            {
                site.lsGameObject.transform.name = site.LaunchSiteName;
                site.lsGameObject.name           = site.LaunchSiteName;

                if (KKFacilities == null)
                {
                    KKFacilities = PSystemSetup.Instance.SpaceCenterFacilities.ToList();
                }

                if (KKFacilities.Where(fac => fac.facilityName == site.LaunchSiteName).FirstOrDefault() == null)
                {
                    //Log.Normal("Registering LaunchSite: " + site.LaunchSiteName);
                    PSystemSetup.SpaceCenterFacility spaceCenterFacility = new PSystemSetup.SpaceCenterFacility();
                    spaceCenterFacility.name = site.LaunchSiteName;
                    spaceCenterFacility.facilityDisplayName   = site.LaunchSiteName;
                    spaceCenterFacility.facilityName          = site.LaunchSiteName;
                    spaceCenterFacility.facilityPQS           = site.staticInstance.CelestialBody.pqsController;
                    spaceCenterFacility.facilityTransformName = site.staticInstance.gameObject.name;
                    // newFacility.facilityTransform = site.lsGameObject.transform.Find(site.LaunchPadTransform);
                    //     newFacility.facilityTransformName = instance.gameObject.transform.name;
                    spaceCenterFacility.pqsName = site.body.pqsController.name;
                    PSystemSetup.SpaceCenterFacility.SpawnPoint spawnPoint = new PSystemSetup.SpaceCenterFacility.SpawnPoint();
                    spawnPoint.name = site.LaunchSiteName;
                    spawnPoint.spawnTransformURL       = site.LaunchPadTransform;
                    spaceCenterFacility.spawnPoints    = new PSystemSetup.SpaceCenterFacility.SpawnPoint[1];
                    spaceCenterFacility.spawnPoints[0] = spawnPoint;
                    if (site.LaunchSiteType == SiteType.VAB)
                    {
                        spaceCenterFacility.editorFacility = EditorFacility.VAB;
                    }
                    else
                    {
                        spaceCenterFacility.editorFacility = EditorFacility.SPH;
                    }

                    KKFacilities.Add(spaceCenterFacility);
                    site.spaceCenterFacility = spaceCenterFacility;

                    AddLaunchSite(site);
                }
                else
                {
                    Log.Error("Launch site " + site.LaunchSiteName + " already exists.");
                }

                RegisterLaunchSitesStock(site);


                if (site.staticInstance.gameObject != null)
                {
                    CustomSpaceCenter.CreateFromLaunchsite(site);
                }
            }
            else
            {
                Log.UserWarning("Launch pad transform \"" + site.LaunchPadTransform + "\" missing for " + site.LaunchSiteName);
            }
        }