public override void OnInspectorGUI()
    {
        HandController t = target as HandController;

        if (t.Gears.Count == 0)
        {
            t.createGears();
        }

        EditorGUILayout.LabelField("Gears:");
        {
            EditorGUI.indentLevel++;
            foreach (var entry in t.Gears)
            {
                entry.Value.angle = EditorGUILayout.FloatField(entry.Key.ToString().ToLower(), entry.Value.angle);
            }
            EditorGUI.indentLevel--;
        }

        EditorGUILayout.Space();

        if (GUILayout.Button("Generate Skeleton"))
        {
            Transform parent = t.transform;

            for (HandBoneIndex i = HandBoneIndices.WristStart; i < HandBoneIndices.WristEnd; ++i)
            {
                parent = createBoneNode(parent, i);
            }

            Transform thumb = parent, index = parent, middle = parent, ring = parent, pinky = parent;

            for (HandBoneIndex i = HandBoneIndices.ThumbStart; i < HandBoneIndices.ThumbEnd; ++i)
            {
                thumb = createBoneNode(thumb, i);
            }
            for (HandBoneIndex i = HandBoneIndices.IndexStart; i < HandBoneIndices.IndexEnd; ++i)
            {
                index = createBoneNode(index, i);
            }
            for (HandBoneIndex i = HandBoneIndices.MiddleStart; i < HandBoneIndices.MiddleEnd; ++i)
            {
                middle = createBoneNode(middle, i);
            }
            for (HandBoneIndex i = HandBoneIndices.RingStart; i < HandBoneIndices.RingEnd; ++i)
            {
                ring = createBoneNode(ring, i);
            }
            for (HandBoneIndex i = HandBoneIndices.PinkyStart; i < HandBoneIndices.PinkyEnd; ++i)
            {
                pinky = createBoneNode(pinky, i);
            }

            HandRig rig = t.GetComponent <HandRig>();
            if (rig)
            {
                rig.searchNodes();
            }
        }
    }
