示例#1
0
        public Templates()
        {
            instance = this;

            mapsGray = new Dictionary<string, MapSO>();
            mapsRGB = new Dictionary<string, MapSO>();
            origMapSOs = new List<MapSO>();
            origTextures = new List<Texture>();
            GetUsedLists(origMapSOs, origTextures, PSystemManager.Instance.systemPrefab.rootBody);

            PSystemBody kerbin = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Kerbin");
            if (kerbin.scaledVersion != null)
            {
                origKerbinDiff = kerbin.scaledVersion.renderer.material.GetTexture("_MainTex");
                origKerbinBump = kerbin.scaledVersion.renderer.material.GetTexture("_BumpMap");
            }

            PSystemBody mun = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Mun");
            if (mun.scaledVersion != null)
            {
                origMunDiff = mun.scaledVersion.renderer.material.GetTexture("_MainTex");
                origMunBump = mun.scaledVersion.renderer.material.GetTexture("_BumpMap");
            }

            // get reference geosphere
            // We need to get the body for Jool (to steal it's mesh)
            PSystemBody Jool = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Jool");

            // Return it's mesh
            refGeosphere = Jool.scaledVersion.GetComponent<MeshFilter>().sharedMesh;

            // Initialize the Sphere-Lists
            sphereOfInfluence = new Dictionary<string, double>();
            hillSphere = new Dictionary<string, double>();

            // Initialize the barycenter list
            barycenters = new List<string>();

            finalizeBodies = new List<string>();
        }
示例#2
0
        /**
         * Awake() is the first function called in the lifecycle of a Unity3D MonoBehaviour.  In the case of KSP,
         * it happens to be called right before the game's PSystem is instantiated from PSystemManager.Instance.systemPrefab
         *
         * TL,DR - Custom planet injection happens here
         *
         **/
        public void Awake()
        {
            // We're ALIVE
            Logger.Initialize();
            Logger.Default.SetAsActive ();
            Logger.Default.Log("Injector.Awake(): Begin");

            // Yo garbage collector - we have work to do man
            DontDestroyOnLoad(this);

            // If the planetary manager does not work, well, error out
            if (PSystemManager.Instance == null)
            {
                // Log the error
                Logger.Default.Log("Injector.Awake(): If PSystemManager.Instance is null, there is nothing to do");
                return;
            }

            // Get the current time
            DateTime start = DateTime.Now;

            // Grab templates
            templates = new Templates();

            // THIS IS WHERE THE MAGIC HAPPENS - OVERWRITE THE SYSTEM PREFAB SO KSP ACCEPTS OUR CUSTOM SOLAR SYSTEM AS IF IT WERE FROM SQUAD
            PSystemManager.Instance.systemPrefab = (new Configuration.Loader()).Generate();

            // SEARCH FOR THE ARCHIVES CONTROLLER PREFAB AND OVERWRITE IT WITH THE CUSTOM SYSTEM
            RDArchivesController archivesController = AssetBase.RnDTechTree.GetRDScreenPrefab ().GetComponentsInChildren<RDArchivesController> (true).First ();
            archivesController.systemPrefab = PSystemManager.Instance.systemPrefab;

            // Add the BaryCenter controller
            archivesController.gameObject.AddComponent<BarycenterUtils.RDBaryCenter>();

            // Clear space center instance so it will accept nouveau Kerbin
            SpaceCenter.Instance = null;

            // Add a handler so that we can do post spawn fixups.
            PSystemManager.Instance.OnPSystemReady.Add(PostSpawnFixups);

            // Done executing the awake function
            TimeSpan duration = (DateTime.Now - start);
            Logger.Default.Log("Injector.Awake(): Completed in: " + duration.TotalMilliseconds + " ms");
            Logger.Default.Flush ();
        }