Example #1
0
    public void Add(Mesh newSharedMesh = null, Material newSharedMaterial = null, PhysicMaterial newSharedPhysicsMaterial = null)
    {
        if (meshes == null)
        {
            meshes = new MeshList(1);
        }
        if (meshGameObjects == null)
        {
            meshGameObjects = new GameObjectList(1);
        }

        var mesh = new SGT_Mesh();

        if (newSharedMesh != null)
        {
            sharedMesh = null; mesh.SharedMesh = newSharedMesh;
        }
        if (newSharedMaterial != null)
        {
            sharedMaterial = null; mesh.SharedMaterial = newSharedMaterial;
        }
        if (newSharedPhysicsMaterial != null)
        {
            sharedPhysicsMaterial = null; mesh.SharedPhysicsMaterial = newSharedPhysicsMaterial;
        }

        meshes.Add(mesh);
        meshGameObjects.Add(null);
    }
Example #2
0
    private void Validate()
    {
        if (nebula == null)
        {
            nebula = SGT_Helper.CreateGameObject("Nebula", this);
        }
        if (nebulaMesh == null)
        {
            nebulaMesh = new SGT_Mesh();
        }
        if (nebulaMaterial == null)
        {
            nebulaMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Nebula/" + nebulaTechnique);
        }

        SGT_Helper.SetParent(nebula, gameObject);
        SGT_Helper.SetLayer(nebula, gameObject.layer);
        SGT_Helper.SetTag(nebula, gameObject.tag);

        var finalColour = SGT_Helper.Premultiply(particleColour);

        nebulaMaterial.SetColor("particleColour", finalColour);
        nebulaMaterial.SetTexture("particleTexture", particleTexture);
        nebulaMaterial.SetFloat("particleFadeInDistance", particleFadeInDistance);

        SGT_Helper.SetRenderQueue(nebulaMaterial, nebulaRenderQueue);

        nebulaMesh.GameObject          = nebula;
        nebulaMesh.HasMeshRenderer     = true;
        nebulaMesh.MeshRendererEnabled = SGT_Helper.IsBlack(finalColour) == false;
        nebulaMesh.SharedMesh          = generatedMesh;
        nebulaMesh.SharedMaterial      = nebulaMaterial;
        nebulaMesh.Update();
    }
	public void LateUpdate()
	{
		if (coronaGameObject == null) coronaGameObject = SGT_Helper.CreateGameObject("Corona", gameObject);
		if (coronaMesh       == null) coronaMesh       = new SGT_Mesh();
		if (coronaObserver   == null) coronaObserver   = SGT_Helper.FindCamera();
		
		SGT_Helper.SetParent(coronaGameObject, gameObject);
		SGT_Helper.SetLayer(coronaGameObject, gameObject.layer);
		SGT_Helper.SetTag(coronaGameObject, gameObject.tag);
		
		if (coronaAutoRegen == true)
		{
			Regenerate();
		}
		
		UpdateMaterial();
		UpdateShader();
		UpdateCoronaOffset();
		
		coronaMesh.GameObject          = coronaGameObject;
		coronaMesh.HasMeshRenderer     = true;
		coronaMesh.MeshRendererEnabled = true;
		coronaMesh.SharedMaterial      = coronaMaterial;
		coronaMesh.SharedMesh          = generatedMesh;
		coronaMesh.Update();
		
#if UNITY_EDITOR == true
		coronaMesh.HideInEditor();
#endif
	}
    // TODO: Check mesh size
    public void LateUpdate()
    {
        if (skysphereGameObject == null) skysphereGameObject = SGT_Helper.CreateGameObject("Skysphere", gameObject);
        if (skysphereMesh       == null) skysphereMesh       = new SGT_Mesh();
        if (skysphereObserver   == null) skysphereObserver   = SGT_Helper.FindCamera();

        SGT_Helper.SetParent(skysphereGameObject, gameObject);
        SGT_Helper.SetLayer(skysphereGameObject, gameObject.layer);
        SGT_Helper.SetTag(skysphereGameObject, gameObject.tag);

        UpdateMaterial();
        UpdateShader();

        if (skysphereObserver != null)
        {
            // Stretch to camera's far view frustum
            SGT_Helper.SetLocalScale(skysphereGameObject.transform, skysphereObserver.far * 0.9f);

            // Centre to main camera
            SGT_Helper.SetPosition(skysphereGameObject.transform, skysphereObserver.transform.position);
        }

        skysphereMesh.GameObject          = skysphereGameObject;
        skysphereMesh.HasMeshRenderer     = true;
        skysphereMesh.MeshRendererEnabled = true;
        skysphereMesh.SharedMaterial      = skysphereMaterial;
        skysphereMesh.Update();

        #if UNITY_EDITOR == true
        skysphereMesh.HideInEditor();
        #endif
    }
	public void LateUpdate()
	{
		if (oblatenessGameObject == null) oblatenessGameObject = SGT_Helper.CreateGameObject("Oblateness", gameObject);
		if (surfaceGameObject    == null) surfaceGameObject    = SGT_Helper.CreateGameObject("Surface", oblatenessGameObject);
		if (atmosphereGameObject == null) atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", oblatenessGameObject);
		if (atmosphereMesh       == null) atmosphereMesh       = new SGT_Mesh();
		if (starObserver         == null) starObserver         = SGT_Helper.FindCamera();
		if (surfaceTexture       == null) surfaceTexture       = new SGT_SurfaceTexture();
		if (surfaceMultiMesh     == null) surfaceMultiMesh     = new SGT_SurfaceMultiMesh();
		
		SGT_Helper.SetParent(oblatenessGameObject, gameObject);
		SGT_Helper.SetLayer(oblatenessGameObject, gameObject.layer);
		SGT_Helper.SetTag(oblatenessGameObject, gameObject.tag);
		
		SGT_Helper.SetParent(surfaceGameObject, oblatenessGameObject);
		SGT_Helper.SetLayer(surfaceGameObject, oblatenessGameObject.layer);
		SGT_Helper.SetTag(surfaceGameObject, oblatenessGameObject.tag);
		
		SGT_Helper.SetParent(atmosphereGameObject, oblatenessGameObject);
		SGT_Helper.SetLayer(atmosphereGameObject, oblatenessGameObject.layer);
		SGT_Helper.SetTag(atmosphereGameObject, oblatenessGameObject.tag);
		
		if (atmosphereDensityColour == null)
		{
			atmosphereDensityColour = new SGT_ColourGradient(false, true);
			atmosphereDensityColour.AddColourNode(new Color(1.0f, 1.0f, 0.0f, 1.0f), 0.0f);
			atmosphereDensityColour.AddColourNode(new Color(1.0f, 0.5f, 0.0f, 1.0f), 0.5f).Locked = true;
			atmosphereDensityColour.AddColourNode(new Color(1.0f, 0.0f, 0.0f, 1.0f), 1.0f);
		}
		
		UpdateTransform();
		UpdateGradient();
		UpdateMaterial();
		UpdateShader();
		
		surfaceMultiMesh.GameObject           = surfaceGameObject;
		surfaceMultiMesh.HasMeshRenderers     = true;
		surfaceMultiMesh.MeshRenderersEnabled = true;
		surfaceMultiMesh.MeshCollidersEnabled = true;
		surfaceMultiMesh.SetSharedMaterials(surfaceMaterials);
		surfaceMultiMesh.Update(gameObject.layer, gameObject.tag);
		
		atmosphereMesh.GameObject          = atmosphereGameObject;
		atmosphereMesh.HasMeshRenderer     = true;
		atmosphereMesh.MeshRendererEnabled = true;
		atmosphereMesh.SharedMaterial      = atmosphereMaterial;
		atmosphereMesh.Update();
		
#if UNITY_EDITOR == true
		SGT_Helper.HideGameObject(oblatenessGameObject);
		
		atmosphereMesh.HideInEditor();
		surfaceMultiMesh.HideInEditor();
#endif
	}
    private void Validate()
    {
        if (dust == null)
        {
            dust = SGT_Helper.CreateGameObject("Dust", this);
        }
        if (dustMesh == null)
        {
            dustMesh = new SGT_Mesh();
        }
        if (dustMaterial == null)
        {
            dustMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Dust/" + dustTechnique);
        }
        if (dustCamera == null)
        {
            dustCamera = SGT_Helper.FindCamera();
        }

        SGT_Helper.SetParent(dust, gameObject);
        SGT_Helper.SetLayer(dust, gameObject.layer);
        SGT_Helper.SetTag(dust, gameObject.tag);

        var finalColour           = SGT_Helper.Premultiply(particleColour);
        var oldDustCameraRotation = dustCameraRotation;

        if (dustCamera != null)
        {
            dustCameraRotation = dustCamera.transform.rotation;
        }

        var cameraRotationDelta = Quaternion.Inverse(oldDustCameraRotation) * dustCameraRotation;

        particleRoll -= cameraRotationDelta.eulerAngles.z;

        var roll = Quaternion.Euler(new Vector3(0.0f, 0.0f, particleRoll));

        dustMaterial.SetTexture("dustTexture", particleTexture);
        dustMaterial.SetFloat("dustRadius", dustRadius);
        dustMaterial.SetColor("particleColour", finalColour);
        dustMaterial.SetFloat("particleFadeInDistance", dustRadius / particleFadeInDistance);
        dustMaterial.SetFloat("particleFadeOutDistance", dustRadius / particleFadeOutDistance);
        dustMaterial.SetMatrix("particleRoll", SGT_MatrixHelper.Rotation(roll));

        SGT_Helper.SetRenderQueue(dustMaterial, dustRenderQueue);

        dustMesh.GameObject          = dust;
        dustMesh.HasMeshRenderer     = true;
        dustMesh.MeshRendererEnabled = SGT_Helper.IsBlack(finalColour) == false;
        dustMesh.SharedMesh          = generatedMesh;
        dustMesh.SharedMaterial      = dustMaterial;
        dustMesh.Update();
    }
