示例#1
0
    public static FrameInput ToFrameInput(this Dictionary <InputReferences, InputEvents> inputs, sbyte?selectedOption)
    {
        Fix64 horizontalAxisRaw    = 0;
        Fix64 verticalAxisRaw      = 0;
        NetworkButtonPress buttons = NetworkButtonPress.None;

        foreach (KeyValuePair <InputReferences, InputEvents> pair in inputs)
        {
            InputReferences inputReference = pair.Key;
            InputEvents     inputEvent     = pair.Value;

            if (inputReference.inputType == InputType.HorizontalAxis)
            {
                horizontalAxisRaw = inputEvent.axisRaw;
            }
            else if (inputReference.inputType == InputType.VerticalAxis)
            {
                verticalAxisRaw = inputEvent.axisRaw;
            }
            else if (inputReference.inputType == InputType.Button && inputEvent.button)
            {
                NetworkButtonPress buttonPress = inputReference.engineRelatedButton.ToNetworkButtonPress();
                if (UFE.config.networkOptions.networkMessageSize == NetworkMessageSize.Size8Bits)
                {
                    buttonPress &= (NetworkButtonPress)((sbyte)(-1));
                }
                else if (UFE.config.networkOptions.networkMessageSize == NetworkMessageSize.Size16Bits)
                {
                    buttonPress &= (NetworkButtonPress)((short)(-1));
                }

                buttons |= buttonPress;

                //buttons |= inputReference.engineRelatedButton.ToNetworkButtonPress();
            }
        }

        if (UFE.config.inputOptions.forceDigitalInput)
        {
            return(new FrameInput(
                       FPMath.Sign(horizontalAxisRaw),
                       FPMath.Sign(verticalAxisRaw),
                       buttons,
                       selectedOption == null ? FrameInput.NullSelectedOption : selectedOption.Value
                       ));
        }
        else
        {
            return(new FrameInput(
                       horizontalAxisRaw,
                       verticalAxisRaw,
                       buttons,
                       selectedOption == null ? FrameInput.NullSelectedOption : selectedOption.Value
                       ));
        }
    }
    /// <summary>
    /// 改变朝向,改变forward的朝向跟摄像机的朝向一样
    /// </summary>
    /// <param name="forward"></param>
    public void ChangeAvatarForward(FPVector toForward)
    {
        JoystickAngle = 90;
        if (AvatarForm == E_AvatarForm.PERSON_STATE)
        {
            _ufpTransformChildObj.ChangeForward(toForward);
            return;
        }

        RaycastHit _groundHit;

        _characterMotionObj.RayGroundInfo(out _groundHit);
        FPVector _fpNormal = _ufpTransformChildObj.ChangeVec3ToTSVec(_groundHit.normal);

        if (_groundHit.normal == Vector3.up)
        {
            _ufpTransformChildObj.ChangeForward(toForward);

            // _childObj.forward = toForward;
            JoystickAngle = 90;
            return;
        }
        else
        {
            FPVector left       = FPVector.Cross(toForward, _fpNormal); //切线
            FPVector newForward = FPVector.Cross(_fpNormal, left);

            if (_fpNormal == FPVector.zero)
            {
                Debug.Log("forward:::" + toForward);
                return;
            }
            FPQuaternion  newRotation      = FPQuaternion.LookRotation(newForward, _fpNormal);
            U_FPTransform ComMoveTransform = ComMoveFollowObj.GetFPTransform();
            FPQuaternion  comObject        = new FPQuaternion(ComMoveTransform.rotation.x, ComMoveTransform.rotation.y,
                                                              ComMoveTransform.rotation.z, ComMoveTransform.rotation.w);

            // ComMoveFollowObj.transform.rotation = newRotation;
            ComMoveTransform.SetRotation(newRotation);

            FPVector comForward   = ComMoveTransform.forward;
            FPVector childForward = _ufpTransformChildObj.forward;
            FP       DragAngle    = FPVector.Angle(comForward, childForward);
            DragAngle = FPMath.Sign(FPVector.Cross(childForward, comForward).y) * DragAngle;
            ChangeAvaterForward(DragAngle);          //改变对象的旋转数值
            ComMoveTransform.SetRotation(comObject); //恢复摄像机原来的rotation数值
        }
    }
