Пример #1
0
        public Overlay(string planet, float altitude, Material scaledMaterial, Material macroMaterial, Vector2 rotation, int layer, Transform celestialTransform, bool mainMenu, bool matchTerrain)
        {
            this.MainMenu          = mainMenu;
            this.OverlayGameObject = new GameObject();
            this.Body               = planet;
            this.Rotation           = rotation;
            this.scaledMaterial     = scaledMaterial;
            this.macroMaterial      = macroMaterial;
            this.OriginalLayer      = layer;
            this.celestialTransform = celestialTransform;
            this.altitude           = altitude;
            this.matchTerrain       = matchTerrain;

            CelestialBody[] celestialBodies = (CelestialBody[])CelestialBody.FindObjectsOfType(typeof(CelestialBody));
            celestialBody = celestialBodies.First(n => n.bodyName == this.Body);

            if (!mainMenu && matchTerrain)
            {
                IsoSphere.Create(OverlayGameObject, this.altitude, celestialBody);
            }
            else
            {
                IsoSphere.Create(OverlayGameObject, this.Radius, null);
            }

            var mr = OverlayGameObject.AddComponent <MeshRenderer>();

            mr.sharedMaterial = scaledMaterial;
            mr.castShadows    = false;
            mr.receiveShadows = false;
            //mr.enabled = mainMenu;
            mr.enabled = true;
        }
Пример #2
0
        public AtmosphereVolume(string body, Vector2 speed)
        {
            VolumeParent = new GameObject();
            CelestialBody[] celestialBodies = (CelestialBody[])CelestialBody.FindObjectsOfType(typeof(CelestialBody));
            CelestialBody   celestialBody   = celestialBodies.First(n => n.bodyName == body);

            BodyRadius = (float)celestialBody.Radius;
            VolumeParent.transform.parent        = celestialBody.transform;
            VolumeParent.transform.localPosition = Vector3.zero;
            VolumeParent.transform.localScale    = Vector3.one;
            Speed = speed;
            CloudParticleMaterial = new Material(CloudLayer.CloudParticleShader);
            Texture2D tex1 = GameDatabase.Instance.GetTexture("KerbalWeatherSystems/Textures/Clouds/particle/1", false);
            Texture2D tex2 = GameDatabase.Instance.GetTexture("KerbalWeatherSystems/Textures/Clouds/particle/2", false);
            Texture2D tex3 = GameDatabase.Instance.GetTexture("KerbalWeatherSystems/Textures/Clouds/particle/3", false);

            tex1.wrapMode = TextureWrapMode.Clamp;
            tex2.wrapMode = TextureWrapMode.Clamp;
            tex3.wrapMode = TextureWrapMode.Clamp;
            CloudParticleMaterial.SetTexture("_TopTex", tex1);
            CloudParticleMaterial.SetTexture("_LeftTex", tex2);
            CloudParticleMaterial.SetTexture("_FrontTex", tex3);
            CloudParticleMaterial.SetFloat("_DistFade", 1f / 2250f);
            Volume = new VolumeManager(BodyRadius, CloudParticleMaterial, VolumeParent.transform);
            Volumes.Add(this);
            if (!BodyDatabase.ContainsKey(body))
            {
                BodyDatabase.Add(body, new List <AtmosphereVolume>());
            }
            BodyDatabase[body].Add(this);
        }
        protected void Awake()
        {
            if (!setup)
            {
                UnityEngine.Object[] celestialBodies = CelestialBody.FindObjectsOfType(typeof(CelestialBody));
                foreach (CelestialBody cb in celestialBodies)
                {
                    CelestialBodyList.Add(cb);
                    if (cb.name == "Kerbin")
                    {
                        PQS pqs = cb.pqsController;
                        if (cb == GameObject.Find("localSpace").transform.FindChild("Kerbin"))
                        {
                            Log("CB and localspace are equal!");
                        }
                        Assembly     assembly           = Assembly.GetExecutingAssembly();
                        StreamReader shaderStreamReader = new StreamReader(assembly.GetManifestResourceStream("Terrain.Shaders.Compiled-Vertex.shader"));
                        //StreamReader shaderStreamReader = new StreamReader(assembly.GetManifestResourceStream("Terrain.Shaders.Compiled-Normals.shader"));
                        //StreamReader shaderStreamReader = new StreamReader(assembly.GetManifestResourceStream("Terrain.Shaders.Compiled-Tangents.shader"));
                        //StreamReader shaderStreamReader = new StreamReader(assembly.GetManifestResourceStream("Terrain.Shaders.Compiled-uv1.shader"));
                        //StreamReader shaderStreamReader = new StreamReader(assembly.GetManifestResourceStream("Terrain.Shaders.Compiled-uv2.shader"));
                        //StreamReader shaderStreamReader = new StreamReader(assembly.GetManifestResourceStream("Terrain.Shaders.Compiled-Terrain.shader"));

                        Log("reading stream...");
                        String shaderTxt = shaderStreamReader.ReadToEnd();
                        pqs.surfaceMaterial.shader = Shader.Find("VertexLit");

                        pqs.ChildSpheres[0].surfaceMaterial.shader = new Material(shaderTxt).shader;
                    }
                }
                setup = true;
            }
        }
