예제 #1
0
 // Patch the KSC light animation
 private static void PatchTimeOfDayAnimation()
 {
     TimeOfDayAnimation[] animations = Resources.FindObjectsOfTypeAll <TimeOfDayAnimation>();
     for (Int32 i = 0; i < animations.Length; i++)
     {
         animations[i].target = KopernicusStar.GetNearest(FlightGlobals.GetHomeBody()).gameObject.transform;
     }
 }
            /// <summary>
            /// Get the nearest star
            /// </summary>
            void GetTarget()
            {
                if (HighLogic.LoadedScene == GameScenes.PSYSTEM)
                {
                    return;
                }
                CelestialBody body = PSystemManager.Instance.localBodies.Find(b => b.transform.name == transform.name);

                target = KopernicusStar.GetNearest(body).sun.scaledBody.transform;
            }
예제 #3
0
        // Use the nearest star as the AFG star
        private void AtmosphereLightPatch(CelestialBody body)
        {
            if (!body.afg)
            {
                return;
            }

            GameObject star           = KopernicusStar.GetNearest(body).gameObject;
            Vector3    afgCamPosition = body.afg.mainCamera.transform.position;
            Vector3    distance       = body.scaledBody.transform.position - afgCamPosition;

            body.afg.lightDot = Mathf.Clamp01(Vector3.Dot(distance, afgCamPosition - star.transform.position) * body.afg.dawnFactor);
            body.afg.GetComponent <Renderer>().sharedMaterial.SetFloat(_lightDot, body.afg.lightDot);
        }
예제 #4
0
        // Stuff
        void LateUpdate()
        {
            FixZooming();
            ApplyOrbitVisibility();
            RDFixer();

            foreach (CelestialBody body in PSystemManager.Instance.localBodies.Where(b => b.afg != null))
            {
                GameObject star_      = KopernicusStar.GetNearest(body).gameObject;
                Vector3    planet2cam = body.scaledBody.transform.position - body.afg.mainCamera.transform.position;
                body.afg.lightDot = Mathf.Clamp01(Vector3.Dot(planet2cam, body.afg.mainCamera.transform.position - star_.transform.position) * body.afg.dawnFactor);
                body.afg.GetComponent <Renderer>().material.SetFloat("_lightDot", body.afg.lightDot);
            }
        }
예제 #5
0
        private void LateUpdate()
        {
            GameScenes scene = HighLogic.LoadedScene;

            if (scene != GameScenes.FLIGHT && scene != GameScenes.SPACECENTER && !MapView.MapIsEnabled)
            {
                return;
            }

            if (this.Body == null)
            {
                return;
            }

            ScaledSpaceOnDemand ondemand = this.Body.scaledBody.GetComponent <ScaledSpaceOnDemand>();

            if (ondemand != null)
            {
                ondemand.isLoaded = true;
            }

            GameObject stb = ScaledTiltedBody.gameObject;
            GameObject sb  = ScaledBody.gameObject;

            if (!ScaledBody)
            {
                ScaledBody = this.Body.scaledBody;

                if (!ScaledBody)
                {
                    return;
                }
            }


            stb.transform.position = sb.transform.position;

            //Make tilt correctly. The universe seems to be kerbinocentered, eh.
            stb.transform.up = _Kerbin.scaledBody.transform.TransformDirection(this.RotationAxis);
            stb.transform.Rotate(Vector3.up, (float)_Kerbin.rotationAngle, Space.World);
            //Then *actually*, *finally* rotate it.
            stb.transform.Rotate(Vector3.up, -(float)_Kerbin.rotationAngle + sb.transform.rotation.eulerAngles.y, Space.Self);

            UpdateMaterials();

            Vector3 dir = (ScaledTiltedBody.transform.position - KopernicusStar.GetNearest(this.Body).sun.scaledBody.transform.position).normalized;

            dir = ScaledTiltedBody.transform.worldToLocalMatrix * dir;
            ScaledTiltedMR.sharedMaterials[TiltManager.StockMaterialIndex].SetVector("_localLightDirection", dir);
        }
