Exemplo n.º 1
0
    private Vector3 SurfacePositionAtPoint(Vector3 centre, Vector3 point)
    {
        var vector    = point - centre;
        var vectorN   = vector.normalized;
        var tgtRadius = SGT_SurfaceHelper.FindRadius(snapSurface, point) + snapPositionHeight;

        return(centre + vectorN * tgtRadius);
    }
    public override void OnInspector()
    {
        SGT_EditorGUI.Separator();

        SGT_EditorGUI.BeginGroup("Snap");
        {
            Target.SnapSurface = SGT_EditorGUI.ObjectField("Surface", "The surface this object will be snapped to. Note: This GameObject must contain either the Planet or Star component.", Target.SnapSurface, true);

            if (Target.SnapSurface != null && SGT_SurfaceHelper.ContainsSurface(Target.SnapSurface) == false)
            {
                SGT_EditorGUI.HelpBox("The GameObject you have chosen above doesn't contain a surface (Planet or Star component).", MessageType.Warning);
            }

            SGT_EditorGUI.Separator();

            Target.SnapPosition = SGT_EditorGUI.BeginToggleGroup("Position", null, Target.SnapPosition);
            {
                Target.SnapPositionHeight = SGT_EditorGUI.FloatField("Height", "The height about the surface the object will be snapped to.", Target.SnapPositionHeight);
            }
            SGT_EditorGUI.EndToggleGroup();

            if (Target.SnapRotation == SGT_SnapToSurface.RotationSnap.AlignToNormal)
            {
                SGT_EditorGUI.MarkNextFieldAsBold();
                SGT_EditorGUI.Separator();
            }

            Target.SnapRotation = (SGT_SnapToSurface.RotationSnap)SGT_EditorGUI.EnumField("Rotation", "Should the rotation be snapped to the surface?", Target.SnapRotation);

            SGT_EditorGUI.BeginIndent(Target.SnapRotation == SGT_SnapToSurface.RotationSnap.AlignToNormal);
            {
                Target.SnapRotationScanDistance = SGT_EditorGUI.FloatField("Scan Distance", "The amount of units ahead the samples used to find the surface normal will extend.", Target.SnapRotationScanDistance);
            }
            SGT_EditorGUI.EndIndent();
        }
        SGT_EditorGUI.EndGroup();

        SGT_EditorGUI.Separator();
    }
Exemplo n.º 3
0
    public void Update()
    {
        if (GetComponent <Rigidbody>() != null)
        {
            translationVel += GetComponent <Rigidbody>().velocity;
            GetComponent <Rigidbody>().velocity        = Vector3.zero;
            GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
        }

        // Translation
        var moveMul = Input.GetKey(KeyCode.LeftShift) == true ? shiftSpeedMul : 1.0f;

        translationTgt.x = SGT_Input.MoveX * moveSpeed * moveMul;
        translationTgt.z = SGT_Input.MoveY * moveSpeed * moveMul;

        moveSpeed = Mathf.Max(0.0f, moveSpeed + SGT_Input.Zoom * moveSpeed * 2.0f);

        if (translationCur != translationTgt)
        {
            translationCur.x = Mathf.SmoothDamp(translationCur.x, translationTgt.x, ref translationVel.x, moveSmooth, float.PositiveInfinity, SGT_Helper.DeltaTime);
            translationCur.z = Mathf.SmoothDamp(translationCur.z, translationTgt.z, ref translationVel.z, moveSmooth, float.PositiveInfinity, SGT_Helper.DeltaTime);
        }

        var translation = translationCur * SGT_Helper.DeltaTime;

        if (translation != Vector3.zero)
        {
            switch (movePlane)
            {
            case MovementPlane.LocalXZ: transform.Translate(translation.x, 0.0f, translation.z); break;

            case MovementPlane.LocalXY: transform.Translate(translation.x, translation.z, 0.0f); break;
            }
        }

        // Prevent the camera from entering planets/stars
        if (repelBodies == true)
        {
            var currentPosition = transform.position;

            var planets = SGT_CachedFind <SGT_Planet> .All(1.0f);

            foreach (var planet in planets)
            {
                if (planet != null)
                {
                    var radius = planet.SurfaceRadiusAtPoint(currentPosition) * SGT_SurfaceHelper.FindDisplacement(planet.gameObject, currentPosition);

                    RepelByRadius(planet.transform.position, radius * planet.UniformScale);
                }
            }

            var stars = SGT_CachedFind <SGT_Star> .All(1.0f);

            foreach (var star in stars)
            {
                if (star != null)
                {
                    var radius = star.SurfaceRadiusAtPoint(currentPosition) * SGT_SurfaceHelper.FindDisplacement(star.gameObject, currentPosition);

                    RepelByRadius(star.transform.position, radius * star.UniformScale);
                }
            }
        }
    }