Пример #1
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);
        }
        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();
    }
    public void LateUpdate()
    {
        if (starfieldGameObject == null)
        {
            starfieldGameObject = SGT_Helper.CreateGameObject("Starfield", gameObject);
        }
        if (starfieldMultiMesh == null)
        {
            starfieldMultiMesh = new SGT_MultiMesh();
        }
        if (starfieldObserver == null)
        {
            starfieldObserver = SGT_Helper.FindCamera();
        }
        if (packer == null)
        {
            packer = new SGT_Packer();
        }
        if (starVariants == null)
        {
            starVariants = new VariantList();
        }

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

        packer.AtlasFormat     = TextureFormat.RGB24;
        packer.AtlasMaxSize    = SGT_SquareSize.Square2048;
        packer.AtlasFilterMode = FilterMode.Trilinear;
        packer.AtlasCountMax   = 1;

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

        UpdateMaterial();
        UpdateShader();
        UpdateBackground();

        starfieldMultiMesh.GameObject           = starfieldGameObject;
        starfieldMultiMesh.HasMeshRenderers     = true;
        starfieldMultiMesh.MeshRenderersEnabled = true;
        starfieldMultiMesh.SharedMaterial       = starfieldMaterial;
        starfieldMultiMesh.ReplaceAll(meshes);
        starfieldMultiMesh.Update();

#if UNITY_EDITOR == true
        starfieldMultiMesh.HideInEditor();
#endif
    }
Пример #3
0
    public void LateUpdate()
    {
        if (ringGameObject == null)
        {
            ringGameObject = SGT_Helper.CreateGameObject("Ring", gameObject);
        }
        if (ringMultiMesh == null)
        {
            ringMultiMesh = new SGT_MultiMesh();
        }
        if (ringLightSource == null)
        {
            ringLightSource = SGT_LightSource.Find();
        }
        if (ringCamera == null)
        {
            RingCamera = SGT_Helper.FindCamera();                                       // NOTE: Assigning property
        }
        SGT_Helper.SetParent(ringGameObject, gameObject);
        SGT_Helper.SetLayer(ringGameObject, gameObject.layer);
        SGT_Helper.SetTag(ringGameObject, gameObject.tag);

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

        if (shadowAutoUpdate == true)
        {
            var fill = new SGT_FillFloat();

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

            shadowRadius = fill.Float;
        }

        UpdateTechnique();
        UpdateShader();

        ringMultiMesh.GameObject           = ringGameObject;
        ringMultiMesh.HasMeshRenderers     = true;
        ringMultiMesh.MeshRenderersEnabled = true;
        ringMultiMesh.SharedMaterial       = ringMaterial;
        ringMultiMesh.ReplaceAll(generatedMeshes);
        ringMultiMesh.Update();

#if UNITY_EDITOR == true
        ringMultiMesh.HideInEditor();
#endif
    }
Пример #4
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();
    }
Пример #5
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 void LateUpdate()
    {
        if (starfieldGameObject == null)
        {
            starfieldGameObject = SGT_Helper.CreateGameObject("Starfield", gameObject);
        }
        if (starfieldMultiMesh == null)
        {
            starfieldMultiMesh = new SGT_MultiMesh();
        }
        if (starfieldCamera == null)
        {
            StarfieldCamera = SGT_Helper.FindCamera();                                          // NOTE: Assigning property
        }
        SGT_Helper.SetParent(starfieldGameObject, gameObject);
        SGT_Helper.SetLayer(starfieldGameObject, gameObject.layer);
        SGT_Helper.SetTag(starfieldGameObject, gameObject.tag);

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

        UpdateMaterial();
        UpdateShader();
        UpdateBackground();

        starfieldMultiMesh.GameObject           = starfieldGameObject;
        starfieldMultiMesh.HasMeshRenderers     = true;
        starfieldMultiMesh.MeshRenderersEnabled = true;
        starfieldMultiMesh.SharedMaterial       = starfieldMaterial;
        starfieldMultiMesh.ReplaceAll(meshes);
        starfieldMultiMesh.Update();

#if UNITY_EDITOR == true
        starfieldMultiMesh.HideInEditor();
#endif
    }
Пример #8
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
    }
Пример #9
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
    }
Пример #10
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
    }
Пример #11
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
    }