示例#3
0
    private static void DefaultMoveCursorAction(
        this UFEScreen screen,
        Fix64 horizontalAxis,
        Fix64 verticalAxis,
        bool horizontalAxisDown,
        bool verticalAxisDown,
        bool confirmButtonDown,
        bool cancelButtonDown,
        AudioClip sound
        )
    {
        bool axisDown = horizontalAxisDown || verticalAxisDown;

        //---------------------------------------------------------------------------------------------------------
        // Retrieve the current selected GameObject.
        // If no GameObject is selected and the player press any button, select the first GameObject at the screen.
        //---------------------------------------------------------------------------------------------------------
        GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;

        if (currentGameObject == null && axisDown || confirmButtonDown || cancelButtonDown)
        {
            currentGameObject = screen.FindFirstSelectableGameObject();
        }

        //---------------------------------------------------------------------------------------------------------
        // Check if the current Selectable Object is a Slider
        //---------------------------------------------------------------------------------------------------------
        Slider slider = currentGameObject != null?currentGameObject.GetComponent <Slider>() : null;

        //-----------------------------------------------------------------------------------------------------
        // If the current Selectable Object is a Slider, check if the user has pressed a button
        // in the same direction (horizontal / vertical) than the slider, change the slider value.
        //
        // If the current Selectable Object is not an Slider or if the user hasn't pressed a button
        // in the same direction (horizontal / vertical) than the slider, move the cursor
        //-----------------------------------------------------------------------------------------------------
        if (slider != null)
        {
            if (horizontalAxisDown && slider.direction == Slider.Direction.LeftToRight)
            {
                if (slider.wholeNumbers)
                {
                    slider.value += FPMath.Sign(horizontalAxis);
                }
                else
                {
                    slider.normalizedValue += FPMath.Sign(horizontalAxis) * UFEScreenExtensions.NormalizedSliderSpeed;
                }
            }
            else if (horizontalAxisDown && slider.direction == Slider.Direction.RightToLeft)
            {
                if (slider.wholeNumbers)
                {
                    slider.value -= FPMath.Sign(horizontalAxis);
                }
                else
                {
                    slider.normalizedValue -= FPMath.Sign(horizontalAxis) * UFEScreenExtensions.NormalizedSliderSpeed;
                }
            }
            else if (verticalAxisDown && slider.direction == Slider.Direction.BottomToTop)
            {
                if (slider.wholeNumbers)
                {
                    slider.value += FPMath.Sign(verticalAxis);
                }
                else
                {
                    slider.normalizedValue += FPMath.Sign(verticalAxis) * UFEScreenExtensions.NormalizedSliderSpeed;
                }
            }
            else if (verticalAxisDown && slider.direction == Slider.Direction.TopToBottom)
            {
                if (slider.wholeNumbers)
                {
                    slider.value -= FPMath.Sign(verticalAxis);
                }
                else
                {
                    slider.normalizedValue -= FPMath.Sign(verticalAxis) * UFEScreenExtensions.NormalizedSliderSpeed;
                }
            }
            else if (axisDown)
            {
                screen.MoveCursor(new Vector3((float)horizontalAxis, (float)verticalAxis), sound);
            }
        }
        else if (axisDown)
        {
            screen.MoveCursor(new Vector3((float)horizontalAxis, (float)verticalAxis), sound);
        }
    }
