コード例 #1
0
    public bool Update(float deltaTime, ref AxisState axis)
    {
        if (!string.IsNullOrEmpty(name))
        {
            try { inputValue = CinemachineCore.GetInputAxis(name); }
            catch (ArgumentException) {}
            //catch (ArgumentException e) { Debug.LogError(e.ToString()); }
        }

        float input = inputValue * multiplier;

        if (deltaTime < Epsilon)
        {
            mCurrentSpeed = 0;
        }
        else
        {
            float speed    = input / deltaTime;
            float dampTime = Mathf.Abs(speed) < Mathf.Abs(mCurrentSpeed) ? decelTime : accelTime;
            speed         = mCurrentSpeed + Damper.Damp(speed - mCurrentSpeed, dampTime, deltaTime);
            mCurrentSpeed = speed;

            // Decelerate to the end points of the range if not wrapping
            float range = axis.m_MaxValue - axis.m_MinValue;
            if (!axis.m_Wrap && decelTime > Epsilon && range > Epsilon)
            {
                float v0 = ClampValue(ref axis, axis.Value);
                float v  = ClampValue(ref axis, v0 + speed * deltaTime);
                float d  = (speed > 0) ? axis.m_MaxValue - v : v - axis.m_MinValue;
                if (d < (0.1f * range) && Mathf.Abs(speed) > Epsilon)
                {
                    speed = Damper.Damp(v - v0, decelTime, deltaTime) / deltaTime;
                }
            }
            input = speed * deltaTime;
        }

        axis.Value = ClampValue(ref axis, axis.Value + input);
        return(Mathf.Abs(inputValue) > Epsilon);
    }
コード例 #2
0
 public void Init()
 {
     this.thisCamera   = CinemachineCore.get_Instance().GetActiveBrain(0).get_OutputCamera();
     this.housingMgr   = Singleton <Housing> .Instance;
     this.CamDat.Fov   = 23f;
     this.CamReset.Fov = 23f;
     ((CameraState) ref this.m_State).set_Lens(this.lens);
     this.isDrags = new bool[this.CONFIG_SIZE];
     for (int index = 0; index < this.isDrags.Length; ++index)
     {
         this.isDrags[index] = false;
     }
     if (this.isInit)
     {
         return;
     }
     this.isButtons    = new bool[this.CONFIG_SIZE];
     this.targetRender = (Renderer)((Component)this.lookAtTarget).GetComponent <Renderer>();
     this.TargetSet(this.lookAtTarget, true);
     this.isOutsideTargetTex = true;
     this.isConfigTargetTex  = true;
     this.input  = Singleton <Input> .Instance;
     this.isInit = true;
 }
