コード例 #1
0
    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);
            }
        }
    }
コード例 #2
0
    private void UpdateCloudsOffset()
    {
        if (cloudsGameObject != null && planetObserver != null)
        {
            var observerDirection = transform.InverseTransformPoint(planetObserver.transform.position).normalized;
            //var observerDirection = (observerPosition - transform.position).normalized;

            SGT_Helper.SetLocalPosition(cloudsGameObject.transform, observerDirection * cloudsOffset);
        }
    }
コード例 #3
0
    public void Update()
    {
        if (Application.isPlaying == true && GUIUtility.hotControl == 0)
        {
            if (Input.GetKey(KeyCode.Mouse0) == true)
            {
                var x = SGT_Input.DragY * -rotationSpeed;
                var y = SGT_Input.DragX * rotationSpeed;

                targetRotation *= Quaternion.Euler(x, y, 0.0f);
            }

            if (rotationRoll == true)
            {
                if (Input.GetKey(KeyCode.Mouse1) == true)
                {
                    var z = SGT_Input.DragRoll;

                    targetRotation *= Quaternion.Euler(0.0f, 0.0f, z);
                }
            }

            targetDistance -= SGT_Input.Zoom * (1.0f + targetDistance - distanceMin) * distanceSpeed;
        }

        targetDistance = Mathf.Clamp(targetDistance, distanceMin, distanceMax);

        var currentDistance = transform.localPosition.magnitude;
        var currentRotation = transform.localRotation;

        if (Application.isPlaying == true)
        {
            var rotationDampenFactor = SGT_Helper.DampenFactor(rotationDampening, Time.deltaTime);
            var distanceDampenFactor = SGT_Helper.DampenFactor(distanceDampening, Time.deltaTime);

            currentRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationDampenFactor);
            currentDistance = Mathf.Lerp(currentDistance, targetDistance, distanceDampenFactor);
        }
        else
        {
            currentRotation = targetRotation;
            currentDistance = targetDistance;
        }

        SGT_Helper.SetLocalRotation(transform, currentRotation);
        SGT_Helper.SetLocalPosition(transform, currentRotation * new Vector3(0.0f, 0.0f, -currentDistance));
    }
コード例 #4
0
    private void UpdateCoronaOffset()
    {
        if (coronaObserver != null && coronaGameObject != null)
        {
            var observerPosition  = coronaObserver.transform.position;
            var observerDirection = (observerPosition - coronaGameObject.transform.position).normalized;

            SGT_Helper.SetLocalPosition(coronaGameObject.transform, observerDirection * coronaOffset);

            if (meshAlignment == Alignment.Billboard)
            {
                if (coronaGameObject.transform.forward != observerDirection)
                {
                    coronaGameObject.transform.forward = observerDirection;
                }
            }
        }
    }
コード例 #5
0
    public void Update()
    {
        if (orbit == true)
        {
            if (Application.isPlaying == true)
            {
                orbitAngle += SGT_Helper.RadiansPerSecond(orbitPeriod) * Time.deltaTime;
            }

            var targetPosition = SGT_Helper.PolarToCartesian(new Vector2(orbitAngle, 0.0f)) * orbitDistance; targetPosition.x *= (1.0f - orbitOblateness);

            SGT_Helper.SetLocalPosition(transform, targetPosition);
        }

        if (rotation == true)
        {
            if (Application.isPlaying == true)
            {
                transform.Rotate(rotationAxis, SGT_Helper.DegreesPerSecond(rotationPeriod) * Time.deltaTime, Space.Self);
            }
        }
    }
コード例 #6
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
    }