Пример #1
0
    /*
     * Called by PlayerKnifeController prior to beginning the warp to set up variables
     */
    public void Setup(float _fov, Vector3 _startPos, KnifeController _knifeController, Vector3 _camRelativePos, Quaternion _startRot, Quaternion _endRot, bool _gravityShift, FibreOpticController _fibreController)
    {
        startPos           = _startPos;
        startRot           = _startRot;
        transform.position = startPos;
        transform.rotation = startRot;

        knifeController = _knifeController;
        endRot          = _endRot;
        camRelativePos  = endRot * _camRelativePos;
        gravityShift    = _gravityShift;

        cam.fieldOfView     = _fov;
        rb.detectCollisions = true;
        Blackout(false);

        if (_fibreController)
        {
            fibreOpticController = _fibreController;
            fibreOpticWarp       = true;

            fibreOpticController.WarpKnife(knifeController);
        }

        CalculateDuration();
    }
Пример #2
0
 /*
  * Disables the camera and collisions etc
  */
 private void Disable()
 {
     blackoutCamera.enabled = false;
     cam.enabled            = false;
     rb.detectCollisions    = false;
     fibreOpticWarp         = false;
     fibreOpticController   = null;
 }
Пример #3
0
    /*
     * Handles start of fibre optic warp and triggers animation transition of knife along bezier
     */
    void OnFibreOpticWarp(object sender, object args)
    {
        FibreOpticController fibreOpticController = (FibreOpticController)args;

        if (fibreOpticController != this)
        {
            return;
        }

        if (!IsConnected())
        {
            Debug.LogError("Not connected to other FibreOpticController");
            return;
        }
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        FibreOpticController fibre = target as FibreOpticController;

        // Handle button to create mesh
        if (GUILayout.Button("Create Bezier Mesh"))
        {
            fibre.CreateBezierMesh();
        }

        //// create wireframe preview of fibre mesh
        //if (GUILayout.Button("Wireframe Bezier Mesh"))
        //{
        //    testVertices = FibreOpticMeshCreator.GetBezierMeshVertices(fibre.GetBezierPoints(), fibre.GetSegmentCount());
        //}
    }
    private void OnSceneGUI()
    {
        FibreOpticController fibre = target as FibreOpticController;

        Info <Vector3, Vector3, Vector3, Vector3> bezierPoints = fibre.GetBezierPoints();

        if (bezierPoints == null)
        {
            return;
        }

        Transform fibreTransform = fibre.transform;

        Vector3 point1   = bezierPoints.arg0;
        Vector3 point2   = bezierPoints.arg3;
        Vector3 tangent1 = bezierPoints.arg1;
        Vector3 tangent2 = bezierPoints.arg2;

        Handles.DrawBezier(point1, point2, tangent1, tangent2, Color.red, null, 1f);
        Handles.color = Color.green;
        Handles.DrawLine(point1, tangent1);

        Quaternion handleRotation = Tools.pivotRotation == PivotRotation.Local ?
                                    fibreTransform.rotation : Quaternion.identity;

        EditorGUI.BeginChangeCheck();
        tangent1 = Handles.DoPositionHandle(tangent1, handleRotation);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(fibre, "Move Point");
            EditorUtility.SetDirty(fibre);
            fibre.bezierTargetPosition = fibreTransform.InverseTransformPoint(tangent1);
        }

        testVertices = FibreOpticMeshCreator.GetBezierMeshVertices(fibre.GetBezierPoints());
        if (testVertices != null)
        {
            DrawWireframeBezierMesh();
        }
    }
Пример #6
0
    /*
     * Triggers FibreOptic warp
     */
    void OnFibreOpticWarp(object sender, object args)
    {
        if (knife == null)
        {
            return;
        }

        if (currentWarps > 0)
        {
            // perform forced fibreoptic warp
            FibreOpticController fibreOpticController = (FibreOpticController)args;

            playerMotor.WarpToKnife(false, knifeController, fibreOpticController);
        }
        else
        {
            // shouldn't trigger, should always have warps available if knife has been thrown
            Debug.LogError("FibreOpticWarp should not happen if no warps are available");
            // return knife
            ReturnKnife();
        }
    }
