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));
        }
    }
Beispiel #2
0
    public void FixedUpdate()
    {
        if (thrusterPhysics == true)
        {
            if (thrusterPhysicsRigidbody == null)
            {
                thrusterPhysicsRigidbody = SGT_Helper.GetComponentUpwards <Rigidbody>(gameObject);
            }

            if (thrusterPhysicsRigidbody != null && targetThrusterThrottle != 0.0f)
            {
                var force = -transform.forward * thrusterPhysicsForce * targetThrusterThrottle * Time.fixedDeltaTime;

                switch (thrusterPhysicsForceType)
                {
                case ForceType.AddForce: thrusterPhysicsRigidbody.AddForce(force, thrusterPhysicsForceMode); break;

                case ForceType.AddForceAtPosition: thrusterPhysicsRigidbody.AddForceAtPosition(force, transform.position, thrusterPhysicsForceMode); break;

                case ForceType.AddRelativeForce: thrusterPhysicsRigidbody.AddRelativeForce(force, thrusterPhysicsForceMode); break;
                }
            }
        }
    }
Beispiel #3
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
    }