예제 #6
0
        // Patch various references to point to the nearest star
        private static void PatchStarReferences(CelestialBody body)
        {
            GameObject star = KopernicusStar.GetNearest(body).gameObject;

            if (body.afg != null)
            {
                body.afg.sunLight = star;
            }
            if (body.scaledBody.GetComponent <MaterialSetDirection>() != null)
            {
                body.scaledBody.GetComponent <MaterialSetDirection>().target = star.transform;
            }
            foreach (PQSMod_MaterialSetDirection msd in
                     body.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true))
            {
                msd.target = star.transform;
            }
        }
예제 #7
0
        // Awake() - flag this class as don't destroy on load and register delegates
        void Awake()
        {
            // Don't run if Kopernicus isn't compatible
            if (!CompatibilityChecker.IsCompatible())
            {
                Destroy(this);
                return;
            }

            // Make sure the runtime utility isn't killed
            DontDestroyOnLoad(this);

            // Add handlers
            GameEvents.onPartUnpack.Add(OnPartUnpack);
            GameEvents.onLevelWasLoaded.Add(FixCameras);
            GameEvents.onLevelWasLoaded.Add(delegate(GameScenes scene)
            {
                if (HighLogic.LoadedSceneHasPlanetarium && MapView.fetch != null)
                {
                    MapView.fetch.max3DlineDrawDist = 20000f;
                }
                if (scene == GameScenes.MAINMENU)
                {
                    UpdateMenu();
                }
                if (scene == GameScenes.SPACECENTER)
                {
                    PatchFI();
                }
                foreach (CelestialBody body in PSystemManager.Instance.localBodies)
                {
                    GameObject star_ = KopernicusStar.GetNearest(body).gameObject;
                    if (body.afg != null)
                    {
                        body.afg.sunLight = star_;
                    }
                    if (body.scaledBody.GetComponent <MaterialSetDirection>() != null)
                    {
                        body.scaledBody.GetComponent <MaterialSetDirection>().target = star_.transform;
                    }
                    foreach (PQSMod_MaterialSetDirection msd in body.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true))
                    {
                        msd.target = star_.transform;
                    }
                }
                foreach (TimeOfDayAnimation anim in Resources.FindObjectsOfTypeAll <TimeOfDayAnimation>())
                {
                    anim.target = KopernicusStar.GetNearest(FlightGlobals.GetHomeBody()).gameObject.transform;
                }
            });

            // Update Music Logic
            if (MusicLogic.fetch != null && FlightGlobals.fetch != null && FlightGlobals.GetHomeBody() != null)
            {
                MusicLogic.fetch.flightMusicSpaceAltitude = FlightGlobals.GetHomeBody().atmosphereDepth;
            }

            // Log
            Logger.Default.Log("[Kopernicus] RuntimeUtility Started");
            Logger.Default.Flush();
        }