Example #7
0
    private void Validate()
    {
        if (nebula == null)
        {
            nebula = SGT_Helper.CreateGameObject("Nebula", this);
        }
        if (nebulaMesh == null)
        {
            nebulaMesh = new SGT_Mesh();
        }
        if (nebulaMaterial == null)
        {
            nebulaMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Nebula/" + nebulaTechnique);
        }
        if (nebulaCamera == null)
        {
            NebulaCamera = SGT_Helper.FindCamera();                                   // NOTE: Assigning property
        }
        SGT_Helper.SetParent(nebula, gameObject);
        SGT_Helper.SetLayer(nebula, gameObject.layer);
        SGT_Helper.SetTag(nebula, gameObject.tag);

        var sideOrTop         = Mathf.Abs(Vector3.Dot((SGT_Helper.GetPosition(nebulaCamera) - transform.position).normalized, transform.up));
        var finalColour       = SGT_Helper.Premultiply(Color.Lerp(particleSideColour, particleTopColour, sideOrTop));
        var oldCameraRotation = nebulaCameraRotation; if (nebulaCamera != null)
        {
            nebulaCameraRotation = nebulaCamera.transform.rotation;
        }
        var cameraRotationDelta = Quaternion.Inverse(oldCameraRotation) * nebulaCameraRotation;

        nebulaCameraRoll = SGT_Helper.Wrap(nebulaCameraRoll - cameraRotationDelta.eulerAngles.z, 0.0f, 360.0f);

        var roll = Quaternion.Euler(new Vector3(0.0f, 0.0f, nebulaCameraRoll));

        nebulaMaterial.SetColor("particleColour", finalColour);
        nebulaMaterial.SetTexture("particleTexture", particleTexture);
        nebulaMaterial.SetFloat("particleFadeInDistance", particleFadeInDistance);
        nebulaMaterial.SetMatrix("cameraRoll", SGT_MatrixHelper.Rotation(roll));

        SGT_Helper.SetRenderQueue(nebulaMaterial, nebulaRenderQueue);

        nebulaMesh.GameObject          = nebula;
        nebulaMesh.HasMeshRenderer     = true;
        nebulaMesh.MeshRendererEnabled = SGT_Helper.IsBlack(finalColour) == false;
        nebulaMesh.SharedMesh          = generatedMesh;
        nebulaMesh.SharedMaterial      = nebulaMaterial;
        nebulaMesh.Update();
    }
Example #8
0
    public SGT_Mesh GetMesh(int index)
    {
        if (index >= 0 && meshes != null && index < meshes.Count)
        {
            var mesh = meshes[index];

            if (mesh == null)
            {
                mesh          = new SGT_Mesh();
                meshes[index] = mesh;
            }

            return(mesh);
        }

        return(null);
    }
    public static bool MeshesIdentical(SGT_Mesh a, SGT_Mesh b)
    {
        if (a == null && b != null)
        {
            return(false);
        }
        if (a != null && b == null)
        {
            return(false);
        }
        if (a != null && b != null)
        {
            if (a.sharedMesh != b.sharedMesh)
            {
                return(false);
            }
        }

        return(true);
    }