Beispiel #2
0
    ////////////////
    //Input Controls
    ////////////////
    void InputControls()
    {
        //Walk forward / backward
        if (balanced && !KnockedOut)
        {
            var xAxis = getAxis()[0];
            var x     = Camera.main.transform.right * MoveSpeed * xAxis;

            var yAxis = getAxis()[1];
            var y     = Camera.main.transform.forward * MoveSpeed * yAxis;

            var movement = (x + y);
            APR_Parts[0].GetComponent <Rigidbody>().velocity = movement;


            if (xAxis != 0 && yAxis != 0)
            {
                var lookPos = movement;
                lookPos.y = 0;
                var rotation = Quaternion.LookRotation(lookPos);
                APR_Parts[0].GetComponent <ConfigurableJoint>().targetRotation = Quaternion.Lerp(APR_Parts[0].GetComponent <ConfigurableJoint>().targetRotation, Quaternion.Inverse(rotation), Time.deltaTime * damping);
            }

            if (yAxis > 0)
            {
                WalkForward = true;
                isKeyDown   = true;
            }

            if (yAxis < 0)
            {
                WalkBackward = true;
                isKeyDown    = true;
            }
        }

        if (moveBackwardReleased())
        {
            WalkBackward = false;
            isKeyDown    = false;
        }

        if (moveForwardReleased())
        {
            WalkForward = false;
            isKeyDown   = false;
        }

        //Get up
        if (jumpGetupPressed() && !balanced && !isJumping)
        {
            GettingUp = true;
            balanced  = true;

            if (KnockedOut)
            {
                DeactivateRagdoll();
            }
        }



        //Jump
        else if (jumpGetupReleased() && balanced && !inAir && !Jump && !KnockedOut)
        {
            Jump     = true;
            Grounded = false;

            APR_Parts[0].GetComponent <ConfigurableJoint>().angularXDrive  = DriveOff;
            APR_Parts[0].GetComponent <ConfigurableJoint>().angularYZDrive = DriveOff;
        }



        //Reach Left
        if (reachLeftPressed() && !KnockedOut)
        {
            ReachingLeft = true;
        }

        if (reachLeftReleased() && !KnockedOut)
        {
            ReachingLeft = false;
            PickedUp     = false;
            ResetPose    = true;
        }


        //Reach Right
        if (reachRightPressed() && !KnockedOut)
        {
            ReachingRight = true;
        }

        if (reachRightReleased() && !KnockedOut)
        {
            ReachingRight = false;
            PickedUp      = false;
            ResetPose     = true;
        }


        //Pick up left helper
        if (reachLeftPressed() && ReachingLeft && GrabLeft.hasJoint && !KnockedOut)
        {
            if (GrabLeft.GetComponent <FixedJoint>() != null)
            {
                if (GrabLeft.GetComponent <FixedJoint>().connectedBody.gameObject.tag == "Player")
                {
                    GrabLeft.GetComponent <Rigidbody>().AddForce(APR_Parts[0].transform.up * GrabLeft.GetComponent <FixedJoint>().connectedBody.mass * 150);
                }

                else if (GrabLeft.GetComponent <FixedJoint>().connectedBody.gameObject.tag == "Object")
                {
                    GrabLeft.GetComponent <Rigidbody>().AddForce(APR_Parts[0].transform.up * GrabLeft.GetComponent <FixedJoint>().connectedBody.mass * 5);
                }

                else if (GrabLeft.GetComponent <FixedJoint>().connectedBody.gameObject.tag == "Heavy Object")
                {
                    var test = GrabLeft.GetComponent <FixedJoint>();
                    Debug.Log(test.connectedBody.gameObject);
                    GrabLeft.GetComponent <Rigidbody>().AddForce(APR_Parts[0].transform.up * GrabLeft.GetComponent <FixedJoint>().connectedBody.mass);
                }
            }
        }

        //Pick up right helper
        if (reachRightPressed() && ReachingRight && GrabRight.hasJoint && !KnockedOut)
        {
            if (GrabRight.GetComponent <FixedJoint>() != null)
            {
                if (GrabRight.GetComponent <FixedJoint>().connectedBody.gameObject.tag == "Player")
                {
                    GrabRight.GetComponent <Rigidbody>().AddForce(APR_Parts[0].transform.up * GrabRight.GetComponent <FixedJoint>().connectedBody.mass * 150);
                }

                else if (GrabRight.GetComponent <FixedJoint>().connectedBody.gameObject.tag == "Object")
                {
                    GrabRight.GetComponent <Rigidbody>().AddForce(APR_Parts[0].transform.up * GrabRight.GetComponent <FixedJoint>().connectedBody.mass * 5);
                }

                else if (GrabRight.GetComponent <FixedJoint>().connectedBody.gameObject.tag == "Heavy Object")
                {
                    GrabRight.GetComponent <Rigidbody>().AddForce(APR_Parts[0].transform.up * GrabRight.GetComponent <FixedJoint>().connectedBody.mass);
                }
            }
        }

        //Pickup and Throw
        if (pickupThrowPressed() && !PickedUp && !KnockedOut)
        {
            PickedUp     = true;
            GrabbedLeft  = null;
            GrabbedRight = null;
        }

        else if (pickupThrowPressed() && PickedUp && !KnockedOut)
        {
            //Let go left
            if (GrabLeft.hasJoint)
            {
                GrabbedLeft = GrabLeft.GetComponent <FixedJoint>().connectedBody;
                GrabLeft.GetComponent <FixedJoint>().breakForce = 0;
                GrabLeft.hasJoint = false;
            }

            //Let go right
            if (GrabRight.hasJoint)
            {
                GrabbedRight = GrabRight.GetComponent <FixedJoint>().connectedBody;
                GrabRight.GetComponent <FixedJoint>().breakForce = 0;
                GrabRight.hasJoint = false;
            }

            Threw = true;

            //Throw left
            if (Threw)
            {
                if (GrabbedLeft != null && GrabbedLeft.gameObject.tag == "Object")
                {
                    GrabbedLeft.AddForce(APR_Parts[0].transform.forward * ThrowForce * GrabbedLeft.mass, ForceMode.Impulse);
                    GrabbedLeft.AddForce(APR_Parts[0].transform.up * ThrowForce * (GrabbedLeft.mass / 3), ForceMode.Impulse);
                }

                else if (GrabbedLeft != null && GrabbedLeft.gameObject.tag == "Player")
                {
                    GrabbedLeft.AddForce(APR_Parts[0].transform.forward * ThrowForce * GrabbedLeft.mass * 5, ForceMode.Impulse);
                    GrabbedLeft.AddForce(APR_Parts[0].transform.up * ThrowForce * GrabbedLeft.mass * 3.5f, ForceMode.Impulse);
                }
            }

            //Throw right
            if (Threw)
            {
                if (GrabbedRight != null && GrabbedRight.gameObject.tag == "Object")
                {
                    GrabbedRight.AddForce(APR_Parts[0].transform.forward * ThrowForce * GrabbedRight.mass, ForceMode.Impulse);
                    GrabbedRight.AddForce(APR_Parts[0].transform.up * ThrowForce * (GrabbedRight.mass / 3), ForceMode.Impulse);
                }

                else if (GrabbedRight != null && GrabbedRight.gameObject.tag == "Player")
                {
                    GrabbedRight.AddForce(APR_Parts[0].transform.forward * ThrowForce * GrabbedRight.mass * 5, ForceMode.Impulse);
                    GrabbedRight.AddForce(APR_Parts[0].transform.up * ThrowForce * GrabbedRight.mass * 3.5f, ForceMode.Impulse);
                }
            }

            PickedUp = false;
            Threw    = false;
        }



        //punch
        if (punchRightPressed() && !KnockedOut)
        {
            Punching = true;
            PunchRight();
        }

        if (punchLeftPressed() && !KnockedOut)
        {
            Punching = true;
            PunchLeft();
        }
    }