예제 #8
0
        // Stuff
        void LateUpdate()
        {
            FixZooming();
            ApplyOrbitVisibility();
            RDFixer();

            // Remove buttons in map view for barycenters
            if (MapView.MapIsEnabled)
            {
                if (fields == null)
                {
                    FieldInfo mode_f    = typeof(OrbitTargeter).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(f => f.FieldType.IsEnum && f.FieldType.IsNested);
                    FieldInfo context_f = typeof(OrbitTargeter).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(f => f.FieldType == typeof(MapContextMenu));
                    FieldInfo cast_f    = typeof(OrbitTargeter).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(f => f.FieldType == typeof(OrbitRenderer.OrbitCastHit));
                    fields = new FieldInfo[] { mode_f, context_f, cast_f };
                }
                if (FlightGlobals.ActiveVessel != null)
                {
                    OrbitTargeter targeter = FlightGlobals.ActiveVessel.orbitTargeter;
                    if (targeter == null)
                    {
                        return;
                    }
                    Int32 mode = (Int32)fields[0].GetValue(targeter);
                    if (mode == 2)
                    {
                        OrbitRenderer.OrbitCastHit cast = (OrbitRenderer.OrbitCastHit)fields[2].GetValue(targeter);
                        CelestialBody body = PSystemManager.Instance.localBodies.Find(b => b.name == cast.or?.discoveryInfo?.name?.Value);
                        if (body == null)
                        {
                            return;
                        }
                        if (body.Has("barycenter") || body.Has("notSelectable"))
                        {
                            if (cast.driver?.Targetable == null)
                            {
                                return;
                            }
                            MapContextMenu context = MapContextMenu.Create(body.name, new Rect(0.5f, 0.5f, 300f, 50f), cast, () =>
                            {
                                fields[0].SetValue(targeter, 0);
                                fields[1].SetValue(targeter, null);
                            }, new SetAsTarget(cast.driver.Targetable, () => FlightGlobals.fetch.VesselTarget));
                            fields[1].SetValue(targeter, context);
                        }
                    }
                }
            }


            foreach (CelestialBody body in PSystemManager.Instance.localBodies)
            {
                if (body.afg == null)
                {
                    continue;
                }
                GameObject star_      = KopernicusStar.GetNearest(body).gameObject;
                Vector3    planet2cam = body.scaledBody.transform.position - body.afg.mainCamera.transform.position;
                body.afg.lightDot = Mathf.Clamp01(Vector3.Dot(planet2cam, body.afg.mainCamera.transform.position - star_.transform.position) * body.afg.dawnFactor);
                body.afg.GetComponent <Renderer>().material.SetFloat("_lightDot", body.afg.lightDot);
            }
        }
예제 #9
0
        // Awake() - flag this class as don't destroy on load and register delegates
        void Awake()
        {
            // Don't run if Kopernicus isn't compatible
            if (!CompatibilityChecker.IsCompatible())
            {
                Destroy(this);
                return;
            }

            // Make sure the runtime utility isn't killed
            DontDestroyOnLoad(this);

            // Init the runtime logging
            new Logger("Kopernicus.Runtime").SetAsActive();

            // Add handlers
            GameEvents.onPartUnpack.Add(OnPartUnpack);
            GameEvents.onLevelWasLoaded.Add(FixCameras);
            GameEvents.OnMapEntered.Add(delegate { _mapDirty = true; });
            GameEvents.onLevelWasLoaded.Add(delegate(GameScenes scene)
            {
                //if (MapView.fetch != null)
                //    MapView.fetch.max3DlineDrawDist = Single.MaxValue;
                if (scene == GameScenes.SPACECENTER)
                {
                    PatchFI();
                }
                foreach (CelestialBody body in PSystemManager.Instance.localBodies)
                {
                    GameObject star = KopernicusStar.GetNearest(body).gameObject;
                    if (body.afg != null)
                    {
                        body.afg.sunLight = star;
                    }
                    if (body.scaledBody.GetComponent <MaterialSetDirection>() != null)
                    {
                        body.scaledBody.GetComponent <MaterialSetDirection>().target = star.transform;
                    }

                    foreach (PQSMod_MaterialSetDirection msd in body.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true))
                    {
                        msd.target = star.transform;
                    }

                    // Contract Weight
                    if (ContractSystem.ContractWeights != null)
                    {
                        if (body.Has("contractWeight"))
                        {
                            if (ContractSystem.ContractWeights.ContainsKey(body.name))
                            {
                                ContractSystem.ContractWeights[body.name] = body.Get <Int32>("contractWeight");
                            }
                            else
                            {
                                ContractSystem.ContractWeights.Add(body.name, body.Get <Int32>("contractWeight"));
                            }
                        }
                    }
                }

                foreach (TimeOfDayAnimation anim in Resources.FindObjectsOfTypeAll <TimeOfDayAnimation>())
                {
                    anim.target = KopernicusStar.GetNearest(FlightGlobals.GetHomeBody()).gameObject.transform;
                }
#if FALSE
                foreach (TimeOfDayAnimation anim in Resources.FindObjectsOfTypeAll <TimeOfDayAnimation>())
                {
                    anim.gameObject.AddOrGetComponent <KopernicusStarTimeOfDay>();
                }

                foreach (GalaxyCubeControl control in Resources.FindObjectsOfTypeAll <GalaxyCubeControl>())
                {
                    control.gameObject.AddOrGetComponent <KopernicusStarGalaxyCubeControl>();
                }

                foreach (SkySphereControl control in Resources.FindObjectsOfTypeAll <SkySphereControl>())
                {
                    control.gameObject.AddOrGetComponent <KopernicusStarSkySphereControl>();
                }
#endif
            });
            GameEvents.onProtoVesselLoad.Add(TransformBodyReferencesOnLoad);
            GameEvents.onProtoVesselSave.Add(TransformBodyReferencesOnSave);

            // Update Music Logic
            if (MusicLogic.fetch != null && FlightGlobals.fetch != null && FlightGlobals.GetHomeBody() != null)
            {
                MusicLogic.fetch.flightMusicSpaceAltitude = FlightGlobals.GetHomeBody().atmosphereDepth;
            }

            // Log
            Logger.Default.Log("[Kopernicus] RuntimeUtility Started");
            Logger.Default.Flush();
        }