Example #10
0
    public void LateUpdate()     // TODO: Check mesh size
    {
        if (skysphereGameObject == null)
        {
            skysphereGameObject = SGT_Helper.CreateGameObject("Skysphere", gameObject);
        }
        if (skysphereMesh == null)
        {
            skysphereMesh = new SGT_Mesh();
        }
        if (skysphereObserver == null)
        {
            skysphereObserver = SGT_Helper.FindCamera();
        }

        SGT_Helper.SetParent(skysphereGameObject, gameObject);
        SGT_Helper.SetLayer(skysphereGameObject, gameObject.layer);
        SGT_Helper.SetTag(skysphereGameObject, gameObject.tag);

        UpdateMaterial();
        UpdateShader();

        if (skysphereObserver != null)
        {
            // Stretch to camera's far view frustum
            SGT_Helper.SetLocalScale(skysphereGameObject.transform, skysphereObserver.far * 0.9f);

            // Centre to main camera
            SGT_Helper.SetPosition(skysphereGameObject.transform, skysphereObserver.transform.position);
        }

        skysphereMesh.GameObject          = skysphereGameObject;
        skysphereMesh.HasMeshRenderer     = true;
        skysphereMesh.MeshRendererEnabled = true;
        skysphereMesh.SharedMaterial      = skysphereMaterial;
        skysphereMesh.Update();

#if UNITY_EDITOR == true
        skysphereMesh.HideInEditor();
#endif
    }
    public void LateUpdate()
    {
        if (coronaGameObject == null)
        {
            coronaGameObject = SGT_Helper.CreateGameObject("Corona", gameObject);
        }
        if (coronaMesh == null)
        {
            coronaMesh = new SGT_Mesh();
        }
        if (coronaObserver == null)
        {
            coronaObserver = SGT_Helper.FindCamera();
        }

        SGT_Helper.SetParent(coronaGameObject, gameObject);
        SGT_Helper.SetLayer(coronaGameObject, gameObject.layer);
        SGT_Helper.SetTag(coronaGameObject, gameObject.tag);

        if (coronaAutoRegen == true)
        {
            Regenerate();
        }

        UpdateMaterial();
        UpdateShader();
        UpdateCoronaOffset();

        coronaMesh.GameObject          = coronaGameObject;
        coronaMesh.HasMeshRenderer     = true;
        coronaMesh.MeshRendererEnabled = true;
        coronaMesh.SharedMaterial      = coronaMaterial;
        coronaMesh.SharedMesh          = generatedMesh;
        coronaMesh.Update();

#if UNITY_EDITOR == true
        coronaMesh.HideInEditor();
#endif
    }
    public static SGT_Mesh MeshField(string handle, string tooltip, SGT_Mesh field, bool required = false)
    {
        if (CanDraw == true && field != null)
        {
            var currentMesh = field.SharedMesh;

            if (required == true)
            {
                MarkNextFieldAsError(currentMesh == null);
            }

            var rect    = ReserveField(handle, tooltip);
            var newMesh = (Mesh)EditorGUI.ObjectField(rect, currentMesh, typeof(Mesh), false);

            if (currentMesh != newMesh)
            {
                field.SharedMesh = newMesh;
            }
        }

        return field;
    }
Example #13
0
    public static bool MeshesIdentical(SGT_MultiMesh a, SGT_MultiMesh b)
    {
        if (a == null && b != null)
        {
            return(false);
        }
        if (a != null && b == null)
        {
            return(false);
        }
        if (a != null && b != null)
        {
            if (a.meshes == null && b.meshes != null)
            {
                return(false);
            }
            if (a.meshes != null && b.meshes == null)
            {
                return(false);
            }
            if (a.meshes != null && b.meshes != null)
            {
                if (a.meshes.Count != b.meshes.Count)
                {
                    return(false);
                }

                for (var i = 0; i < a.meshes.Count; i++)
                {
                    if (SGT_Mesh.MeshesIdentical(a.meshes[i], b.meshes[i]) == false)
                    {
                        return(false);
                    }
                }
            }
        }

        return(true);
    }
    public static SGT_Mesh MeshField(string handle, string tooltip, SGT_Mesh field, bool required = false)
    {
        if (CanDraw == true && field != null)
        {
            var currentMesh = field.SharedMesh;

            if (required == true)
            {
                MarkNextFieldAsError(currentMesh == null);
            }

            var rect    = ReserveField(handle, tooltip);
            var newMesh = (Mesh)EditorGUI.ObjectField(rect, currentMesh, typeof(Mesh), false);

            if (currentMesh != newMesh)
            {
                field.SharedMesh = newMesh;
            }
        }

        return(field);
    }
Example #15
0
    private void Validate()
    {
        if (dust == null)
        {
            dust = SGT_Helper.CreateGameObject("Dust", this);
        }
        if (dustMesh == null)
        {
            dustMesh = new SGT_Mesh();
        }
        if (dustMaterial == null)
        {
            dustMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Dust/" + dustTechnique);
        }

        SGT_Helper.SetParent(dust, gameObject);
        SGT_Helper.SetLayer(dust, gameObject.layer);
        SGT_Helper.SetTag(dust, gameObject.tag);

        var finalColour = SGT_Helper.Premultiply(particleColour);

        dustMaterial.SetTexture("dustTexture", particleTexture);
        dustMaterial.SetFloat("dustRadius", dustRadius);
        dustMaterial.SetColor("particleColour", finalColour);
        dustMaterial.SetFloat("particleFadeInDistance", dustRadius / particleFadeInDistance);
        dustMaterial.SetFloat("particleFadeOutDistance", dustRadius / particleFadeOutDistance);

        SGT_Helper.SetRenderQueue(dustMaterial, dustRenderQueue);

        dustMesh.GameObject          = dust;
        dustMesh.HasMeshRenderer     = true;
        dustMesh.MeshRendererEnabled = SGT_Helper.IsBlack(finalColour) == false;
        dustMesh.SharedMesh          = generatedMesh;
        dustMesh.SharedMaterial      = dustMaterial;
        dustMesh.Update();
    }
