コード例 #1
0
    private void Update()
    {
        // If left joycon, inverse the up down direction
        var gryo = JoyConInputManager.GetJoyConGyro(false);

        acc = JoyConInputManager.GetJoyConAccel(false);
        transform.localRotation = JoyConInputManager.GetJoyConOrientation(false);
        //var rotZ = TransformUtils.GetInspectorRotation(transform).z;
        //if (rotZ < 0 && Mathf.Abs(rotZ + 90.0f) > 22) return;
        //if (rotZ > 0 && Mathf.Abs(rotZ - 90.0f) > 22) return;
        //roundAccX = Mathf.Round(acc.x * 10.0f) / 10.0f;
        //transform.position = new Vector3(transform.position.x, transform.position.y + roundAccX * 12.0f * Time.deltaTime, transform.position.z);
        //Debug.Log(gryo);
        //Vector3 presentAcc = JoyConInputManager.GetJoyConAccel(false);
        //transform.Translate((prevAcc - presentAcc) * Time.deltaTime * speed);
        //prevAcc = presentAcc;
    }
コード例 #2
0
    private void RotatePlayer()
    {
        #region KeyboardInput
        var horizontalInput = Input.GetAxis("Keyboard_Horizontal");
        if (horizontalInput != 0.0f)
        {
            var newQuat = Quaternion.Euler(0.0f,
                                           horizontalInput * keyboardRotSpeed * Time.deltaTime,
                                           0.0f);
            rd.MoveRotation(newQuat * rd.rotation);
            return;
        }
        #endregion

        #region JoyConInput
        // Recenter
        if (JoyConInputManager.GetJoyConButtonDown(Joycon.Button.SHOULDER_1))
        {
            RecenterPlayerJoyCon();
        }

        // Clamp
        ++frameCount;
        Quaternion joyConFixQuat = Quaternion.Euler(0.0f, JoyConRotFixAngle * Mathf.Pow(frameCount, JoyConRotFixPower) * Time.deltaTime, 0.0f);
        targetJoyConRot = joyConFixQuat * JoyConInputManager.GetJoyConOrientation(isUsingLeftJoyCon);
        if (targetJoyConRot != Quaternion.identity)
        {
            deferredJoyConRot = Quaternion.RotateTowards(deferredJoyConRot,
                                                         targetJoyConRot, joyConRotSpeed * Time.deltaTime);

            var joyConDir = deferredJoyConRot * Vector3.up;
            if (Vector3.Angle(joyConDir, Vector3.forward) > angleLimit)
            {
                return;
            }

            // Add gyro data to player model rotation
            var initiRot = transform.rotation.eulerAngles;
            var tempQuat = deferredJoyConRot * Quaternion.Euler(90.0f, 0.0f, 0.0f);
            transform.rotation  = Quaternion.Euler(initiRot.x, tempQuat.eulerAngles.y, initiRot.z);
            transform.rotation *= Quaternion.AngleAxis(180.0f, Vector3.up);
        }
        #endregion
    }
コード例 #3
0
    private void PassBridge()
    {
        if (!shouldCountUnstableTimer)
        {
            Debug.Assert(passingBridge != null);
            MovePlayer(passBridgeSpeed);
            transform.position = new Vector3(passingBridge.transform.position.x,
                                             transform.position.y, transform.position.z);
            transform.localRotation = Quaternion.identity;
        }

        #region UnstableProcess
        if (!shouldCheckUnstable)
        {
            return;
        }
        var  joyConAccel     = JoyConInputManager.GetJoyConAccel(isUsingLeftJoyCon);
        bool isAccelUnstable = joyConAccel.magnitude - 1.0f > accelTolerance ||
                               Input.GetAxis("Keyboard_Horizontal") != 0.0f;
        var  joyConYRot      = JoyConInputManager.GetJoyConOrientation(isUsingLeftJoyCon).eulerAngles.y;
        bool isAngleUnstable = Quaternion.Dot(passBridgeBenchmarkQuat,
                                              JoyConInputManager.GetJoyConOrientation(isUsingLeftJoyCon))
                               < angleTolerance;

        if (isAccelUnstable || isAngleUnstable)
        {
            shouldCountUnstableTimer = true;
            ani.SetBool("isBridgeUnstable", true);
        }

        if (shouldCountUnstableTimer)
        {
            timer += Time.deltaTime;
        }

        if (timer >= unstableHoldTime)
        {
            timer = 0.0f;
            shouldCountUnstableTimer = false;
            ani.SetBool("isBridgeUnstable", false);
        }
        else
        {
            if (timer < unstableRemedyTime)
            {
                return;
            }
            if (isAccelUnstable || isAngleUnstable)
            {
                timer = 0.0f;
                shouldCountUnstableTimer = false;
                ani.SetBool("isBridgeUnstable", false);
                SetPlayerState(MarathonPlayerStatus.Falling);
                passingBridge.BeforePlayerFelledOut(this);
                Vector3 dropDir = UnityEngine.Random.value > 0.5f ?
                                  transform.right : -transform.right;
                rd.AddForce(dropDir * fellOutForce, ForceMode.Impulse);
            }
        }
        #endregion
    }
コード例 #4
0
 private void Start()
 {
     targetJoyConRot = JoyConInputManager.GetJoyConOrientation(isUsingLeftJoyCon);
     RecenterPlayerJoyCon();
 }
コード例 #5
0
    private void Update()
    {
        if (!isDirtyInitilized)
        {
            JoyConInputManager.Recenter(isUsingLeftJoyCon);
            isDirtyInitilized = true;
        }

        // Calc the point of intersection between joyConDirection and UIScreen
        var joyConQuat = JoyConInputManager.GetJoyConOrientation(isUsingLeftJoyCon);

        joyConPointDir = joyConQuat * Camera.main.transform.up;
        if (joyConPointDir.z < 0)
        {
            return;
        }
        if (shouldReverseJoyConY)
        {
            joyConPointDir = new Vector3(joyConPointDir.x, -joyConPointDir.y, joyConPointDir.z).normalized;
        }
        else
        {
            joyConPointDir = joyConPointDir.normalized;
        }

        joyConPointDir = Camera.main.WorldToScreenPoint(joyConPointDir * pointerMoveSpeed
                                                        + Camera.main.transform.position) + new Vector3(pointerAdjuster.x, pointerAdjuster.y, 0);

        // Detect hit
        eventDataCurrentPosition.position = joyConPointDir;
        EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
        if (results.Count > 0)
        {
            bool hasIcon = false;
            foreach (var i in results)
            {
                var interfaceComp = i.gameObject.GetComponent <IJoyConSelectable>();
                // If not seletable icon
                if (interfaceComp == null)
                {
                    if (i.gameObject.name == "BG")
                    {
                        pointerMark.transform.position = i.screenPosition;
                    }
                }
                else
                {
                    i.gameObject.GetComponent <Image>().color = Color.red;
                    hasIcon = true;
                }
            }

            if (!hasIcon)
            {
                foreach (var i in iconObjs)
                {
                    i.GetComponent <Image>().color = Color.white;
                }
            }
        }

        HandleJoyConInput();
    }