protected void Start() { if (Application.isPlaying) { Vector2 atlas = Resources.BillboardMaterial.mainTextureScale; int atlas_x = Mathf.RoundToInt(1f / atlas.x); int atlas_y = Mathf.RoundToInt(1f / atlas.y); // Create mesh prototypes var meshes = new Mesh[2 * atlas_x * atlas_y]; { for (int y = 0; y < atlas_y; y++) { for (int x = 0; x < atlas_x; x++) { meshes[y * atlas_x + x] = TOD_Resources.CreateQuad(new Vector2(x, y), new Vector2(x + 1, y + 1)); } } for (int y = 0; y < atlas_y; y++) { for (int x = 0; x < atlas_x; x++) { meshes[atlas_x * atlas_y + y * atlas_x + x] = TOD_Resources.CreateQuad(new Vector2(x + 1, y), new Vector2(x, y + 1)); } } } // Spawn billboard instances for (int i = 0; i < Clouds.Billboards; i++) { var go = new GameObject("Cloud " + i); go.transform.parent = Components.Billboards.transform; var scale = Random.Range(0.3f, 0.4f); go.transform.localScale = new Vector3(scale, scale * 0.5f, 1.0f); var angle = 2.0f * Mathf.PI * ((float)i / Clouds.Billboards); go.transform.localPosition = 0.95f * new Vector3(Mathf.Sin(angle), Random.Range(0.1f, 0.2f), Mathf.Cos(angle)).normalized; go.transform.LookAt(Components.DomeTransform.position); var cloudFilter = go.AddComponent <MeshFilter>(); cloudFilter.sharedMesh = meshes[Random.Range(0, meshes.Length)]; var cloudRenderer = go.AddComponent <MeshRenderer>(); cloudRenderer.sharedMaterial = Resources.BillboardMaterial; } } }
protected void OnEnable() { this.DomeTransform = base.transform; if (Camera.main == null) { Debug.LogWarning("Main camera does not exist or is not tagged 'MainCamera'."); } else { this.CameraTransform = Camera.main.transform; } this.Sky = base.GetComponent <TOD_Sky>(); this.Animation = base.GetComponent <TOD_Animation>(); this.Time = base.GetComponent <TOD_Time>(); this.Weather = base.GetComponent <TOD_Weather>(); this.Resources = base.GetComponent <TOD_Resources>(); if (!this.Space) { Debug.LogError("Space reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.SpaceRenderer = this.Space.renderer; this.SpaceShader = this.SpaceRenderer.sharedMaterial; this.SpaceMeshFilter = this.Space.GetComponent <MeshFilter>(); if (!this.Atmosphere) { Debug.LogError("Atmosphere reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.AtmosphereRenderer = this.Atmosphere.renderer; this.AtmosphereShader = this.AtmosphereRenderer.sharedMaterial; this.AtmosphereMeshFilter = this.Atmosphere.GetComponent <MeshFilter>(); if (!this.Clear) { Debug.LogError("Clear reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.ClearRenderer = this.Clear.renderer; this.ClearShader = this.ClearRenderer.sharedMaterial; this.ClearMeshFilter = this.Clear.GetComponent <MeshFilter>(); if (!this.Clouds) { Debug.LogError("Clouds reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.CloudRenderer = this.Clouds.renderer; this.CloudShader = this.CloudRenderer.sharedMaterial; this.CloudMeshFilter = this.Clouds.GetComponent <MeshFilter>(); if (!this.Projector) { Debug.LogError("Projector reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.ShadowProjector = this.Projector.GetComponent <UnityEngine.Projector>(); this.ShadowShader = this.ShadowProjector.material; if (!this.Light) { Debug.LogError("Light reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.LightTransform = this.Light.transform; this.LightSource = this.Light.light; if (!this.Sun) { Debug.LogError("Sun reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.SunTransform = this.Sun.transform; this.SunRenderer = this.Sun.renderer; this.SunShader = this.SunRenderer.sharedMaterial; this.SunMeshFilter = this.Sun.GetComponent <MeshFilter>(); if (!this.Moon) { Debug.LogError("Moon reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.MoonTransform = this.Moon.transform; this.MoonRenderer = this.Moon.renderer; this.MoonShader = this.MoonRenderer.sharedMaterial; this.MoonMeshFilter = this.Moon.GetComponent <MeshFilter>(); }
private void SetupQualitySettings() { Material spaceMaterial; TOD_Resources resources = this.Components.Resources; Material cloudMaterialFastest = null; Material shadowMaterialFastest = null; switch (this.CloudQuality) { case TOD_Sky.CloudQualityType.Fastest: { cloudMaterialFastest = resources.CloudMaterialFastest; shadowMaterialFastest = resources.ShadowMaterialFastest; break; } case TOD_Sky.CloudQualityType.Density: { cloudMaterialFastest = resources.CloudMaterialDensity; shadowMaterialFastest = resources.ShadowMaterialDensity; break; } case TOD_Sky.CloudQualityType.Bumped: { cloudMaterialFastest = resources.CloudMaterialBumped; shadowMaterialFastest = resources.ShadowMaterialBumped; break; } default: { Debug.LogError("Unknown cloud quality."); break; } } Mesh icosphereLow = null; Mesh icosphereMedium = null; Mesh mesh = null; Mesh halfIcosphereLow = null; Mesh quad = null; Mesh sphereLow = null; switch (this.MeshQuality) { case TOD_Sky.MeshQualityType.Low: { icosphereLow = resources.IcosphereLow; icosphereMedium = resources.IcosphereLow; mesh = resources.IcosphereLow; halfIcosphereLow = resources.HalfIcosphereLow; quad = resources.Quad; sphereLow = resources.SphereLow; break; } case TOD_Sky.MeshQualityType.Medium: { icosphereLow = resources.IcosphereMedium; icosphereMedium = resources.IcosphereMedium; mesh = resources.IcosphereLow; halfIcosphereLow = resources.HalfIcosphereMedium; quad = resources.Quad; sphereLow = resources.SphereMedium; break; } case TOD_Sky.MeshQualityType.High: { icosphereLow = resources.IcosphereHigh; icosphereMedium = resources.IcosphereHigh; mesh = resources.IcosphereLow; halfIcosphereLow = resources.HalfIcosphereHigh; quad = resources.Quad; sphereLow = resources.SphereHigh; break; } default: { Debug.LogError("Unknown mesh quality."); break; } } if (!this.Components.SpaceShader || this.Components.SpaceShader.name != resources.SpaceMaterial.name) { TOD_Components components = this.Components; spaceMaterial = resources.SpaceMaterial; this.Components.SpaceRenderer.sharedMaterial = spaceMaterial; components.SpaceShader = spaceMaterial; } if (!this.Components.AtmosphereShader || this.Components.AtmosphereShader.name != resources.AtmosphereMaterial.name) { TOD_Components tODComponent = this.Components; spaceMaterial = resources.AtmosphereMaterial; this.Components.AtmosphereRenderer.sharedMaterial = spaceMaterial; tODComponent.AtmosphereShader = spaceMaterial; } if (!this.Components.ClearShader || this.Components.ClearShader.name != resources.ClearMaterial.name) { TOD_Components components1 = this.Components; spaceMaterial = resources.ClearMaterial; this.Components.ClearRenderer.sharedMaterial = spaceMaterial; components1.ClearShader = spaceMaterial; } if (!this.Components.CloudShader || this.Components.CloudShader.name != cloudMaterialFastest.name) { TOD_Components tODComponent1 = this.Components; spaceMaterial = cloudMaterialFastest; this.Components.CloudRenderer.sharedMaterial = spaceMaterial; tODComponent1.CloudShader = spaceMaterial; } if (!this.Components.ShadowShader || this.Components.ShadowShader.name != shadowMaterialFastest.name) { TOD_Components components2 = this.Components; spaceMaterial = shadowMaterialFastest; this.Components.ShadowProjector.material = spaceMaterial; components2.ShadowShader = spaceMaterial; } if (!this.Components.SunShader || this.Components.SunShader.name != resources.SunMaterial.name) { TOD_Components tODComponent2 = this.Components; spaceMaterial = resources.SunMaterial; this.Components.SunRenderer.sharedMaterial = spaceMaterial; tODComponent2.SunShader = spaceMaterial; } if (!this.Components.MoonShader || this.Components.MoonShader.name != resources.MoonMaterial.name) { TOD_Components components3 = this.Components; spaceMaterial = resources.MoonMaterial; this.Components.MoonRenderer.sharedMaterial = spaceMaterial; components3.MoonShader = spaceMaterial; } if (this.Components.SpaceMeshFilter.sharedMesh != icosphereLow) { this.Components.SpaceMeshFilter.mesh = icosphereLow; } if (this.Components.AtmosphereMeshFilter.sharedMesh != icosphereMedium) { this.Components.AtmosphereMeshFilter.mesh = icosphereMedium; } if (this.Components.ClearMeshFilter.sharedMesh != mesh) { this.Components.ClearMeshFilter.mesh = mesh; } if (this.Components.CloudMeshFilter.sharedMesh != halfIcosphereLow) { this.Components.CloudMeshFilter.mesh = halfIcosphereLow; } if (this.Components.SunMeshFilter.sharedMesh != quad) { this.Components.SunMeshFilter.mesh = quad; } if (this.Components.MoonMeshFilter.sharedMesh != sphereLow) { this.Components.MoonMeshFilter.mesh = sphereLow; } }
protected void OnEnable() { DomeTransform = transform; CameraTransform = Camera.main != null ? Camera.main.transform : DomeTransform; Sky = GetComponent <TOD_Sky>(); Animation = GetComponent <TOD_Animation>(); Time = GetComponent <TOD_Time>(); Weather = GetComponent <TOD_Weather>(); Resources = GetComponent <TOD_Resources>(); if (Space) { SpaceRenderer = Space.renderer; SpaceShader = SpaceRenderer.sharedMaterial; SpaceMeshFilter = Space.GetComponent <MeshFilter>(); } else { Debug.LogError("Space reference not set. Disabling script."); this.enabled = false; return; } if (Atmosphere) { AtmosphereRenderer = Atmosphere.renderer; AtmosphereShader = AtmosphereRenderer.sharedMaterial; AtmosphereMeshFilter = Atmosphere.GetComponent <MeshFilter>(); } else { Debug.LogError("Atmosphere reference not set. Disabling script."); this.enabled = false; return; } if (Clouds) { CloudRenderer = Clouds.renderer; CloudShader = CloudRenderer.sharedMaterial; CloudMeshFilter = Clouds.GetComponent <MeshFilter>(); } else { Debug.LogError("Clouds reference not set. Disabling script."); this.enabled = false; return; } if (Projector) { ShadowProjector = Projector.GetComponent <Projector>(); ShadowShader = ShadowProjector.material; } else { Debug.LogError("Projector reference not set. Disabling script."); this.enabled = false; return; } if (Light) { LightTransform = Light.transform; LightSource = Light.light; } else { Debug.LogError("Light reference not set. Disabling script."); this.enabled = false; return; } if (Sun) { SunTransform = Sun.transform; SunRenderer = Sun.renderer; SunShader = SunRenderer.sharedMaterial; SunMeshFilter = Sun.GetComponent <MeshFilter>(); } else { Debug.LogError("Sun reference not set. Disabling script."); this.enabled = false; return; } if (Moon) { MoonTransform = Moon.transform; MoonRenderer = Moon.renderer; MoonShader = MoonRenderer.sharedMaterial; MoonMeshFilter = Moon.GetComponent <MeshFilter>(); } else { Debug.LogError("Moon reference not set. Disabling script."); this.enabled = false; return; } }
/// Initializes all component references public void Initialize() { DomeTransform = GetComponent <Transform>(); Sky = GetComponent <TOD_Sky>(); Animation = GetComponent <TOD_Animation>(); Time = GetComponent <TOD_Time>(); Weather = GetComponent <TOD_Weather>(); Resources = GetComponent <TOD_Resources>(); if (Space) { SpaceTransform = Space.GetComponent <Transform>(); SpaceRenderer = Space.GetComponent <Renderer>(); SpaceMaterial = SpaceRenderer.sharedMaterial; SpaceMeshFilter = Space.GetComponent <MeshFilter>(); } else { Debug.LogError("Space reference not set."); } if (Atmosphere) { AtmosphereRenderer = Atmosphere.GetComponent <Renderer>(); AtmosphereMaterial = AtmosphereRenderer.sharedMaterial; AtmosphereMeshFilter = Atmosphere.GetComponent <MeshFilter>(); } else { Debug.LogError("Atmosphere reference not set."); } if (Clear) { ClearRenderer = Clear.GetComponent <Renderer>(); ClearMaterial = ClearRenderer.sharedMaterial; ClearMeshFilter = Clear.GetComponent <MeshFilter>(); } else { Debug.LogError("Clear reference not set."); } if (Clouds) { CloudRenderer = Clouds.GetComponent <Renderer>(); CloudMaterial = CloudRenderer.sharedMaterial; CloudMeshFilter = Clouds.GetComponent <MeshFilter>(); } else { Debug.LogError("Clouds reference not set."); } if (Projector) { ShadowProjector = Projector.GetComponent <Projector>(); ShadowMaterial = ShadowProjector.material; } else { Debug.LogError("Projector reference not set."); } if (Light) { LightTransform = Light.GetComponent <Transform>(); LightSource = Light.GetComponent <Light>(); } else { Debug.LogError("Light reference not set."); } if (Sun) { SunTransform = Sun.GetComponent <Transform>(); SunRenderer = Sun.GetComponent <Renderer>(); SunMaterial = SunRenderer.sharedMaterial; SunMeshFilter = Sun.GetComponent <MeshFilter>(); } else { Debug.LogError("Sun reference not set."); } if (Moon) { MoonTransform = Moon.GetComponent <Transform>(); MoonRenderer = Moon.GetComponent <Renderer>(); MoonMaterial = MoonRenderer.sharedMaterial; MoonMeshFilter = Moon.GetComponent <MeshFilter>(); } else { Debug.LogError("Moon reference not set."); } }
/// Adjust shaders and meshes according to the quality settings. private void SetupQualitySettings() { if (Headless) { return; } TOD_Resources resources = Components.Resources; Material cloudMaterial = null; Material shadowMaterial = null; switch (CloudQuality) { case TOD_CloudQualityType.Fastest: cloudMaterial = resources.CloudMaterialFastest; shadowMaterial = resources.ShadowMaterialFastest; break; case TOD_CloudQualityType.Density: cloudMaterial = resources.CloudMaterialDensity; shadowMaterial = resources.ShadowMaterialDensity; break; case TOD_CloudQualityType.Bumped: cloudMaterial = resources.CloudMaterialBumped; shadowMaterial = resources.ShadowMaterialBumped; break; } Mesh spaceMesh = null; Mesh atmosphereMesh = null; Mesh clearMesh = null; Mesh cloudMesh = null; Mesh sunMesh = null; Mesh moonMesh = null; switch (MeshQuality) { case TOD_MeshQualityType.Low: spaceMesh = resources.IcosphereLow; atmosphereMesh = resources.IcosphereLow; clearMesh = resources.IcosphereLow; cloudMesh = resources.HalfIcosphereLow; sunMesh = resources.Quad; moonMesh = resources.SphereLow; break; case TOD_MeshQualityType.Medium: spaceMesh = resources.IcosphereMedium; atmosphereMesh = resources.IcosphereMedium; clearMesh = resources.IcosphereLow; cloudMesh = resources.HalfIcosphereMedium; sunMesh = resources.Quad; moonMesh = resources.SphereMedium; break; case TOD_MeshQualityType.High: spaceMesh = resources.IcosphereHigh; atmosphereMesh = resources.IcosphereHigh; clearMesh = resources.IcosphereLow; cloudMesh = resources.HalfIcosphereHigh; sunMesh = resources.Quad; moonMesh = resources.SphereHigh; break; } if (Components.SpaceRenderer && Components.SpaceShader != resources.SpaceMaterial) { Components.SpaceShader = Components.SpaceRenderer.sharedMaterial = resources.SpaceMaterial; } if (Components.AtmosphereRenderer && Components.AtmosphereShader != resources.AtmosphereMaterial) { Components.AtmosphereShader = Components.AtmosphereRenderer.sharedMaterial = resources.AtmosphereMaterial; } if (Components.ClearRenderer && Components.ClearShader != resources.ClearMaterial) { Components.ClearShader = Components.ClearRenderer.sharedMaterial = resources.ClearMaterial; } if (Components.CloudRenderer && Components.CloudShader != cloudMaterial) { Components.CloudShader = Components.CloudRenderer.sharedMaterial = cloudMaterial; } if (Components.ShadowProjector && Components.ShadowShader != shadowMaterial) { Components.ShadowShader = Components.ShadowProjector.material = shadowMaterial; } if (Components.SunRenderer && Components.SunShader != resources.SunMaterial) { Components.SunShader = Components.SunRenderer.sharedMaterial = resources.SunMaterial; } if (Components.MoonRenderer && Components.MoonShader != resources.MoonMaterial) { Components.MoonShader = Components.MoonRenderer.sharedMaterial = resources.MoonMaterial; } if (Components.SpaceMeshFilter && Components.SpaceMeshFilter.sharedMesh != spaceMesh) { Components.SpaceMeshFilter.mesh = spaceMesh; } if (Components.AtmosphereMeshFilter && Components.AtmosphereMeshFilter.sharedMesh != atmosphereMesh) { Components.AtmosphereMeshFilter.mesh = atmosphereMesh; } if (Components.ClearMeshFilter && Components.ClearMeshFilter.sharedMesh != clearMesh) { Components.ClearMeshFilter.mesh = clearMesh; } if (Components.CloudMeshFilter && Components.CloudMeshFilter.sharedMesh != cloudMesh) { Components.CloudMeshFilter.mesh = cloudMesh; } if (Components.SunMeshFilter && Components.SunMeshFilter.sharedMesh != sunMesh) { Components.SunMeshFilter.mesh = sunMesh; } if (Components.MoonMeshFilter && Components.MoonMeshFilter.sharedMesh != moonMesh) { Components.MoonMeshFilter.mesh = moonMesh; } }
/// Adjust shaders and meshes according to the quality settings. private void SetupQualitySettings() { TOD_Resources resources = Components.Resources; Material cloudMaterial = null; Material shadowMaterial = null; switch (CloudQuality) { case TOD_Sky.CloudQualityType.Fastest: cloudMaterial = resources.CloudMaterialFastest; shadowMaterial = resources.ShadowMaterialFastest; break; case TOD_Sky.CloudQualityType.Density: cloudMaterial = resources.CloudMaterialDensity; shadowMaterial = resources.ShadowMaterialDensity; break; case TOD_Sky.CloudQualityType.Bumped: cloudMaterial = resources.CloudMaterialBumped; shadowMaterial = resources.ShadowMaterialBumped; break; default: Debug.LogError("Unknown cloud quality."); break; } Mesh spaceMesh = null; Mesh atmosphereMesh = null; Mesh cloudMesh = null; Mesh sunMesh = null; Mesh moonMesh = null; switch (MeshQuality) { case TOD_Sky.MeshQualityType.Low: spaceMesh = resources.IcosphereLow; atmosphereMesh = resources.IcosphereLow; cloudMesh = resources.HalfIcosphereLow; sunMesh = resources.Quad; moonMesh = resources.SphereLow; break; case TOD_Sky.MeshQualityType.Medium: spaceMesh = resources.IcosphereMedium; atmosphereMesh = resources.IcosphereMedium; cloudMesh = resources.HalfIcosphereMedium; sunMesh = resources.Quad; moonMesh = resources.SphereMedium; break; case TOD_Sky.MeshQualityType.High: spaceMesh = resources.IcosphereHigh; atmosphereMesh = resources.IcosphereHigh; cloudMesh = resources.HalfIcosphereHigh; sunMesh = resources.Quad; moonMesh = resources.SphereHigh; break; default: Debug.LogError("Unknown mesh quality."); break; } if (!Components.SpaceShader || Components.SpaceShader.name != resources.SpaceMaterial.name) { Components.SpaceShader = Components.SpaceRenderer.sharedMaterial = resources.SpaceMaterial; } if (!Components.AtmosphereShader || Components.AtmosphereShader.name != resources.AtmosphereMaterial.name) { Components.AtmosphereShader = Components.AtmosphereRenderer.sharedMaterial = resources.AtmosphereMaterial; } if (!Components.CloudShader || Components.CloudShader.name != cloudMaterial.name) { Components.CloudShader = Components.CloudRenderer.sharedMaterial = cloudMaterial; } if (!Components.ShadowShader || Components.ShadowShader.name != shadowMaterial.name) { Components.ShadowShader = Components.ShadowProjector.material = shadowMaterial; } if (!Components.SunShader || Components.SunShader.name != resources.SunMaterial.name) { Components.SunShader = Components.SunRenderer.sharedMaterial = resources.SunMaterial; } if (!Components.MoonShader || Components.MoonShader.name != resources.MoonMaterial.name) { Components.MoonShader = Components.MoonRenderer.sharedMaterial = resources.MoonMaterial; } if (Components.SpaceMeshFilter.sharedMesh != spaceMesh) { Components.SpaceMeshFilter.mesh = spaceMesh; } if (Components.AtmosphereMeshFilter.sharedMesh != atmosphereMesh) { Components.AtmosphereMeshFilter.mesh = atmosphereMesh; } if (Components.CloudMeshFilter.sharedMesh != cloudMesh) { Components.CloudMeshFilter.mesh = cloudMesh; } if (Components.SunMeshFilter.sharedMesh != sunMesh) { Components.SunMeshFilter.mesh = sunMesh; } if (Components.MoonMeshFilter.sharedMesh != moonMesh) { Components.MoonMeshFilter.mesh = moonMesh; } }
protected void OnEnable() { DomeTransform = transform; CameraTransform = Camera.main != null ? Camera.main.transform : DomeTransform; Sky = GetComponent<TOD_Sky>(); Animation = GetComponent<TOD_Animation>(); Time = GetComponent<TOD_Time>(); Weather = GetComponent<TOD_Weather>(); Resources = GetComponent<TOD_Resources>(); if (Space) { SpaceRenderer = Space.renderer; SpaceShader = SpaceRenderer.sharedMaterial; SpaceMeshFilter = Space.GetComponent<MeshFilter>(); } else { Debug.LogError("Space reference not set. Disabling script."); this.enabled = false; return; } if (Atmosphere) { AtmosphereRenderer = Atmosphere.renderer; AtmosphereShader = AtmosphereRenderer.sharedMaterial; AtmosphereMeshFilter = Atmosphere.GetComponent<MeshFilter>(); } else { Debug.LogError("Atmosphere reference not set. Disabling script."); this.enabled = false; return; } if (Clouds) { CloudRenderer = Clouds.renderer; CloudShader = CloudRenderer.sharedMaterial; CloudMeshFilter = Clouds.GetComponent<MeshFilter>(); } else { Debug.LogError("Clouds reference not set. Disabling script."); this.enabled = false; return; } if (Projector) { ShadowProjector = Projector.GetComponent<Projector>(); ShadowShader = ShadowProjector.material; } else { Debug.LogError("Projector reference not set. Disabling script."); this.enabled = false; return; } if (Light) { LightTransform = Light.transform; LightSource = Light.light; } else { Debug.LogError("Light reference not set. Disabling script."); this.enabled = false; return; } if (Sun) { SunTransform = Sun.transform; SunRenderer = Sun.renderer; SunShader = SunRenderer.sharedMaterial; SunMeshFilter = Sun.GetComponent<MeshFilter>(); } else { Debug.LogError("Sun reference not set. Disabling script."); this.enabled = false; return; } if (Moon) { MoonTransform = Moon.transform; MoonRenderer = Moon.renderer; MoonShader = MoonRenderer.sharedMaterial; MoonMeshFilter = Moon.GetComponent<MeshFilter>(); } else { Debug.LogError("Moon reference not set. Disabling script."); this.enabled = false; return; } }
private void SetupQualitySettings() { Material spaceMaterial; TOD_Resources resources = this.Components.Resources; Material cloudMaterialFastest = null; Material shadowMaterialFastest = null; switch (this.CloudQuality) { case CloudQualityType.Fastest: cloudMaterialFastest = resources.CloudMaterialFastest; shadowMaterialFastest = resources.ShadowMaterialFastest; break; case CloudQualityType.Density: cloudMaterialFastest = resources.CloudMaterialDensity; shadowMaterialFastest = resources.ShadowMaterialDensity; break; case CloudQualityType.Bumped: cloudMaterialFastest = resources.CloudMaterialBumped; shadowMaterialFastest = resources.ShadowMaterialBumped; break; default: Debug.LogError("Unknown cloud quality."); break; } Mesh icosphereLow = null; Mesh icosphereMedium = null; Mesh mesh3 = null; Mesh halfIcosphereLow = null; Mesh quad = null; Mesh sphereLow = null; switch (this.MeshQuality) { case MeshQualityType.Low: icosphereLow = resources.IcosphereLow; icosphereMedium = resources.IcosphereLow; mesh3 = resources.IcosphereLow; halfIcosphereLow = resources.HalfIcosphereLow; quad = resources.Quad; sphereLow = resources.SphereLow; break; case MeshQualityType.Medium: icosphereLow = resources.IcosphereMedium; icosphereMedium = resources.IcosphereMedium; mesh3 = resources.IcosphereLow; halfIcosphereLow = resources.HalfIcosphereMedium; quad = resources.Quad; sphereLow = resources.SphereMedium; break; case MeshQualityType.High: icosphereLow = resources.IcosphereHigh; icosphereMedium = resources.IcosphereHigh; mesh3 = resources.IcosphereLow; halfIcosphereLow = resources.HalfIcosphereHigh; quad = resources.Quad; sphereLow = resources.SphereHigh; break; default: Debug.LogError("Unknown mesh quality."); break; } if ((this.Components.SpaceShader == null) || (this.Components.SpaceShader.name != resources.SpaceMaterial.name)) { spaceMaterial = resources.SpaceMaterial; this.Components.SpaceRenderer.sharedMaterial = spaceMaterial; this.Components.SpaceShader = spaceMaterial; } if ((this.Components.AtmosphereShader == null) || (this.Components.AtmosphereShader.name != resources.AtmosphereMaterial.name)) { spaceMaterial = resources.AtmosphereMaterial; this.Components.AtmosphereRenderer.sharedMaterial = spaceMaterial; this.Components.AtmosphereShader = spaceMaterial; } if ((this.Components.ClearShader == null) || (this.Components.ClearShader.name != resources.ClearMaterial.name)) { spaceMaterial = resources.ClearMaterial; this.Components.ClearRenderer.sharedMaterial = spaceMaterial; this.Components.ClearShader = spaceMaterial; } if ((this.Components.CloudShader == null) || (this.Components.CloudShader.name != cloudMaterialFastest.name)) { spaceMaterial = cloudMaterialFastest; this.Components.CloudRenderer.sharedMaterial = spaceMaterial; this.Components.CloudShader = spaceMaterial; } if ((this.Components.ShadowShader == null) || (this.Components.ShadowShader.name != shadowMaterialFastest.name)) { spaceMaterial = shadowMaterialFastest; this.Components.ShadowProjector.material = spaceMaterial; this.Components.ShadowShader = spaceMaterial; } if ((this.Components.SunShader == null) || (this.Components.SunShader.name != resources.SunMaterial.name)) { spaceMaterial = resources.SunMaterial; this.Components.SunRenderer.sharedMaterial = spaceMaterial; this.Components.SunShader = spaceMaterial; } if ((this.Components.MoonShader == null) || (this.Components.MoonShader.name != resources.MoonMaterial.name)) { spaceMaterial = resources.MoonMaterial; this.Components.MoonRenderer.sharedMaterial = spaceMaterial; this.Components.MoonShader = spaceMaterial; } if (this.Components.SpaceMeshFilter.sharedMesh != icosphereLow) { this.Components.SpaceMeshFilter.mesh = icosphereLow; } if (this.Components.AtmosphereMeshFilter.sharedMesh != icosphereMedium) { this.Components.AtmosphereMeshFilter.mesh = icosphereMedium; } if (this.Components.ClearMeshFilter.sharedMesh != mesh3) { this.Components.ClearMeshFilter.mesh = mesh3; } if (this.Components.CloudMeshFilter.sharedMesh != halfIcosphereLow) { this.Components.CloudMeshFilter.mesh = halfIcosphereLow; } if (this.Components.SunMeshFilter.sharedMesh != quad) { this.Components.SunMeshFilter.mesh = quad; } if (this.Components.MoonMeshFilter.sharedMesh != sphereLow) { this.Components.MoonMeshFilter.mesh = sphereLow; } }
protected void OnEnable() { DomeTransform = transform; if (Camera.main != null) { CameraTransform = Camera.main.transform; } else { Debug.LogWarning("Main camera does not exist or is not tagged 'MainCamera'."); } Sky = GetComponent <TOD_Sky>(); Animation = GetComponent <TOD_Animation>(); Time = GetComponent <TOD_Time>(); Weather = GetComponent <TOD_Weather>(); Resources = GetComponent <TOD_Resources>(); if (Space) { SpaceRenderer = Space.GetComponent <Renderer>(); SpaceShader = SpaceRenderer.sharedMaterial; SpaceMeshFilter = Space.GetComponent <MeshFilter>(); } else { Debug.LogError("Space reference not set. Disabling TOD_Sky script."); Sky.enabled = false; return; } if (Atmosphere) { AtmosphereRenderer = Atmosphere.GetComponent <Renderer>(); AtmosphereShader = AtmosphereRenderer.sharedMaterial; AtmosphereMeshFilter = Atmosphere.GetComponent <MeshFilter>(); } else { Debug.LogError("Atmosphere reference not set. Disabling TOD_Sky script."); Sky.enabled = false; return; } if (Clear) { ClearRenderer = Clear.GetComponent <Renderer>(); ClearShader = ClearRenderer.sharedMaterial; ClearMeshFilter = Clear.GetComponent <MeshFilter>(); } else { Debug.LogError("Clear reference not set. Disabling TOD_Sky script."); Sky.enabled = false; return; } if (Clouds) { CloudRenderer = Clouds.GetComponent <Renderer>(); CloudShader = CloudRenderer.sharedMaterial; CloudMeshFilter = Clouds.GetComponent <MeshFilter>(); } else { Debug.LogError("Clouds reference not set. Disabling TOD_Sky script."); Sky.enabled = false; return; } if (Projector) { ShadowProjector = Projector.GetComponent <Projector>(); ShadowShader = ShadowProjector.material; } else { Debug.LogError("Projector reference not set. Disabling TOD_Sky script."); Sky.enabled = false; return; } if (Light) { //LightTransform = gameObject.FindOrCreateChild ("LightTransform");//Light.transform; LightSource = Light.GetComponent <Light>(); } else { Debug.LogError("Light reference not set. Disabling TOD_Sky script."); Sky.enabled = false; return; } if (Sun) { SunTransform = Sun.transform; SunRenderer = Sun.GetComponent <Renderer>(); SunShader = SunRenderer.sharedMaterial; SunMeshFilter = Sun.GetComponent <MeshFilter>(); } else { Debug.LogError("Sun reference not set. Disabling TOD_Sky script."); Sky.enabled = false; return; } if (Moon) { MoonTransform = Moon.transform; MoonRenderer = Moon.GetComponent <Renderer>(); MoonShader = MoonRenderer.sharedMaterial; MoonMeshFilter = Moon.GetComponent <MeshFilter>(); } else { Debug.LogError("Moon reference not set. Disabling TOD_Sky script."); Sky.enabled = false; return; } if (Application.isPlaying) { DontDestroyOnLoad(transform); DontDestroyOnLoad(LightTransform); DontDestroyOnLoad(LightSource); } }
protected void OnEnable() { this.DomeTransform = base.transform; if (Camera.main == null) { Debug.LogWarning("Main camera does not exist or is not tagged 'MainCamera'."); } else { this.CameraTransform = Camera.main.transform; } this.Sky = base.GetComponent<TOD_Sky>(); this.Animation = base.GetComponent<TOD_Animation>(); this.Time = base.GetComponent<TOD_Time>(); this.Weather = base.GetComponent<TOD_Weather>(); this.Resources = base.GetComponent<TOD_Resources>(); if (!this.Space) { Debug.LogError("Space reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.SpaceRenderer = this.Space.renderer; this.SpaceShader = this.SpaceRenderer.sharedMaterial; this.SpaceMeshFilter = this.Space.GetComponent<MeshFilter>(); if (!this.Atmosphere) { Debug.LogError("Atmosphere reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.AtmosphereRenderer = this.Atmosphere.renderer; this.AtmosphereShader = this.AtmosphereRenderer.sharedMaterial; this.AtmosphereMeshFilter = this.Atmosphere.GetComponent<MeshFilter>(); if (!this.Clear) { Debug.LogError("Clear reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.ClearRenderer = this.Clear.renderer; this.ClearShader = this.ClearRenderer.sharedMaterial; this.ClearMeshFilter = this.Clear.GetComponent<MeshFilter>(); if (!this.Clouds) { Debug.LogError("Clouds reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.CloudRenderer = this.Clouds.renderer; this.CloudShader = this.CloudRenderer.sharedMaterial; this.CloudMeshFilter = this.Clouds.GetComponent<MeshFilter>(); if (!this.Projector) { Debug.LogError("Projector reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.ShadowProjector = this.Projector.GetComponent<UnityEngine.Projector>(); this.ShadowShader = this.ShadowProjector.material; if (!this.Light) { Debug.LogError("Light reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.LightTransform = this.Light.transform; this.LightSource = this.Light.light; if (!this.Sun) { Debug.LogError("Sun reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.SunTransform = this.Sun.transform; this.SunRenderer = this.Sun.renderer; this.SunShader = this.SunRenderer.sharedMaterial; this.SunMeshFilter = this.Sun.GetComponent<MeshFilter>(); if (!this.Moon) { Debug.LogError("Moon reference not set. Disabling TOD_Sky script."); this.Sky.enabled = false; return; } this.MoonTransform = this.Moon.transform; this.MoonRenderer = this.Moon.renderer; this.MoonShader = this.MoonRenderer.sharedMaterial; this.MoonMeshFilter = this.Moon.GetComponent<MeshFilter>(); }