Example #16
0
    public void LateUpdate()
    {
        if (surfaceGameObject == null)
        {
            surfaceGameObject = SGT_Helper.CreateGameObject("Surface", gameObject);
        }
        if (atmosphereGameObject == null)
        {
            atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", gameObject);
        }
        if (cloudsGameObject == null)
        {
            cloudsGameObject = SGT_Helper.CreateGameObject("Clouds", gameObject);
        }
        if (surfaceMesh == null)
        {
            surfaceMesh = new SGT_SurfaceMultiMesh();
        }
        if (surfaceTextureDay == null)
        {
            surfaceTextureDay = new SGT_SurfaceTexture();
        }
        if (surfaceTextureNight == null)
        {
            surfaceTextureNight = new SGT_SurfaceTexture();
        }
        if (surfaceTextureNormal == null)
        {
            surfaceTextureNormal = new SGT_SurfaceTexture();
        }
        if (surfaceTextureSpecular == null)
        {
            surfaceTextureSpecular = new SGT_SurfaceTexture();
        }
        if (planetObserver == null)
        {
            planetObserver = SGT_Helper.FindCamera();
        }
        if (planetLightSource == null)
        {
            planetLightSource = SGT_LightSource.Find();
        }

        SGT_Helper.SetParent(surfaceGameObject, gameObject);
        SGT_Helper.SetLayer(surfaceGameObject, gameObject.layer);
        SGT_Helper.SetTag(surfaceGameObject, gameObject.tag);

        SGT_Helper.SetParent(atmosphereGameObject, gameObject);
        SGT_Helper.SetLayer(atmosphereGameObject, gameObject.layer);
        SGT_Helper.SetTag(atmosphereGameObject, gameObject.tag);

        SGT_Helper.SetParent(cloudsGameObject, gameObject);
        SGT_Helper.SetLayer(cloudsGameObject, gameObject.layer);
        SGT_Helper.SetTag(cloudsGameObject, gameObject.tag);

        surfaceTextureDay.Configuration      = surfaceMesh.Configuration;
        surfaceTextureNight.Configuration    = surfaceMesh.Configuration;
        surfaceTextureNormal.Configuration   = surfaceMesh.Configuration;
        surfaceTextureSpecular.Configuration = surfaceMesh.Configuration;

        if (surfaceTextureDay.Modified == true)
        {
            updateShader |= ShaderFlags.SurfaceTextureDay;      surfaceTextureDay.Modified = false;
        }
        if (surfaceTextureNight.Modified == true)
        {
            updateShader |= ShaderFlags.SurfaceTextureNight;    surfaceTextureNight.Modified = false;
        }
        if (surfaceTextureNormal.Modified == true)
        {
            updateShader |= ShaderFlags.SurfaceTextureNormal;   surfaceTextureNormal.Modified = false;
        }
        if (surfaceTextureSpecular.Modified == true)
        {
            updateShader |= ShaderFlags.SurfaceTextureSpecular; surfaceTextureSpecular.Modified = false;
        }

        if (atmosphere == true)
        {
            if (atmosphereMesh == null)
            {
                atmosphereMesh = new SGT_Mesh();
            }
        }
        else
        {
            if (atmosphereMesh != null)
            {
                atmosphereMesh.Clear();
            }
        }

        if (clouds == true)
        {
            if (cloudsMesh == null)
            {
                cloudsMesh = new SGT_SurfaceMultiMesh();
            }
            if (cloudsTexture == null)
            {
                cloudsTexture = new SGT_SurfaceTexture();
            }

            if (cloudsTexture.Modified == true)
            {
                updateShader |= ShaderFlags.CloudsTexture; cloudsTexture.Modified = false;
            }
        }
        else
        {
            if (cloudsTexture != null)
            {
                cloudsTexture = null;
            }
            if (cloudsMesh != null)
            {
                cloudsMesh.Clear();
            }
        }

        if (planetLighting == null)
        {
            planetLighting = new SGT_ColourGradient(false, false);
            planetLighting.AddColourNode(Color.black, 0.45f);
            planetLighting.AddColourNode(Color.white, 0.55f);
        }

        if (atmosphereTwilightColour == null)
        {
            atmosphereTwilightColour = new SGT_ColourGradient(false, true);
            atmosphereTwilightColour.AddAlphaNode(1.0f, 0.45f);
            atmosphereTwilightColour.AddAlphaNode(0.0f, 0.65f);
            atmosphereTwilightColour.AddColourNode(new Color(1.0f, 0.19f, 0.0f, 1.0f), 0.5f);
        }

        if (atmosphereDensityColour == null)
        {
            atmosphereDensityColour = new SGT_ColourGradient(false, true);
            atmosphereDensityColour.AddColourNode(new Color(0.17f, 0.53f, 0.85f), 0.2f);
            atmosphereDensityColour.AddColourNode(Color.white, 0.5f).Locked = true;
            atmosphereDensityColour.AddColourNode(new Color(0.17f, 0.51f, 1.0f), 1.0f);
        }

        if (cloudsLimbColour == null)
        {
            cloudsLimbColour = new SGT_ColourGradient(false, true);
            cloudsLimbColour.AddColourNode(Color.white, 0.5f);
        }

        // Rotate?
        if (Application.isPlaying == true)
        {
            if (cloudsRotationPeriod != 0.0f)
            {
                cloudsGameObject.transform.Rotate(0.0f, SGT_Helper.DegreesPerSecond(cloudsRotationPeriod) * Time.smoothDeltaTime, 0.0f);
            }
        }

        // Update scales
        SGT_Helper.SetLocalScale(surfaceGameObject.transform, surfaceRadius);

        if (atmosphere == true)
        {
            SGT_Helper.SetLocalScale(atmosphereGameObject.transform, AtmosphereRadius);

            // Point atmosphere at camera
            if (planetObserver != null)
            {
                var observerPosition  = planetObserver.transform.position;
                var observerDirection = (observerPosition - gameObject.transform.position).normalized;

                SGT_Helper.SetUp(atmosphereGameObject.transform, observerDirection);
            }
        }

        if (clouds == true)
        {
            SGT_Helper.SetLocalScale(cloudsGameObject.transform, CloudsRadius);

            UpdateCloudsOffset();
        }

        UpdateGradient();
        UpdateTechnique();
        UpdateShader();

        surfaceMesh.GameObject           = surfaceGameObject;
        surfaceMesh.HasMeshRenderers     = true;
        surfaceMesh.MeshRenderersEnabled = true;
        surfaceMesh.MeshCollidersEnabled = true;
        surfaceMesh.SetSharedMaterials(surfaceMaterials);
        surfaceMesh.Update(gameObject.layer, gameObject.tag);

        if (atmosphere == true)
        {
            atmosphereMesh.GameObject          = atmosphereGameObject;
            atmosphereMesh.HasMeshRenderer     = true;
            atmosphereMesh.MeshRendererEnabled = true;
            atmosphereMesh.SharedMaterial      = atmosphereMaterial;
            atmosphereMesh.Update();
        }

        if (clouds == true)
        {
            cloudsMesh.GameObject           = cloudsGameObject;
            cloudsMesh.HasMeshRenderers     = true;
            cloudsMesh.MeshRenderersEnabled = true;
            cloudsMesh.SetSharedMaterials(cloudsMaterials);
            cloudsMesh.Update(gameObject.layer, gameObject.tag);
        }

#if UNITY_EDITOR == true
        surfaceMesh.HideInEditor();
        if (atmosphereMesh != null)
        {
            atmosphereMesh.HideInEditor();
        }
        if (cloudsMesh != null)
        {
            cloudsMesh.HideInEditor();
        }

        SGT_Helper.HideGameObject(atmosphereGameObject);
        SGT_Helper.HideGameObject(cloudsGameObject);
#endif
    }