Пример #7
0
    /*
     * Warps the player to the current knife position, inheriting velocity and moving gravity vectors if required
     */
    public void WarpToKnife(bool _shiftGravity, KnifeController _knifeController, FibreOpticController _fibreOpticController = null)
    {
        if (frozen)
        {
            return;
        }

        // record starting position and rotation for transitionCamera
        Vector3    camStartPos    = cam.transform.position;
        Quaternion camStartRot    = cam.transform.rotation;
        Vector3    relativeFacing = cam.transform.forward;

        Vector3 newGravDirection = _knifeController.GetGravVector();

        bool fibreOpticWarp = _fibreOpticController != null;

        // Shift gravity if the difference between current gravity and surface normal is
        // above the threshold defined by warpGravShiftAngle
        float surfaceDiffAngle = Vector3.Angle(-transform.up, newGravDirection);
        bool  gravityShift     = (_shiftGravity && surfaceDiffAngle > warpGravShiftAngle && newGravDirection != Vector3.zero);

        if (gravityShift)
        {
            this.PostNotification(GravityWarpNotification, _knifeController.GetStuckObject());
        }
        else
        {
            this.PostNotification(WarpNotification);
        }

        // rotate to face new direction at end of warp.
        // needed for gravity and fibreoptic warps
        if (gravityShift)
        {
            RotateToDirection(newGravDirection, relativeFacing);
        }
        else if (fibreOpticWarp)
        {
            RotateToDirection(currentGravVector, _fibreOpticController.GetExitDirection(), true);
        }

        // Determine transitionCamera end rotation
        Quaternion camEndRot = (gravityShift) ? transform.rotation : camStartRot;

        // Setup transitionCamera
        transCamController.Setup(cam.fieldOfView, camStartPos, _knifeController, cameraRelativePos, camStartRot, camEndRot, gravityShift, _fibreOpticController);

        cam.enabled = false;
        Freeze();

        // Begin warp transition
        transCamController.StartTransition();

        if (gravityShift)
        {
            GlobalGravityControl.TransitionGravity(newGravDirection, transCamController.GetDuration());

            // Begin gravity shift countdown coroutine
            if (gravShiftTimerCoroutine != null)
            {
                StopCoroutine(gravShiftTimerCoroutine);
            }

            gravShiftTimerCoroutine = StartCoroutine("GravShiftCountdown");
        }
    }
Пример #8
0
    /*
     * Sticks knife into surface when colliding with an object
     */
    public virtual void StickToSurface(Vector3 _position, Vector3 _normal, GameObject _other, bool _cancelNotifications = false)
    {
        // disable rigidbody
        rb.isKinematic = true;
        dontGoThroughThings.enabled = false;
        stuckInSurface = true;

        // align knife position with collision position
        transform.position = _position;
        transform.rotation = Quaternion.FromToRotation(Vector3.up, _normal);

        // stick knife out of surface at collision point
        rb.velocity = Vector3.zero;

        // parent knife to other gameobject (to handle moving objects)
        transform.SetParent(_other.transform);
        objectStuck = _other;

        if (_cancelNotifications)
        {
            trailRenderer.enabled = false;
            return;
        }

        KnifeInteractionTrigger knifeTrigger = objectStuck.GetComponent <KnifeInteractionTrigger>();

        if (knifeTrigger != null)
        {
            // disable autoWarp
            autoWarp = false;
            // attach knife to interactable object
            knifeTrigger.AttachKnife();
        }

        GravityPanel tempGravPanel = objectStuck.GetComponent <GravityPanel>();

        if (tempGravPanel != null)
        {
            // Prepare to shift gravity if warping to GravityPanel
            gravPanel       = tempGravPanel;
            gravShiftVector = gravPanel.GetGravityVector();

            if (gravShiftVector == Vector3.zero)
            {
                gravShiftVector = -_normal;
            }
        }

        Controller controller = objectStuck.GetComponent <Controller>();

        if (controller != null)
        {
            //autoWarp = true;
            // TODO: store controller for switching after warp
            this.PostNotification(ReturnKnifeNotification);
            this.PostNotification(Controller.ControllerChangeNotification, controller);
            return;
        }

        FibreOpticController fibreController = objectStuck.GetComponent <FibreOpticController>();

        if (fibreController != null)
        {
            // Activate fibre optic warp
            this.PostNotification(FibreOpticWarpNotification, fibreController);
            return;
        }

        // activate knife marker ui
        Info <Transform, bool> info = new Info <Transform, bool>(transform, gravPanel != null);

        this.PostNotification(ShowKnifeMarkerNotification, info);
    }
Пример #9
0
 // Used to make sure that both ends are connected properly
 public void SetOtherEndController(FibreOpticController _other)
 {
     otherEndFibreOpticController = _other;
 }