コード例 #3
0
        public void AutoAdjustOffset(CinemachineVirtualCameraBase vcam,
                                     CameraState state, float deltaTime, ref Vector3 offset)
        {
            //在特定触发器的状态下不调整
            if (m_IsTrigger)
            {
                Vector3 targetOffset = m_TriggerTarget - offset;
                offset += Damper.Damp(targetOffset, m_AdjustDampingX, deltaTime);
                return;
            }

            if (IsSelectAutoAdjustMode(AutoAdjustMode.Distance))
            {
                if (m_AdjustNearFarRange.x >= m_AdjustNearFarRange.y)
                {
                    return;
                }
                Quaternion inverseRawOrientation = Quaternion.Inverse(state.RawOrientation);
                float      dis = (inverseRawOrientation * (vcam.Follow.position - state.FinalPosition)).z;
                if (dis < m_AdjustNearFarRange.x)
                {
                    dis       = dis - m_AdjustNearFarRange.x;
                    offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime);
                }
                else if (dis > m_AdjustNearFarRange.y)
                {
                    dis       = dis - m_AdjustNearFarRange.y;
                    offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime);
                }
                else
                {
                    dis       = -offset.z;
                    offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime);
                }
            }

            if (IsSelectAutoAdjustMode(AutoAdjustMode.Turn))
            {
                if (m_TurnAxisName == "" || m_AdjustRangeX.x >= m_AdjustRangeX.y)
                {
                    return;
                }
                float value = CinemachineCore.GetInputAxis(m_TurnAxisName);
                if (value < 0)
                {
                    float target       = Mathf.Lerp(m_AdjustRangeX.y, m_AdjustRangeX.x, -value);
                    float targetOffset = target - offset.x;
                    offset.x += Damper.Damp(targetOffset, m_AdjustDampingX, deltaTime);
                }
                else if (value > 0)
                {
                    float target       = Mathf.Lerp(m_AdjustRangeX.y, m_AdjustRangeX.z, value);
                    float targetOffset = target - offset.x;
                    offset.x += Damper.Damp(targetOffset, m_AdjustDampingX, deltaTime);
                }
                else
                {
                    float targetOffset = m_AdjustRangeX.y - offset.x;
                    offset.x += Damper.Damp(targetOffset, m_AdjustDampingX, deltaTime);
                }
            }

            if (IsSelectAutoAdjustMode(AutoAdjustMode.RunFar))
            {
                CinemachineCore.ActorData actor  = CinemachineCore.Instance.GetActorData();
                Quaternion inverseRawOrientation = Quaternion.Inverse(state.RawOrientation);
                Vector3    moveDirCamera         = inverseRawOrientation * actor.MoveDirection;
                if (Mathf.Abs(moveDirCamera.x) > 0.5f || moveDirCamera.z < 0.0f)
                {
                    float dis = (inverseRawOrientation * (vcam.Follow.position - state.FinalPosition)).z;
                    dis       = dis - m_AdjustMinDic;
                    offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime);
                }
                else
                {
                    float dis = -offset.z;
                    offset.z += Damper.Damp(dis, m_AdjustDampingZ, deltaTime);
                }
            }
        }
コード例 #4
0
    private void Update()
    {
        Vector3 moveInput = Vector3.ClampMagnitude(new Vector3(Input.GetAxisRaw(horizontalMoveInput), 0, Input.GetAxisRaw(verticalMoveInput)), 1);
        Vector3 moveDir   = transform.right * moveInput.x + transform.forward * moveInput.z;

        transform.Rotate(Vector3.up * CinemachineCore.GetInputAxis("Mouse X"));
        character.Move(moveDir.normalized);

        RaycastHit hit;

        if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward), out hit, pickUpRange) && hit.transform.GetComponent <Rigidbody>())
        {
            if (CrosshairAnimator.Instance.animator.GetBool("Grabbing") == false)
            {
                CrosshairAnimator.Instance.animator.Play("hand_twitch");
            }
        }
        else
        {
            if (CrosshairAnimator.Instance.animator.GetBool("Grabbing") == false)
            {
                CrosshairAnimator.Instance.animator.Play("default");
            }
        }

        // Interact
        if (Input.GetButtonDown(interactInput))
        {
            if (!heldobj && hit.transform.GetComponent <Rigidbody>())
            {
                PickupObject(hit.transform.gameObject);
            }
            else
            {
                if (heldobj)
                {
                    DropObject();
                }
            }
        }

        if (heldobj)
        {
            //if (Vector3.Distance(heldobj.transform.position, holdParent.position) > 2.5f) {
            //Vector3 moveDirection = (holdParent.position - heldobj.transform.position);
            //heldobj.GetComponent<Rigidbody>().AddForce(moveDirection * moveForce);
            //}
        }

        // Jump
        if (Input.GetButtonDown(jumpInput))
        {
            character.Jump();
        }

        // Toggle Flashlight
        if (Input.GetButtonDown(flashlightInput))
        {
            flashlight.SetActive(!flashlight.activeInHierarchy);
        }

        // Interact
        if (Input.GetButtonDown(interactInput))
        {
            character.Interact();
        }
    }