Example #17
0
    public void LateUpdate()
    {
        if (thrusterObserver        == null) thrusterObserver        = SGT_Helper.FindCamera();
        if (thrusterFlameGameObject == null) thrusterFlameGameObject = SGT_Helper.CreateGameObject("Flame", gameObject);
        if (thrusterFlareGameObject == null) thrusterFlareGameObject = SGT_Helper.CreateGameObject("Flare", gameObject);

        SGT_Helper.SetParent(thrusterFlameGameObject, gameObject);
        SGT_Helper.SetLayer(thrusterFlameGameObject, gameObject.layer);
        SGT_Helper.SetTag(thrusterFlameGameObject, gameObject.tag);

        SGT_Helper.SetParent(thrusterFlareGameObject, gameObject);
        SGT_Helper.SetLayer(thrusterFlareGameObject, gameObject.layer);
        SGT_Helper.SetTag(thrusterFlareGameObject, gameObject.tag);

        if (thrusterPhysics == true && thrusterPhysicsRigidbody == null) thrusterPhysicsRigidbody = SGT_Helper.GetComponentUpwards<Rigidbody>(gameObject);

        var observerPosition = SGT_Helper.GetPosition(thrusterObserver);

        if (Application.isPlaying == true)
        {
            currentThrusterThrottle = Mathf.MoveTowards(currentThrusterThrottle, targetThrusterThrottle, thrusterTweenSpeed * Time.deltaTime);
        }
        else
        {
            currentThrusterThrottle = targetThrusterThrottle;
        }

        if (thrusterFlame == true)
        {
            if (thrusterFlameMesh == null) thrusterFlameMesh = new SGT_Mesh();

            // Offset flame
            SGT_Helper.SetLocalPosition(thrusterFlameGameObject.transform, thrusterFlameOffset);

            var finalFlameScale = thrusterFlameScale + thrusterFlameScaleChange * currentThrusterThrottle;

            // Hide/show flame
            if (finalFlameScale == Vector3.zero)
            {
                thrusterFlameMesh.MeshRendererEnabled = false;
            }
            else
            {
                if (Application.isPlaying == true)
                {
                    finalFlameScale *= Random.Range(1.0f - thrusterFlameScaleFlicker, 1.0f);
                }

                thrusterFlameMesh.MeshRendererEnabled = true;

                SGT_Helper.SetLocalScale(thrusterFlameGameObject.transform, finalFlameScale);

                // Roll flame to observer
                var pointDir = transform.InverseTransformPoint(observerPosition);
                var roll     = Mathf.Atan2(pointDir.y, pointDir.x) * Mathf.Rad2Deg;

                SGT_Helper.SetRotation(thrusterFlameGameObject.transform, transform.rotation * Quaternion.Euler(0.0f, 0.0f, roll));
            }

            thrusterFlameMesh.GameObject      = thrusterFlameGameObject;
            thrusterFlameMesh.HasMeshRenderer = true;
            thrusterFlameMesh.Update();
        }
        else
        {
            if (thrusterFlameMesh != null) thrusterFlameMesh = thrusterFlameMesh.Clear();
        }

        if (thrusterFlare == true)
        {
            if (thrusterFlareMesh == null) thrusterFlareMesh = new SGT_Mesh();

            // Offset flare
            SGT_Helper.SetLocalPosition(thrusterFlareGameObject.transform, thrusterFlareOffset);

            // Flare visible?
            var a               = thrusterFlareGameObject.transform.position;
            var b               = observerPosition;
            var direction       = (b - a).normalized;
            var distance        = (b - a).magnitude;
            var targetFlareSize = 0.0f;

            // If the ray hits something, then hide the flare
            if (Physics.Raycast(a, direction, distance, thrusterFlareRaycastMask) == true)
            {
                targetFlareSize = 0.0f;
            }
            else
            {
                targetFlareSize = 1.0f;
            }

            // Point flare at observer
            if (thrusterObserver != null)
            {
                SGT_Helper.SetRotation(thrusterFlareGameObject.transform, thrusterObserver.transform.rotation);
            }

            // Fade flare in/out based on raycast
            if (Application.isPlaying == true)
            {
                currentThrusterFlareScale = Mathf.MoveTowards(currentThrusterFlareScale, targetFlareSize, thrusterFlareScaleTweenSpeed * Time.deltaTime);
            }
            else
            {
                currentThrusterFlareScale = targetFlareSize;
            }

            var finalFlareScale = currentThrusterFlareScale * (thrusterFlareScale + thrusterFlareScaleChange * currentThrusterThrottle);

            // Hide/show flare
            if (finalFlareScale == Vector3.zero)
            {
                thrusterFlareMesh.MeshRendererEnabled = false;
            }
            else
            {
                if (Application.isPlaying == true)
                {
                    finalFlareScale *= Random.Range(1.0f - thrusterFlareScaleFlicker, 1.0f);
                }

                thrusterFlareMesh.MeshRendererEnabled = true;

                SGT_Helper.SetLocalScale(thrusterFlareGameObject.transform, finalFlareScale);
            }

            thrusterFlareMesh.GameObject      = thrusterFlareGameObject;
            thrusterFlareMesh.HasMeshRenderer = true;
            thrusterFlareMesh.Update();
        }
        else
        {
            if (thrusterFlareMesh != null) thrusterFlareMesh = thrusterFlareMesh.Clear();
        }

        #if UNITY_EDITOR == true
        if (thrusterFlameMesh != null) thrusterFlameMesh.HideInEditor();
        if (thrusterFlareMesh != null) thrusterFlareMesh.HideInEditor();

        SGT_Helper.HideGameObject(thrusterFlameGameObject);
        SGT_Helper.HideGameObject(thrusterFlareGameObject);
        #endif
    }
Example #18
0
    public void LateUpdate()
    {
        if (oblatenessGameObject == null)
        {
            oblatenessGameObject = SGT_Helper.CreateGameObject("Oblateness", gameObject);
        }
        if (surfaceGameObject == null)
        {
            surfaceGameObject = SGT_Helper.CreateGameObject("Surface", oblatenessGameObject);
        }
        if (atmosphereGameObject == null)
        {
            atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", oblatenessGameObject);
        }
        if (atmosphereMesh == null)
        {
            atmosphereMesh = new SGT_Mesh();
        }
        if (starObserver == null)
        {
            starObserver = SGT_Helper.FindCamera();
        }
        if (surfaceTexture == null)
        {
            surfaceTexture = new SGT_SurfaceTexture();
        }
        if (surfaceMultiMesh == null)
        {
            surfaceMultiMesh = new SGT_SurfaceMultiMesh();
        }

        SGT_Helper.SetParent(oblatenessGameObject, gameObject);
        SGT_Helper.SetLayer(oblatenessGameObject, gameObject.layer);
        SGT_Helper.SetTag(oblatenessGameObject, gameObject.tag);

        SGT_Helper.SetParent(surfaceGameObject, oblatenessGameObject);
        SGT_Helper.SetLayer(surfaceGameObject, oblatenessGameObject.layer);
        SGT_Helper.SetTag(surfaceGameObject, oblatenessGameObject.tag);

        SGT_Helper.SetParent(atmosphereGameObject, oblatenessGameObject);
        SGT_Helper.SetLayer(atmosphereGameObject, oblatenessGameObject.layer);
        SGT_Helper.SetTag(atmosphereGameObject, oblatenessGameObject.tag);

        if (atmosphereDensityColour == null)
        {
            atmosphereDensityColour = new SGT_ColourGradient(false, true);
            atmosphereDensityColour.AddColourNode(new Color(1.0f, 1.0f, 0.0f, 1.0f), 0.0f);
            atmosphereDensityColour.AddColourNode(new Color(1.0f, 0.5f, 0.0f, 1.0f), 0.5f).Locked = true;
            atmosphereDensityColour.AddColourNode(new Color(1.0f, 0.0f, 0.0f, 1.0f), 1.0f);
        }

        UpdateTransform();
        UpdateGradient();
        UpdateMaterial();
        UpdateShader();

        surfaceMultiMesh.GameObject           = surfaceGameObject;
        surfaceMultiMesh.HasMeshRenderers     = true;
        surfaceMultiMesh.MeshRenderersEnabled = true;
        surfaceMultiMesh.MeshCollidersEnabled = true;
        surfaceMultiMesh.SetSharedMaterials(surfaceMaterials);
        surfaceMultiMesh.Update(gameObject.layer, gameObject.tag);

        atmosphereMesh.GameObject          = atmosphereGameObject;
        atmosphereMesh.HasMeshRenderer     = true;
        atmosphereMesh.MeshRendererEnabled = true;
        atmosphereMesh.SharedMaterial      = atmosphereMaterial;
        atmosphereMesh.Update();

#if UNITY_EDITOR == true
        SGT_Helper.HideGameObject(oblatenessGameObject);

        atmosphereMesh.HideInEditor();
        surfaceMultiMesh.HideInEditor();
#endif
    }
    public void LateUpdate()
    {
        if (oblatenessGameObject == null) oblatenessGameObject = SGT_Helper.CreateGameObject("Oblateness", gameObject);
        if (atmosphereGameObject == null) atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", oblatenessGameObject);
        if (atmosphereMesh       == null) atmosphereMesh      = new SGT_Mesh();
        if (gasGiantLightSource  == null) gasGiantLightSource = SGT_LightSource.Find();
        if (gasGiantObserver     == null) gasGiantObserver    = SGT_Helper.FindCamera();

        SGT_Helper.SetParent(oblatenessGameObject, gameObject);
        SGT_Helper.SetLayer(oblatenessGameObject, gameObject.layer);
        SGT_Helper.SetTag(oblatenessGameObject, gameObject.tag);

        SGT_Helper.SetParent(atmosphereGameObject, oblatenessGameObject);
        SGT_Helper.SetLayer(atmosphereGameObject, oblatenessGameObject.layer);
        SGT_Helper.SetTag(atmosphereGameObject, oblatenessGameObject.tag);

        if (atmosphereLightingColour == null)
        {
            atmosphereLightingColour = new SGT_ColourGradient(false, false);
            atmosphereLightingColour.AddColourNode(Color.black, 0.4f);
            atmosphereLightingColour.AddColourNode(Color.white, 0.7f);
        }

        if (atmosphereTwilightColour == null)
        {
            atmosphereTwilightColour = new SGT_ColourGradient(false, true);
            atmosphereTwilightColour.AddAlphaNode(1.0f, 0.4f);
            atmosphereTwilightColour.AddAlphaNode(0.0f, 0.5f);
            atmosphereTwilightColour.AddColourNode(Color.red, 0.5f);
        }

        if (atmosphereLimbColour == null)
        {
            atmosphereLimbColour = new SGT_ColourGradient(false, true);
            atmosphereLimbColour.AddAlphaNode(0.0f, 0.75f);
            atmosphereLimbColour.AddAlphaNode(1.0f, 1.0f);
            atmosphereLimbColour.AddColourNode(Color.blue, 0.4f);
        }

        if (shadowAutoUpdate == true)
        {
            switch (shadowType)
            {
                case SGT_ShadowOccluder.Ring:
                {
                    var fill = new SGT_FillRingDimensions();

                    SendMessage("FillRingDimensions", fill, SendMessageOptions.DontRequireReceiver);

                    shadowRadius = fill.Radius;
                    shadowWidth  = fill.Width;
                }
                break;

                case SGT_ShadowOccluder.Planet:
                {
                    if (shadowGameObject != null)
                    {
                        var fill = new SGT_FillFloat();

                        shadowGameObject.SendMessage("FillShadowRadius", fill, SendMessageOptions.DontRequireReceiver);

                        shadowRadius = fill.Float;
                    }
                }
                break;
            }
        }

        UpdateTransform();
        UpdateGradient();
        UpdateMaterial();
        UpdateShader();

        // Update mesh
        atmosphereMesh.GameObject          = atmosphereGameObject;
        atmosphereMesh.HasMeshRenderer     = true;
        atmosphereMesh.MeshRendererEnabled = true;
        atmosphereMesh.SharedMaterial      = atmosphereMaterial;
        atmosphereMesh.Update();

        #if UNITY_EDITOR == true
        SGT_Helper.HideGameObject(oblatenessGameObject);

        atmosphereMesh.HideInEditor();
        #endif
    }