예제 #10
0
        // Stuff
        void LateUpdate()
        {
            FixZooming();
            ApplyOrbitVisibility();
            RDFixer();
            ApplyOrbitIconCustomization();

            // Prevent the orbit lines from flickering
            PlanetariumCamera.Camera.farClipPlane = 1e14f;

            // Remove buttons in map view for barycenters
            if (MapView.MapIsEnabled)
            {
                if (fields == null)
                {
                    FieldInfo mode_f    = typeof(OrbitTargeter).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(f => f.FieldType.IsEnum && f.FieldType.IsNested);
                    FieldInfo context_f = typeof(OrbitTargeter).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(f => f.FieldType == typeof(MapContextMenu));
                    #if !KSP131
                    FieldInfo cast_f = typeof(OrbitTargeter).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(f => f.FieldType == typeof(OrbitRendererBase.OrbitCastHit));
                    #else
                    FieldInfo cast_f = typeof(OrbitTargeter).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(f => f.FieldType == typeof(OrbitRenderer.OrbitCastHit));
                    #endif
                    fields = new FieldInfo[] { mode_f, context_f, cast_f };
                }
                if (FlightGlobals.ActiveVessel != null)
                {
                    OrbitTargeter targeter = FlightGlobals.ActiveVessel.orbitTargeter;
                    if (targeter == null)
                    {
                        return;
                    }
                    Int32 mode = (Int32)fields[0].GetValue(targeter);
                    if (mode == 2)
                    {
                        #if !KSP131
                        OrbitRendererBase.OrbitCastHit cast = (OrbitRendererBase.OrbitCastHit)fields[2].GetValue(targeter);
                        #else
                        OrbitRenderer.OrbitCastHit cast = (OrbitRenderer.OrbitCastHit)fields[2].GetValue(targeter);
                        #endif
                        CelestialBody body = PSystemManager.Instance.localBodies.Find(b => b.name == cast.or?.discoveryInfo?.name?.Value);
                        if (body == null)
                        {
                            return;
                        }
                        if (body.Has("barycenter") || !body.Get("selectable", true))
                        {
                            if (cast.driver?.Targetable == null)
                            {
                                return;
                            }
                            MapContextMenu context = MapContextMenu.Create(body.name, new Rect(0.5f, 0.5f, 300f, 50f), cast, () =>
                            {
                                fields[0].SetValue(targeter, 0);
                                fields[1].SetValue(targeter, null);
                            }, new SetAsTarget(cast.driver.Targetable, () => FlightGlobals.fetch.VesselTarget));
                            fields[1].SetValue(targeter, context);
                        }
                    }
                }
            }

            foreach (CelestialBody body in PSystemManager.Instance.localBodies)
            {
                if (body.afg == null)
                {
                    continue;
                }
                GameObject star_      = KopernicusStar.GetNearest(body).gameObject;
                Vector3    planet2cam = body.scaledBody.transform.position - body.afg.mainCamera.transform.position;
                body.afg.lightDot = Mathf.Clamp01(Vector3.Dot(planet2cam, body.afg.mainCamera.transform.position - star_.transform.position) * body.afg.dawnFactor);
                body.afg.GetComponent <Renderer>().sharedMaterial.SetFloat("_lightDot", body.afg.lightDot);
            }

            // Update the names of the presets in the settings dialog
            if (HighLogic.LoadedScene == GameScenes.SETTINGS)
            {
                foreach (SettingsTerrainDetail detail in Resources.FindObjectsOfTypeAll <SettingsTerrainDetail>())
                {
                    detail.displayStringValue = true;
                    detail.stringValues       = _details ?? (_details = Templates.PresetDisplayNames.ToArray());
                }
            }
        }