示例#4
0
    public void Update()
    {
        if (Target == null)
        {
            return;
        }
        //  ChangeDirectionByDragging();
        //if (_dragging && _directorToLeft && !_bTouchMouse)  //左遥感
        //{
        //    _rockerControl = ComMoveController.RockerControl.LeftControl;
        //    _ufpTransform.RotateAround(_playerTransformObj.position, FPVector.up, FrameSyncManager.DeltaTime * RockerSpeed);
        //    _ufpTransform.UpdateAllData();
        //    Debug.Log("_ufpTransform:::" + _ufpTransform.forward.ToVector());
        //    //transform.RotateAround(_childObj.position, Vector3.up, Time.deltaTime * RockerSpeed);
        //    return;
        //}
        //else if (_dragging && _directorToRight && !_bTouchMouse) //右遥感
        //{
        //    _rockerControl = ComMoveController.RockerControl.RightControl;
        //    _ufpTransform.RotateAround(_playerTransformObj.position, FPVector.up, FrameSyncManager.DeltaTime * -RockerSpeed);
        //    _ufpTransform.UpdateAllData();

        //    // transform.RotateAround(_childObj.position, Vector3.up, Time.deltaTime * -RockerSpeed);
        //    return;
        //}


        //Debug.Log("_currentAngle:::" + _currentAngle + ",_childObj.eulerAngles.y::" + _childObj.eulerAngles.y
        //    + ",transform.rotation::"+ transform.rotation);

        RaycastHit GroundHitInfo;
        RaycastHit BarrieHitrInfo;
        bool       bGroundInfoFlag  = _motionObj.RayGroundInfo(out GroundHitInfo);
        bool       bBarrierInfoFlag = _motionObj.RayBarrierInfo(_childTransformObj.forward.ToVector(), out BarrieHitrInfo);

        FPVector fpGroundInfoNormal = FPVector.zero;

        if (bGroundInfoFlag)
        {
            fpGroundInfoNormal = GroundHitInfo.normal.ToFPVector();
        }

        if (!_dragging && !_bTouchMouse && _bBeforeDragging)
        {
            _rockerControl = ComMoveController.RockerControl.None;
            return;
        }
        else if (!_dragging)
        {
            if (_bBeforeDragging)  //在这里设置值,为了保证childObj的forward朝向跟摄像机的一致,防止先后差值
            {
                _bBeforeDragging = false;
                return;
            }

            if (!bGroundInfoFlag)  //在空中
            {
                _rockerControl = ComMoveController.RockerControl.AirControl;
                if (_motionObj.bJumpFlag && false)  //这是处理不跟随着对象跳跃的逻辑部分
                {
                    Distance = FPMath.Clamp(Distance - (Input.GetAxis("Mouse ScrollWheel") * MouseScrollWheelSensitivity), DistanceMin, DistanceMax);
                    FPVector DataVec3 = new FPVector(_playerTransformObj.position.x, transform.position.y - Height, _playerTransformObj.position.z);
                    _ufpTransform.position = (_ufpTransform.rotation * new FPVector(.0f, Height, -Distance)) + DataVec3;
                    _ufpTransform.UpdateAllData();
                    return;
                }
            }
            else if (!bBarrierInfoFlag || !_motionObj.JudgetGroundSlope(BarrieHitrInfo.normal))  //有地面接触但前方没有障碍物
            {
                if (!_motionObj.JudgetGroundSlope(GroundHitInfo.normal))
                {
                    _rockerControl  = ComMoveController.RockerControl.OtherControl;
                    _climbOtherWall = false;
                }
                else
                {
                    if (_climbOtherWall && _beforeWallNormalVec3 != fpGroundInfoNormal)  //表示从一面墙跨到另外一面墙
                    {
                        _beforeGroundNormalVec3 = _beforeWallNormalVec3;
                        _beforeWallNormalVec3   = fpGroundInfoNormal;
                    }
                    _rockerControl = ComMoveController.RockerControl.ClimbControl;
                }
            }
            else //有地面接触且前方有障碍物
            {
                _rockerControl = ComMoveController.RockerControl.None;
                _beforeControl = ComMoveController.RockerControl.OtherControl;
                if (!_motionObj.JudgetGroundSlope(GroundHitInfo.normal)) //从地面跨到墙上的情况
                {
                    _beforeGroundNormalVec3 = fpGroundInfoNormal;
                }
                else                                                   //从一面墙跨到另外一面墙的情况
                {
                    _climbOtherWall       = true;
                    _beforeWallNormalVec3 = fpGroundInfoNormal;   //设置这个变量的原因是:有可能检测到障碍物,但是玩家并没有跨越过去
                }
            }
        }

        if (_rockerControl == RockerControl.AirControl)
        {
            Distance = FPMath.Clamp(Distance - (Input.GetAxis("Mouse ScrollWheel") * MouseScrollWheelSensitivity), DistanceMin, DistanceMax);
            _ufpTransform.position = (_ufpTransform.rotation * new FPVector(.0f, Height, -Distance)) + _playerTransformObj.position;
            _ufpTransform.UpdateAllData();
        }
        else if (_rockerControl == RockerControl.OtherControl)
        {
            var quaternion = FPQuaternion.AngleAxis((_currentAngle) + _childTransformObj.transform.eulerAngles.y, FPVector.up);
            Distance = FPMath.Clamp(Distance - (Input.GetAxis("Mouse ScrollWheel") * MouseScrollWheelSensitivity), DistanceMin, DistanceMax);
            _ufpTransform.SetRotation(quaternion);
            // transform.rotation = quaternion;
            FPVector data = (_ufpTransform.rotation * new FPVector(.0f, Height, -Distance));

            _ufpTransform.position = (_ufpTransform.rotation * new FPVector(.0f, Height, -Distance)) + _playerTransformObj.position;
            _ufpTransform.UpdatePosition();
            //Debug.Log("data::"+ data.ToVector()+ ", _ufpTransform.position::::" + _ufpTransform.position.ToVector()
            //    + ",transform::" + transform.position + "::_playerTransformObj.position:" + _playerTransformObj.position.ToVector()
            //    + ",,name::" + _playerTransformObj.gameObject.name);
            _rotation = _ufpTransform.rotation;
            _ufpTransform.UpdateForward();
        }
        else if (_rockerControl == RockerControl.ClimbControl)
        {
            Distance = FPMath.Clamp(Distance - (Input.GetAxis("Mouse ScrollWheel") * MouseScrollWheelSensitivity), DistanceMin, DistanceMax);
            var quaternion = FPQuaternion.AngleAxis((0) + transform.eulerAngles.y, FPVector.up);
            _ufpTransform.position = (_ufpTransform.rotation * new FPVector(.0f, Height, -Distance)) + _playerTransformObj.position;
            _ufpTransform.UpdateAllData();

            FPVector climbForward = _ufpTransform.forward;

            if (_beforeControl == ComMoveController.RockerControl.OtherControl && _beforeGroundNormalVec3 != FPVector.zero)
            {
                FP       tempAngle = FPVector.Angle(_beforeGroundNormalVec3, fpGroundInfoNormal);
                FPVector normal    = FPVector.Cross(_beforeGroundNormalVec3, fpGroundInfoNormal); //叉乘求出法线向量
                                                                                                  //  num *= Mathf.Sign(Vector3.Dot(normal, info.transform.up));  //求法线向量与物体上方向向量点乘,结果为1或-1,修正旋转方向
                climbForward          = FPQuaternion.AngleAxis((90 - tempAngle), normal) * fpGroundInfoNormal;
                climbForward          = -1 * climbForward;
                _finishWallNormalVec3 = climbForward;
                _beforeControl        = ComMoveController.RockerControl.ClimbControl;
            }

            FP forwardAngle = FPVector.Angle(_finishWallNormalVec3, _ufpTransform.forward);
            if (forwardAngle != 0 && false)  //处理摄像机角度偏转
            {
                //1)调整摄像机的旋转角度
                float    direcFlag  = -1;
                FPVector normalVec3 = FPVector.Cross(_finishWallNormalVec3, _ufpTransform.forward);           //叉乘求出法线向量
                direcFlag    *= FPMath.Sign(Vector3.Dot(normalVec3.ToVector(), _ufpTransform.up.ToVector())); //求法线向量与物体上方向向量点乘,结果为1或-1,修正旋转方向
                forwardAngle *= direcFlag;

                FPVector beforeForward = _ufpTransform.forward;
                FPVector forward       = FPQuaternion.AngleAxis(forwardAngle, _ufpTransform.up) * _ufpTransform.forward;
                //   Debug.Log("_ufpTransform.forward::" + _ufpTransform.forward.ToVector() + ",forward::" + forward.ToVector()
                //        + "forwardAngle:::" + forwardAngle.AsFloat() + ",forward1111::" + forward);
                float quaternionSpeed = 0.003f;
                if (!_bTouchMouse)
                {
                    quaternionSpeed = 0.03f;
                }
                if (beforeForward != forward)
                {
                    Debug.Log("LookRotation(forward):::" + FPQuaternion.LookRotation(forward) + ",_rotation::" + _rotation + ",unity::" + Quaternion.LookRotation(forward.ToVector()));

                    _rotation = FPQuaternion.Slerp(_rotation, FPQuaternion.LookRotation(forward), quaternionSpeed);
                    _ufpTransform.SetRotation(_rotation);
                }
                //   Debug.Log(",forward::"+ forward.ToVector() + ",_ufpTransform.forward::" + _ufpTransform.forward.ToVector());
                //2)调整人物的旋转角度
                if (!_climbOtherWall)  // 这是从地面爬到墙得处理,如果是从一面墙爬到另外一面墙,镜头不做转换
                {
                    Debug.Log("beforeForward:::" + beforeForward.ToVector() + ",_ufpTransform.forward::" + _ufpTransform.forward.ToVector());
                    _offsetAngle = FPVector.Angle(beforeForward, _ufpTransform.forward) * direcFlag;
                    _avatarObj.ChangeAvaterForward(_offsetAngle);
                }
            }
        }

        Debug.DrawLine(_ufpTransform.position.ToVector(), _playerTransformObj.transform.position, Color.red);

        if (_rockerControl == RockerControl.OtherControl ||
            _rockerControl == RockerControl.ClimbControl)
        {
            //看是否有障碍物
            FPVector directionTarget = (_ufpTransform.position - _ufpTransform.ChangeVec3ToTSVec(_rayPointObj.position)).normalized;
            FP       distance        = FPVector.Distance(_ufpTransform.position, _ufpTransform.ChangeVec3ToTSVec(_rayPointObj.position));
            if (distance > Distance)
            {
                _ufpTransform.Translate(directionTarget * (distance - Distance));
                _ufpTransform.UpdateRotationAndPosition();
            }

            //  Debug.DrawRay(_rayPointObj.position, directionTarget * Distance, Color.black);
            int        layerMask = LayerMask.GetMask(Layers.Render);
            RaycastHit info;
            if (Physics.Raycast(_rayPointObj.position, directionTarget.ToVector(), out info, Distance.AsFloat(), layerMask))  //如果
            {
                //   Debug.Log("info.name::" + info.transform.name);
                if (info.transform.name != transform.name /*&& info.transform.tag != Tags.Ground*/)
                {
                    _ufpTransform.SetPosition(_ufpTransform.ChangeVec3ToTSVec(info.point));
                    //transform.position = info.point;
                }
                if (_rockerControl == RockerControl.OtherControl)
                {
                    _beforeControl = RockerControl.OtherControl;
                }
            }
        }
    }
示例#5
0
 public static float SignedAngle(FPVector2 from, FPVector2 to) => FPMath.Angle(from, to) * FPMath.Sign(from.x * to.y - from.y * to.x);