Example #20
0
    public void LateUpdate()
    {
        if (oblatenessGameObject == null)
        {
            oblatenessGameObject = SGT_Helper.CreateGameObject("Oblateness", gameObject);
        }
        if (atmosphereGameObject == null)
        {
            atmosphereGameObject = SGT_Helper.CreateGameObject("Atmosphere", oblatenessGameObject);
        }
        if (atmosphereMesh == null)
        {
            atmosphereMesh = new SGT_Mesh();
        }
        if (gasGiantLightSource == null)
        {
            gasGiantLightSource = SGT_LightSource.Find();
        }
        if (gasGiantObserver == null)
        {
            gasGiantObserver = SGT_Helper.FindCamera();
        }

        SGT_Helper.SetParent(oblatenessGameObject, gameObject);
        SGT_Helper.SetLayer(oblatenessGameObject, gameObject.layer);
        SGT_Helper.SetTag(oblatenessGameObject, gameObject.tag);

        SGT_Helper.SetParent(atmosphereGameObject, oblatenessGameObject);
        SGT_Helper.SetLayer(atmosphereGameObject, oblatenessGameObject.layer);
        SGT_Helper.SetTag(atmosphereGameObject, oblatenessGameObject.tag);

        if (atmosphereLightingColour == null)
        {
            atmosphereLightingColour = new SGT_ColourGradient(false, false);
            atmosphereLightingColour.AddColourNode(Color.black, 0.4f);
            atmosphereLightingColour.AddColourNode(Color.white, 0.7f);
        }

        if (atmosphereTwilightColour == null)
        {
            atmosphereTwilightColour = new SGT_ColourGradient(false, true);
            atmosphereTwilightColour.AddAlphaNode(1.0f, 0.4f);
            atmosphereTwilightColour.AddAlphaNode(0.0f, 0.5f);
            atmosphereTwilightColour.AddColourNode(Color.red, 0.5f);
        }

        if (atmosphereLimbColour == null)
        {
            atmosphereLimbColour = new SGT_ColourGradient(false, true);
            atmosphereLimbColour.AddAlphaNode(0.0f, 0.75f);
            atmosphereLimbColour.AddAlphaNode(1.0f, 1.0f);
            atmosphereLimbColour.AddColourNode(Color.blue, 0.4f);
        }

        if (shadowAutoUpdate == true)
        {
            switch (shadowType)
            {
            case SGT_ShadowOccluder.Ring:
            {
                var fill = new SGT_FillRingDimensions();

                SendMessage("FillRingDimensions", fill, SendMessageOptions.DontRequireReceiver);

                shadowRadius = fill.Radius;
                shadowWidth  = fill.Width;
            }
            break;

            case SGT_ShadowOccluder.Planet:
            {
                if (shadowGameObject != null)
                {
                    var fill = new SGT_FillFloat();

                    shadowGameObject.SendMessage("FillShadowRadius", fill, SendMessageOptions.DontRequireReceiver);

                    shadowRadius = fill.Float;
                }
            }
            break;
            }
        }

        UpdateTransform();
        UpdateGradient();
        UpdateMaterial();
        UpdateShader();

        // Update mesh
        atmosphereMesh.GameObject          = atmosphereGameObject;
        atmosphereMesh.HasMeshRenderer     = true;
        atmosphereMesh.MeshRendererEnabled = true;
        atmosphereMesh.SharedMaterial      = atmosphereMaterial;
        atmosphereMesh.Update();

#if UNITY_EDITOR == true
        SGT_Helper.HideGameObject(oblatenessGameObject);

        atmosphereMesh.HideInEditor();
#endif
    }