Пример #4
0
        void Awake()
        {
            string     codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri      = new UriBuilder(codeBase);

            path = Uri.UnescapeDataString(uri.Path);
            path = Path.GetDirectoryName(path);

            int index = path.LastIndexOf("GameData");

            gameDataPath = path.Remove(index + 9, path.Length - index - 9);

            //load the planets list and the settings
            loadSettings();

            //find all celestial bodies, used for finding scatterer-enabled bodies and disabling the stock ocean
            CelestialBodies = (CelestialBody[])CelestialBody.FindObjectsOfType(typeof(CelestialBody));

            if (SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 9"))
            {
                d3d9 = true;
            }
            else if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL"))
            {
                opengl = true;
            }
            else if (SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 11"))
            {
                d3d11 = true;
            }

            Debug.Log("[Scatterer] Version:" + versionNumber);
            Debug.Log("[Scatterer] Detected " + SystemInfo.graphicsDeviceVersion + " on " + SystemInfo.operatingSystem);

            if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                isActive     = true;
                windowRect.x = inGameWindowLocation.x;
                windowRect.y = inGameWindowLocation.y;
            }

            else if (HighLogic.LoadedScene == GameScenes.MAINMENU)
            {
                mainMenu     = true;
                visible      = showMenuOnStart;
                windowRect.x = mainMenuWindowLocation.x;
                windowRect.y = mainMenuWindowLocation.y;

                //find and remove stock oceans
                if (useOceanShaders)
                {
                    removeStockOceans();
                }
            }
        }
Пример #5
0
 public static void Init()
 {
     if (!setup)
     {
         UnityEngine.Object[] celestialBodies = CelestialBody.FindObjectsOfType(typeof(CelestialBody));
         foreach (CelestialBody cb in celestialBodies)
         {
             CelestialBodyList.Add(cb);
             if (cb.name == "Kerbin")
             {
                 CurrentPQS = cb.pqsController;
             }
         }
         setup = true;
     }
 }
        private void DrawMainWindow(int windowID)
        {
            CelestialBody[] celestialBodies = CelestialBody.FindObjectsOfType(typeof(CelestialBody)) as CelestialBody[];
            KWSManagerClass currentManager;
            Rect            placement     = new Rect(0, 0, 0, 1);
            float           width         = _mainWindowRect.width - 10;
            float           height        = _mainWindowRect.height - 10;
            Rect            placementBase = new Rect(10, 25, width, height);

            currentManager = GUIHelper.DrawSelector <KWSManagerClass>(Managers, ref selectedManagerIndex, 4, placementBase, ref placement);

            if (currentManager != null)
            {
                currentManager.DrawGUI(placementBase, placement);
            }

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
        void findCelestialBodies()
        {
            CelestialBodies = (CelestialBody[])CelestialBody.FindObjectsOfType(typeof(CelestialBody));

            foreach (ScattererCelestialBody sctBody in Scatterer.Instance.planetsConfigsReader.scattererCelestialBodies)
            {
                var _idx = 0;

                Utils.LogDebug("Finding ScattererCelestialBody name: " + sctBody.celestialBodyName + ". TransformName: " + sctBody.transformName);

                var celBody = CelestialBodies.SingleOrDefault(_cb => _cb.bodyName == sctBody.celestialBodyName);

                if (celBody == null)
                {
                    Utils.LogDebug("ScattererCelestialBody not found by name, trying transformName");
                    celBody = CelestialBodies.SingleOrDefault(_cb => _cb.bodyName == sctBody.transformName);
                }

                if (celBody == null)
                {
                    Utils.LogError("ScattererCelestialBody " + sctBody.celestialBodyName + " not found by name, or transformName. Effects for this body won't be available.");
                    continue;
                }
                else
                {
                    _idx = Scatterer.Instance.planetsConfigsReader.scattererCelestialBodies.IndexOf(sctBody);
                    Utils.LogDebug("Found ScattererCelestialBody: " + sctBody.celestialBodyName + ", actual ingame name: " + celBody.GetName());
                }

                sctBody.celestialBody = celBody;

                var sctBodyTransform = ScaledSpace.Instance.transform.FindChild(sctBody.transformName);
                if (!sctBodyTransform)
                {
                    sctBodyTransform = ScaledSpace.Instance.transform.FindChild(sctBody.celestialBodyName);
                }
                else
                {
                    sctBody.transform    = sctBodyTransform;
                    sctBody.hasTransform = true;
                }
                sctBody.active = false;
            }
        }
        void findCelestialBodies()
        {
            CelestialBodies = (CelestialBody[])CelestialBody.FindObjectsOfType(typeof(CelestialBody));

            foreach (ScattererCelestialBody sctBody in Scatterer.Instance.planetsConfigsReader.scattererCelestialBodies)
            {
                var _idx = 0;

                var celBody = CelestialBodies.SingleOrDefault(_cb => _cb.bodyName == sctBody.celestialBodyName);

                if (celBody == null)
                {
                    celBody = CelestialBodies.SingleOrDefault(_cb => _cb.bodyName == sctBody.transformName);
                }

                Utils.LogDebug("Celestial Body: " + celBody);
                if (celBody != null)
                {
                    _idx = Scatterer.Instance.planetsConfigsReader.scattererCelestialBodies.IndexOf(sctBody);
                    Utils.LogDebug("Found: " + sctBody.celestialBodyName + " / " + celBody.GetName());
                }
                ;

                sctBody.celestialBody = celBody;

                var sctBodyTransform = ScaledSpace.Instance.transform.FindChild(sctBody.transformName);
                if (!sctBodyTransform)
                {
                    sctBodyTransform = ScaledSpace.Instance.transform.FindChild(sctBody.celestialBodyName);
                }
                else
                {
                    sctBody.transform    = sctBodyTransform;
                    sctBody.hasTransform = true;
                }
                sctBody.active = false;
            }
        }
 public static CelestialBody GetCelestialBody(String body)
 {
     CelestialBody[] celestialBodies = CelestialBody.FindObjectsOfType(typeof(CelestialBody)) as CelestialBody[];
     return(celestialBodies.Single(n => n.bodyName == body));
 }
Пример #10
0
        public static void Init()
        {
            if (!setup)
            {
                UnityEngine.Object[] celestialBodies = CelestialBody.FindObjectsOfType(typeof(CelestialBody));
                config = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/BoulderCo/common.cfg");
                ConfigNode cameraSwapConfig = config.GetNode("CAMERA_SWAP_DISTANCES");

                foreach (CelestialBody cb in celestialBodies)
                {
                    CelestialBodyList.Add(cb);
                    string name = cb.bodyName;
                    string val  = cameraSwapConfig.GetValue(name);
                    float  dist = 0;
                    if (val != null && val != "")
                    {
                        dist = float.Parse(val);
                    }
                    Log("loading " + name + " distance " + dist);
                    MAP_SWITCH_DISTANCE.Add(name, dist);
                }

                ConfigNode cameraLayers = config.GetNode("CAMERA_LAYERS");
                if (cameraLayers != null)
                {
                    string value = cameraLayers.GetValue("IGNORE_LAYER");
                    if (value != null && value != "")
                    {
                        IGNORE_LAYER = int.Parse(value);
                    }
                    value = cameraLayers.GetValue("OVER_LAYER");
                    if (value != null && value != "")
                    {
                        OVER_LAYER = int.Parse(value);
                    }
                    value = cameraLayers.GetValue("UNDER_LAYER");
                    if (value != null && value != "")
                    {
                        UNDER_LAYER = int.Parse(value);
                    }
                    value = cameraLayers.GetValue("MAP_LAYER");
                    if (value != null && value != "")
                    {
                        MAP_LAYER = int.Parse(value);
                    }
                }
                Log("Camera Layers Parsed.");

                Camera referenceCam = ScaledCamera.Instance.camera;


                GameObject Ogo = new GameObject();
                overlayCamera = Ogo.AddComponent <Camera>();
                overlayCamera.transform.parent        = referenceCam.transform;
                overlayCamera.transform.localPosition = new Vector3(0, 0, 0);
                overlayCamera.transform.localRotation = Quaternion.FromToRotation(new Vector3(0, 0, 0), new Vector3(0, 0, 1));
                overlayCamera.depth              = referenceCam.depth + 2.5f;
                overlayCamera.fieldOfView        = referenceCam.fieldOfView;
                overlayCamera.farClipPlane       = referenceCam.farClipPlane;
                overlayCamera.cullingMask        = (1 << OVER_LAYER); //-10,-9,-18,-23,-29
                overlayCamera.eventMask          = 0;
                overlayCamera.nearClipPlane      = .05f;
                overlayCamera.layerCullDistances = new float[32];
                overlayCamera.layerCullSpherical = true;
                overlayCamera.clearFlags         = CameraClearFlags.Depth;

                Log("Initialized Overlay Camera.");

                //for underside of clouds, etc.
                GameObject Ugo = new GameObject();
                underlayCamera = Ugo.AddComponent <Camera>();
                underlayCamera.transform.parent        = referenceCam.transform;
                underlayCamera.transform.localPosition = new Vector3(0, 0, 0);
                underlayCamera.transform.localRotation = Quaternion.FromToRotation(new Vector3(0, 0, 0), new Vector3(0, 0, 1));
                underlayCamera.depth              = referenceCam.depth + .1f;
                underlayCamera.fieldOfView        = referenceCam.fieldOfView;
                underlayCamera.farClipPlane       = referenceCam.farClipPlane;
                underlayCamera.cullingMask        = (1 << UNDER_LAYER); //-10,-9,-18,-23,-29
                underlayCamera.eventMask          = 0;
                underlayCamera.nearClipPlane      = .05f;
                underlayCamera.layerCullDistances = new float[32];
                underlayCamera.layerCullSpherical = true;
                underlayCamera.clearFlags         = CameraClearFlags.Depth;
                Log("Initialized Underlay Camera.");

                Sun.Instance.light.cullingMask |= (1 << OVER_LAYER) | (1 << UNDER_LAYER);
                Log("Initialized Light mask.");

                setup = true;
            }
        }