예제 #1
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);
    }
예제 #2
0
    public static Muscle CreateFromString(string data, List <Bone> bones)
    {
        var muscleID = 0;
        var startID  = 0;
        var endID    = 0;

        var parts = data.Split('%');

        try {
            muscleID = int.Parse(parts[0]);
            startID  = int.Parse(parts[1]);
            endID    = int.Parse(parts[2]);
        } catch (System.FormatException e) {
            Debug.Log(string.Format("x{0}x", data));
            throw e;
        }

        var muscle = Muscle.Create();

        muscle.ID  = muscleID;
        ID_COUNTER = Mathf.Max(ID_COUNTER - 1, muscle.ID);              // ID_COUNTER - 1 because the counter gets increased on Create()

        foreach (var bone in bones)
        {
            if (bone.ID == startID)
            {
                muscle.startingJoint = bone.muscleJoint;
            }
            else if (bone.ID == endID)
            {
                muscle.endingJoint = bone.muscleJoint;
            }
        }

        muscle.ConnectToJoints();
        muscle.UpdateLinePoints();

        muscle.AddCollider();

        return(muscle);
    }