Example #21
0
    public void LateUpdate()
    {
        if (thrusterObserver == null)
        {
            thrusterObserver = SGT_Helper.FindCamera();
        }
        if (thrusterFlameGameObject == null)
        {
            thrusterFlameGameObject = SGT_Helper.CreateGameObject("Flame", gameObject);
        }
        if (thrusterFlareGameObject == null)
        {
            thrusterFlareGameObject = SGT_Helper.CreateGameObject("Flare", gameObject);
        }

        SGT_Helper.SetParent(thrusterFlameGameObject, gameObject);
        SGT_Helper.SetLayer(thrusterFlameGameObject, gameObject.layer);
        SGT_Helper.SetTag(thrusterFlameGameObject, gameObject.tag);

        SGT_Helper.SetParent(thrusterFlareGameObject, gameObject);
        SGT_Helper.SetLayer(thrusterFlareGameObject, gameObject.layer);
        SGT_Helper.SetTag(thrusterFlareGameObject, gameObject.tag);

        if (thrusterPhysics == true && thrusterPhysicsRigidbody == null)
        {
            thrusterPhysicsRigidbody = SGT_Helper.GetComponentUpwards <Rigidbody>(gameObject);
        }

        var observerPosition = SGT_Helper.GetPosition(thrusterObserver);

        if (Application.isPlaying == true)
        {
            currentThrusterThrottle = Mathf.MoveTowards(currentThrusterThrottle, targetThrusterThrottle, thrusterTweenSpeed * Time.deltaTime);
        }
        else
        {
            currentThrusterThrottle = targetThrusterThrottle;
        }

        if (thrusterFlame == true)
        {
            if (thrusterFlameMesh == null)
            {
                thrusterFlameMesh = new SGT_Mesh();
            }

            // Offset flame
            SGT_Helper.SetLocalPosition(thrusterFlameGameObject.transform, thrusterFlameOffset);

            var finalFlameScale = thrusterFlameScale + thrusterFlameScaleChange * currentThrusterThrottle;

            // Hide/show flame
            if (finalFlameScale == Vector3.zero)
            {
                thrusterFlameMesh.MeshRendererEnabled = false;
            }
            else
            {
                if (Application.isPlaying == true)
                {
                    finalFlameScale *= Random.Range(1.0f - thrusterFlameScaleFlicker, 1.0f);
                }

                thrusterFlameMesh.MeshRendererEnabled = true;

                SGT_Helper.SetLocalScale(thrusterFlameGameObject.transform, finalFlameScale);

                // Roll flame to observer
                var pointDir = transform.InverseTransformPoint(observerPosition);
                var roll     = Mathf.Atan2(pointDir.y, pointDir.x) * Mathf.Rad2Deg;

                SGT_Helper.SetRotation(thrusterFlameGameObject.transform, transform.rotation * Quaternion.Euler(0.0f, 0.0f, roll));
            }

            thrusterFlameMesh.GameObject      = thrusterFlameGameObject;
            thrusterFlameMesh.HasMeshRenderer = true;
            thrusterFlameMesh.Update();
        }
        else
        {
            if (thrusterFlameMesh != null)
            {
                thrusterFlameMesh = thrusterFlameMesh.Clear();
            }
        }

        if (thrusterFlare == true)
        {
            if (thrusterFlareMesh == null)
            {
                thrusterFlareMesh = new SGT_Mesh();
            }

            // Offset flare
            SGT_Helper.SetLocalPosition(thrusterFlareGameObject.transform, thrusterFlareOffset);

            // Flare visible?
            var a               = thrusterFlareGameObject.transform.position;
            var b               = observerPosition;
            var direction       = (b - a).normalized;
            var distance        = (b - a).magnitude;
            var targetFlareSize = 0.0f;

            // If the ray hits something, then hide the flare
            if (Physics.Raycast(a, direction, distance, thrusterFlareRaycastMask) == true)
            {
                targetFlareSize = 0.0f;
            }
            else
            {
                targetFlareSize = 1.0f;
            }

            // Point flare at observer
            if (thrusterObserver != null)
            {
                SGT_Helper.SetRotation(thrusterFlareGameObject.transform, thrusterObserver.transform.rotation);
            }

            // Fade flare in/out based on raycast
            if (Application.isPlaying == true)
            {
                currentThrusterFlareScale = Mathf.MoveTowards(currentThrusterFlareScale, targetFlareSize, thrusterFlareScaleTweenSpeed * Time.deltaTime);
            }
            else
            {
                currentThrusterFlareScale = targetFlareSize;
            }

            var finalFlareScale = currentThrusterFlareScale * (thrusterFlareScale + thrusterFlareScaleChange * currentThrusterThrottle);

            // Hide/show flare
            if (finalFlareScale == Vector3.zero)
            {
                thrusterFlareMesh.MeshRendererEnabled = false;
            }
            else
            {
                if (Application.isPlaying == true)
                {
                    finalFlareScale *= Random.Range(1.0f - thrusterFlareScaleFlicker, 1.0f);
                }

                thrusterFlareMesh.MeshRendererEnabled = true;

                SGT_Helper.SetLocalScale(thrusterFlareGameObject.transform, finalFlareScale);
            }

            thrusterFlareMesh.GameObject      = thrusterFlareGameObject;
            thrusterFlareMesh.HasMeshRenderer = true;
            thrusterFlareMesh.Update();
        }
        else
        {
            if (thrusterFlareMesh != null)
            {
                thrusterFlareMesh = thrusterFlareMesh.Clear();
            }
        }

#if UNITY_EDITOR == true
        if (thrusterFlameMesh != null)
        {
            thrusterFlameMesh.HideInEditor();
        }
        if (thrusterFlareMesh != null)
        {
            thrusterFlareMesh.HideInEditor();
        }

        SGT_Helper.HideGameObject(thrusterFlameGameObject);
        SGT_Helper.HideGameObject(thrusterFlareGameObject);
#endif
    }
