Esempio n. 1
0
 /// <summary>
 /// Attempts to place a muscle starting at the specified position.
 /// </summary>
 public void TryStartingMuscle(Bone bone)
 {
     if (bone != null)
     {
         CreateMuscleFromBone(bone);
         var startPos = bone.Center;
         currentMuscle.SetLinePoints(startPos, startPos);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Instantiates a muscle at the specified point.
        /// </summary>
        private void CreateMuscleFromBone(Bone bone)
        {
            var muscleData = new MuscleData(idCounter++, bone.BoneData.id, bone.BoneData.id, Muscle.Defaults.MaxForce, true);

            currentMuscle = Muscle.CreateFromData(muscleData);
            currentMuscle.startingBone = bone;
            currentMuscle.SetLinePoints(bone.Center, bone.Center);
        }
Esempio n. 3
0
    /** Instantiates a muscle at the specified point. */
    private void CreateMuscleFromJoint(MuscleJoint joint)
    {
        Vector3 point = joint.position;

        point.z = 0;

        /*GameObject muscleEmpty = new GameObject();
        *  muscleEmpty.name = "Muscle";
        *  currentMuscle = muscleEmpty.AddComponent<Muscle>();
        *  currentMuscle.AddLineRenderer();
        *  currentMuscle.SetMaterial(muscleMaterial);*/
        //currentMuscle = ((GameObject) Instantiate(musclePreset, point, Quaternion.identity)).GetComponent<Muscle>();
        currentMuscle = Muscle.Create();
        currentMuscle.startingJoint = joint;
        currentMuscle.SetLinePoints(joint.position, joint.position);
    }
Esempio n. 4
0
    /// <summary>
    /// Checks for click / touch events and handles them appropiately depending on the
    /// currently selected body part.
    /// </summary>
    private void HandleClicks()
    {
        // Middle click or two touches to move the camera
        if ((Input.GetMouseButton(2) && Input.touchCount == 0) || Input.touchCount == 2)
        {
            //if (EventSystem.current.IsPointerOverGameObject() || isPointerOverUIObject()) return;

            var position = Input.mousePosition;

            if (Input.touchCount == 2)
            {
                position = GetPinchCenter(Input.touches[0].position, Input.touches[1].position);
            }

            //position = ScreenToWorldPoint(position);


            var distance = lastTouchPos - position;
            lastTouchPos = position;

            if (firstMovementTouch)
            {
                firstMovementTouch = false;
                return;
            }

            firstMovementTouch = false;

            // move the camera by the distance
            distance = ScreenToWorldDistance(distance);
            buttonManager.MoveCamera(distance);

            return;
        }
        else
        {
            firstMovementTouch = true;
            lastTouchPos       = Vector3.zero;
        }

        if (Input.GetMouseButtonDown(0))                // user clicked

        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }
            if (isPointerOverUIObject())
            {
                return;
            }

            if (selectedPart == BuildSelection.Joint)                                   // Place a JOINT

            {
                var pos = ScreenToWorldPoint(Input.mousePosition);
                pos.z = 0;
                // Grid logic
                if (grid.gameObject.activeSelf)
                {
                    pos = grid.ClosestPointOnGrid(pos);
                }

                // Make sure the joint doesn't overlap another one
                bool noOverlap = true;
                foreach (var joint in joints)
                {
                    if ((joint.center - pos).magnitude < jointNonOverlapRadius)
                    {
                        noOverlap = false;
                        break;
                    }
                }

                if (noOverlap)
                {
                    PlaceJoint(pos);
                }
            }
            else if (selectedPart == BuildSelection.Bone)                       // Start placing BONE
            // find the selected joint
            {
                Joint joint = GetHoveringObject <Joint>(joints);

                if (joint != null)
                {
                    CreateBoneFromJoint(joint);
                    PlaceConnectionBetweenPoints(currentBone.gameObject, joint.center, ScreenToWorldPoint(Input.mousePosition), CONNECTION_WIDHT);
                }
            }
            else if (selectedPart == BuildSelection.Muscle)                     // Start placing MUSCLE
            // find the selected bone
            {
                Bone bone = GetHoveringObject <Bone>(bones);

                if (bone != null)
                {
                    Vector3     mousePos = ScreenToWorldPoint(Input.mousePosition);
                    MuscleJoint joint    = bone.muscleJoint;

                    CreateMuscleFromJoint(joint);
                    //PlaceConnectionBetweenPoints(currentMuscle.gameObject, joint.position, mousePos, CONNECTION_WIDHT);
                    currentMuscle.SetLinePoints(joint.position, mousePos);
                }
            }
            else if (selectedPart == BuildSelection.Delete)                 // Delete selected object

            //UpdateDeletedObjects();

            {
                BodyComponent joint  = GetHoveringObject <Joint>(joints);
                BodyComponent bone   = GetHoveringObject <Bone>(bones);
                BodyComponent muscle = GetHoveringObject <Muscle>(muscles);

                BodyComponent toDelete = joint != null ? joint : (bone != null ? bone : muscle);

                if (toDelete != null)
                {
                    toDelete.Delete();
                    UpdateDeletedObjects();

                    ResetCurrentCreatureName();                     // The creature was modified

                    Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
                }

                //UpdateDeletedObjects();
            }
            else if (selectedPart == BuildSelection.Move)
            {
                // Make sure the user is hovering over a joint
                Joint joint = GetHoveringObject <Joint>(joints);

                if (joint != null)
                {
                    currentMovingJoint = joint;

                    ResetCurrentCreatureName();                     // The creature was modified
                }
            }
        }
        else if (Input.GetMouseButton(0))
        {
            // Mouse click & hold
            if (selectedPart == BuildSelection.Bone)
            {
                if (currentBone != null)
                {
                    // check if user is hovering over an ending joint which is not the same as the starting
                    // joint of the currentBone
                    Joint   joint       = GetHoveringObject <Joint>(joints);
                    Vector3 endingPoint = ScreenToWorldPoint(Input.mousePosition);

                    if (joint != null && !joint.Equals(currentBone.startingJoint))
                    {
                        endingPoint             = joint.center;
                        currentBone.endingJoint = joint;
                    }

                    PlaceConnectionBetweenPoints(currentBone.gameObject, currentBone.startingPoint, endingPoint, CONNECTION_WIDHT);
                }
            }
            else if (selectedPart == BuildSelection.Muscle)
            {
                if (currentMuscle != null)
                {
                    // check if user is hovering over an ending joint which is not the same as the starting
                    // joint of the currentMuscle
                    Bone    bone        = GetHoveringObject <Bone>(bones);
                    Vector3 endingPoint = ScreenToWorldPoint(Input.mousePosition);

                    if (bone != null)
                    {
                        MuscleJoint joint = bone.muscleJoint;

                        if (!joint.Equals(currentMuscle.startingJoint))
                        {
                            endingPoint = joint.position;
                            currentMuscle.endingJoint = joint;
                        }
                        else
                        {
                            currentMuscle.endingJoint = null;
                        }
                    }
                    else
                    {
                        currentMuscle.endingJoint = null;
                    }

                    //PlaceConnectionBetweenPoints(currentMuscle.gameObject, currentMuscle.startingPoint, endingPoint, CONNECTION_WIDHT);
                    currentMuscle.SetLinePoints(currentMuscle.startingPoint, endingPoint);
                }
            }
            else if (selectedPart == BuildSelection.Move)
            {
                if (currentMovingJoint != null)
                {
                    // Move the joint to the mouse position.
                    var newPoint = ScreenToWorldPoint(Input.mousePosition);

                    if (grid.gameObject.activeSelf)
                    {
                        newPoint = grid.ClosestPointOnGrid(newPoint);
                    }
                    newPoint.z = 0;

                    currentMovingJoint.MoveTo(newPoint);

                    ResetCurrentCreatureName();                     // The creature was modified
                }
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (selectedPart == BuildSelection.Bone)
            {
                PlaceCurrentBone();
            }
            else if (selectedPart == BuildSelection.Muscle)
            {
                PlaceCurrentMuscle();
            }
            else if (selectedPart == BuildSelection.Move)
            {
                currentMovingJoint = null;
            }
        }
    }