private void UpdateBackground() { if (starfieldGameObject != null) { if (starfieldInBackground == true) { if (starfieldCamera != null) { // Stretch to camera's far view frustum if (distributionRadius != 0.0f) { var scale = SGT_Helper.NewVector3(starfieldCamera.farClipPlane / distributionRadius) * 0.9f; SGT_Helper.SetLocalScale(starfieldGameObject.transform, scale); } // Centre to main camera SGT_Helper.SetPosition(starfieldGameObject.transform, starfieldCamera.transform.position); } } else { SGT_Helper.SetLocalPosition(starfieldGameObject.transform, Vector3.zero); SGT_Helper.SetLocalScale(starfieldGameObject.transform, Vector3.one); } } }
public void LateUpdate() { Validate(); if (dustAutoRegen == true) { Regenerate(); } SGT_Helper.SetLocalScale(dust.transform, dustRadius * 2.0f); #if UNITY_EDITOR == true dustMesh.HideInEditor(); #endif }
private void StepScale() { if (parent == null) { parent = SGT_Helper.GetComponentUpwards <SGT_DebrisSpawner>(gameObject); } if (parent != null) { var position = SGT_Helper.GetPosition(parent.DebrisCentre); var distance = (position - transform.position).magnitude; var scaleMul = 1.0f - SGT_Helper.RemapClamped(parent.DebrisContainerInnerRadius, parent.DebrisContainerRadius, distance, 0.0f, 1.0f); SGT_Helper.SetLocalScale(transform, SGT_Helper.NewVector3(scale * scaleMul)); } }
private void UpdateTransform() { //var starObserverPosition = SGT_Helper.GetPosition(gasGiantObserver); //var starObserverDirection = (starObserverPosition - atmosphereGameObject.transform.position).normalized; var atmosphereScale = new Vector3(gasGiantEquatorialRadius, GasGiantPolarRadius, gasGiantEquatorialRadius); SGT_Helper.SetLocalScale(oblatenessGameObject.transform, atmosphereScale); // TODO: Make this work /* * if (atmosphereGameObject.transform.up != starObserverDirection) * { * atmosphereGameObject.transform.up = starObserverDirection; * * SGT_Helper.UpdateNonOrthogonalTransform(atmosphereGameObject.transform); * } */ }
private void UpdateTransform() { var oblatenessScale = new Vector3(1.0f, 1.0f - surfaceOblateness, 1.0f); var surfaceScale = SGT_Helper.NewVector3(SurfaceEquatorialRadius); var atmosphereScale = SGT_Helper.NewVector3(AtmosphereEquatorialRadius); var starObserverPosition = SGT_Helper.GetPosition(starObserver); var starObserverDirection = (starObserverPosition - atmosphereGameObject.transform.position).normalized; SGT_Helper.SetLocalScale(oblatenessGameObject.transform, oblatenessScale); SGT_Helper.SetLocalScale(surfaceGameObject.transform, surfaceScale); SGT_Helper.SetLocalScale(atmosphereGameObject.transform, atmosphereScale); if (atmosphereGameObject.transform.up != starObserverDirection) { atmosphereGameObject.transform.up = starObserverDirection; SGT_Helper.UpdateNonOrthogonalTransform(atmosphereGameObject.transform); } }
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 (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 }
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 }
public void Update() { if (surfaceGameObject == null) { var fillSurfaceGameObject = new SGT_FillGameObject(); SendMessage("FillSurfaceGameObject", fillSurfaceGameObject, SendMessageOptions.DontRequireReceiver); surfaceGameObject = fillSurfaceGameObject.GameObject; } if (activeCollider != null) { if (activeGameObject == null) { activeGameObject = SGT_Helper.CreateGameObject("Collider (Active)", gameObject); } activeCollider.GameObject = activeGameObject; activeCollider.Update(); } else { if (activeGameObject != null) { SGT_Helper.DestroyGameObject(activeGameObject); } } if (nextCollider != null) { if (nextGameObject == null) { nextGameObject = SGT_Helper.CreateGameObject("Collider (Currently Building)", gameObject); } nextCollider.GameObject = nextGameObject; nextCollider.Update(); } else { if (nextGameObject != null) { SGT_Helper.DestroyGameObject(nextGameObject); } } if (activeGameObject != null) { SGT_Helper.SetLocalScale(activeGameObject.transform, surfaceGameObject.transform.localScale); } if (nextGameObject != null) { SGT_Helper.SetLocalScale(nextGameObject.transform, surfaceGameObject.transform.localScale); } #if UNITY_EDITOR == true if (Application.isEditor == true) { SGT_Helper.HideGameObject(activeGameObject); SGT_Helper.HideGameObject(nextGameObject); } #endif }