예제 #11
0
        // Awake() - flag this class as don't destroy on load and register delegates
        void Awake()
        {
            // Don't run if Kopernicus isn't compatible
            if (!CompatibilityChecker.IsCompatible())
            {
                Destroy(this);
                return;
            }

            // Make sure the runtime utility isn't killed
            DontDestroyOnLoad(this);

            // Add handlers
            GameEvents.onPartUnpack.Add(OnPartUnpack);
            GameEvents.onLevelWasLoaded.Add(FixCameras);
            GameEvents.onLevelWasLoaded.Add(delegate(GameScenes scene)
            {
                if (HighLogic.LoadedSceneHasPlanetarium && MapView.fetch != null)
                {
                    MapView.fetch.max3DlineDrawDist = 20000f;
                }
                if (scene == GameScenes.MAINMENU)
                {
                    UpdateMenu();
                }
                if (scene == GameScenes.SPACECENTER)
                {
                    PatchFI();
                }
                foreach (CelestialBody body in PSystemManager.Instance.localBodies)
                {
                    GameObject star_ = KopernicusStar.GetNearest(body).gameObject;
                    if (body.afg != null)
                    {
                        body.afg.sunLight = star_;
                    }
                    if (body.scaledBody.GetComponent <MaterialSetDirection>() != null)
                    {
                        body.scaledBody.GetComponent <MaterialSetDirection>().target = star_.transform;
                    }
                    foreach (PQSMod_MaterialSetDirection msd in body.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true))
                    {
                        msd.target = star_.transform;
                    }
                }
                foreach (TimeOfDayAnimation anim in Resources.FindObjectsOfTypeAll <TimeOfDayAnimation>())
                {
                    anim.target = KopernicusStar.GetNearest(FlightGlobals.GetHomeBody()).gameObject.transform;
                }
            });

            // Update Music Logic
            if (MusicLogic.fetch != null && FlightGlobals.fetch != null && FlightGlobals.GetHomeBody() != null)
            {
                MusicLogic.fetch.flightMusicSpaceAltitude = FlightGlobals.GetHomeBody().atmosphereDepth;
            }

            // Stars
            GameObject     gob  = Sun.Instance.gameObject;
            KopernicusStar star = gob.AddComponent <KopernicusStar>();

            Utility.CopyObjectFields(Sun.Instance, star, false);
            DestroyImmediate(Sun.Instance);
            Sun.Instance = star;

            // More stars
            foreach (CelestialBody body in PSystemManager.Instance.localBodies.Where(b => b.flightGlobalsIndex != 0 && b.scaledBody.GetComponentsInChildren <SunShaderController>(true).Length > 0))
            {
                GameObject     starObj = Instantiate(Sun.Instance.gameObject);
                KopernicusStar star_   = starObj.GetComponent <KopernicusStar>();
                star_.sun = body;
                starObj.transform.parent        = Sun.Instance.transform.parent;
                starObj.name                    = body.name;
                starObj.transform.localPosition = Vector3.zero;
                starObj.transform.localRotation = Quaternion.identity;
                starObj.transform.localScale    = Vector3.one;
                starObj.transform.position      = body.position;
                starObj.transform.rotation      = body.rotation;
            }

            // Log
            Logger.Default.Log("[Kopernicus]: RuntimeUtility Started");
            Logger.Default.Flush();
        }
 void GetTarget()
 {
     body   = PSystemManager.Instance.localBodies.Find(b => b.scaledBody.name == transform.parent.name);
     target = KopernicusStar.GetNearest(body).sun.scaledBody.transform;
 }