Example #22
0
    public void Update()
    {
        if (meshes == null)
        {
            meshes = new MeshList();
        }
        if (meshGameObjects == null)
        {
            meshGameObjects = new GameObjectList();
        }

        if (meshGameObjects.Count != meshes.Count)
        {
            SGT_ArrayHelper.Resize(ref meshGameObjects, meshes.Count, true);
        }

        // Update meshes
        for (var i = meshes.Count - 1; i >= 0; i--)
        {
            var mesh           = meshes[i];
            var meshGameObject = meshGameObjects[i];

            if (mesh == null)
            {
                mesh      = new SGT_Mesh();
                meshes[i] = mesh;
            }

            if (meshGameObject == null)
            {
                meshGameObject     = SGT_Helper.CreateGameObject("Mesh " + (i + 1), gameObject);
                meshGameObjects[i] = meshGameObject;
            }

            if (gameObject != null)
            {
                SGT_Helper.SetParent(meshGameObject, gameObject);
                SGT_Helper.SetLayer(meshGameObject, gameObject.layer);
                SGT_Helper.SetTag(meshGameObject, gameObject.tag);
            }

            if (sharedMesh != null)
            {
                mesh.SharedMesh = sharedMesh;
            }
            if (sharedMaterial != null)
            {
                mesh.SharedMaterial = sharedMaterial;
            }
            if (sharedPhysicsMaterial != null)
            {
                mesh.SharedPhysicsMaterial = sharedPhysicsMaterial;
            }

            mesh.GameObject          = meshGameObject;
            mesh.HasMeshRenderer     = hasMeshRenderers;
            mesh.MeshRendererEnabled = meshRenderersEnabled;
            mesh.HasMeshCollider     = hasMeshColliders;
            mesh.MeshColliderEnabled = meshCollidersEnabled;
            mesh.Update();
        }

        // Check integrity
        if (gameObject != null && meshGameObjects.Count != gameObject.transform.childCount)
        {
            SGT_Helper.DestroyChildren(gameObject);
            SGT_Helper.DestroyGameObjects(meshGameObjects);
        }
    }
    public void LateUpdate()
    {
        if (surfaceGameObject      == null) surfaceGameObject      = SGT_Helper.CreateGameObject("Surface", gameObject);
        if (atmosphereGameObject   == null) atmosphereGameObject   = SGT_Helper.CreateGameObject("Atmosphere", gameObject);
        if (cloudsGameObject       == null) cloudsGameObject       = SGT_Helper.CreateGameObject("Clouds", gameObject);
        if (surfaceMesh            == null) surfaceMesh            = new SGT_SurfaceMultiMesh();
        if (surfaceTextureDay      == null) surfaceTextureDay      = new SGT_SurfaceTexture();
        if (surfaceTextureNight    == null) surfaceTextureNight    = new SGT_SurfaceTexture();
        if (surfaceTextureNormal   == null) surfaceTextureNormal   = new SGT_SurfaceTexture();
        if (surfaceTextureSpecular == null) surfaceTextureSpecular = new SGT_SurfaceTexture();
        if (planetObserver         == null) planetObserver         = SGT_Helper.FindCamera();
        if (planetLightSource      == null) planetLightSource      = SGT_LightSource.Find();

        SGT_Helper.SetParent(surfaceGameObject, gameObject);
        SGT_Helper.SetLayer(surfaceGameObject, gameObject.layer);
        SGT_Helper.SetTag(surfaceGameObject, gameObject.tag);

        SGT_Helper.SetParent(atmosphereGameObject, gameObject);
        SGT_Helper.SetLayer(atmosphereGameObject, gameObject.layer);
        SGT_Helper.SetTag(atmosphereGameObject, gameObject.tag);

        SGT_Helper.SetParent(cloudsGameObject, gameObject);
        SGT_Helper.SetLayer(cloudsGameObject, gameObject.layer);
        SGT_Helper.SetTag(cloudsGameObject, gameObject.tag);

        surfaceTextureDay.Configuration      = surfaceMesh.Configuration;
        surfaceTextureNight.Configuration    = surfaceMesh.Configuration;
        surfaceTextureNormal.Configuration   = surfaceMesh.Configuration;
        surfaceTextureSpecular.Configuration = surfaceMesh.Configuration;

        if (surfaceTextureDay.Modified      == true) { updateShader |= ShaderFlags.SurfaceTextureDay;      surfaceTextureDay.Modified      = false; }
        if (surfaceTextureNight.Modified    == true) { updateShader |= ShaderFlags.SurfaceTextureNight;    surfaceTextureNight.Modified    = false; }
        if (surfaceTextureNormal.Modified   == true) { updateShader |= ShaderFlags.SurfaceTextureNormal;   surfaceTextureNormal.Modified   = false; }
        if (surfaceTextureSpecular.Modified == true) { updateShader |= ShaderFlags.SurfaceTextureSpecular; surfaceTextureSpecular.Modified = false; }

        if (atmosphere == true)
        {
            if (atmosphereMesh == null) atmosphereMesh = new SGT_Mesh();
        }
        else
        {
            if (atmosphereMesh != null) atmosphereMesh.Clear();
        }

        if (clouds == true)
        {
            if (cloudsMesh    == null) cloudsMesh    = new SGT_SurfaceMultiMesh();
            if (cloudsTexture == null) cloudsTexture = new SGT_SurfaceTexture();

            if (cloudsTexture.Modified == true) { updateShader |= ShaderFlags.CloudsTexture; cloudsTexture.Modified = false; }
        }
        else
        {
            if (cloudsTexture != null) cloudsTexture = null;
            if (cloudsMesh    != null) cloudsMesh.Clear();
        }

        if (planetLighting == null)
        {
            planetLighting = new SGT_ColourGradient(false, false);
            planetLighting.AddColourNode(Color.black, 0.45f);
            planetLighting.AddColourNode(Color.white, 0.55f);
        }

        if (atmosphereTwilightColour == null)
        {
            atmosphereTwilightColour = new SGT_ColourGradient(false, true);
            atmosphereTwilightColour.AddAlphaNode(1.0f, 0.45f);
            atmosphereTwilightColour.AddAlphaNode(0.0f, 0.65f);
            atmosphereTwilightColour.AddColourNode(new Color(1.0f, 0.19f, 0.0f, 1.0f), 0.5f);
        }

        if (atmosphereDensityColour == null)
        {
            atmosphereDensityColour = new SGT_ColourGradient(false, true);
            atmosphereDensityColour.AddColourNode(new Color(0.17f, 0.53f, 0.85f), 0.2f);
            atmosphereDensityColour.AddColourNode(Color.white, 0.5f).Locked = true;
            atmosphereDensityColour.AddColourNode(new Color(0.17f, 0.51f, 1.0f), 1.0f);
        }

        if (cloudsLimbColour == null)
        {
            cloudsLimbColour = new SGT_ColourGradient(false, true);
            cloudsLimbColour.AddColourNode(Color.white, 0.5f);
        }

        // Rotate?
        if (Application.isPlaying == true)
        {
            if (cloudsRotationPeriod != 0.0f)
            {
                cloudsGameObject.transform.Rotate(0.0f, SGT_Helper.DegreesPerSecond(cloudsRotationPeriod) * Time.smoothDeltaTime, 0.0f);
            }
        }

        // Update scales
        SGT_Helper.SetLocalScale(surfaceGameObject.transform, surfaceRadius);

        if (atmosphere == true)
        {
            SGT_Helper.SetLocalScale(atmosphereGameObject.transform, AtmosphereRadius);

            // Point atmosphere at camera
            if (planetObserver != null)
            {
                var observerPosition  = planetObserver.transform.position;
                var observerDirection = (observerPosition - gameObject.transform.position).normalized;

                SGT_Helper.SetUp(atmosphereGameObject.transform, observerDirection);
            }
        }

        if (clouds == true)
        {
            SGT_Helper.SetLocalScale(cloudsGameObject.transform, CloudsRadius);

            UpdateCloudsOffset();
        }

        UpdateGradient();
        UpdateTechnique();
        UpdateShader();

        surfaceMesh.GameObject           = surfaceGameObject;
        surfaceMesh.HasMeshRenderers     = true;
        surfaceMesh.MeshRenderersEnabled = true;
        surfaceMesh.MeshCollidersEnabled = true;
        surfaceMesh.SetSharedMaterials(surfaceMaterials);
        surfaceMesh.Update(gameObject.layer, gameObject.tag);

        if (atmosphere == true)
        {
            atmosphereMesh.GameObject          = atmosphereGameObject;
            atmosphereMesh.HasMeshRenderer     = true;
            atmosphereMesh.MeshRendererEnabled = true;
            atmosphereMesh.SharedMaterial      = atmosphereMaterial;
            atmosphereMesh.Update();
        }

        if (clouds == true)
        {
            cloudsMesh.GameObject           = cloudsGameObject;
            cloudsMesh.HasMeshRenderers     = true;
            cloudsMesh.MeshRenderersEnabled = true;
            cloudsMesh.SetSharedMaterials(cloudsMaterials);
            cloudsMesh.Update(gameObject.layer, gameObject.tag);
        }

        #if UNITY_EDITOR == true
        surfaceMesh.HideInEditor();
        if (atmosphereMesh != null) atmosphereMesh.HideInEditor();
        if (cloudsMesh     != null) cloudsMesh.HideInEditor();

        SGT_Helper.HideGameObject(atmosphereGameObject);
        SGT_Helper.HideGameObject(cloudsGameObject);
        #endif
    }