Exemple #1
0
    protected Rope CreateRopeWithSectionType(RopeSection sectionPrefab)
    {
        // Create Rope Container
        Rope ropeContainer = Instantiate(ropePrefab, transform.position, Quaternion.identity) as Rope;

        ropeContainer.name = "Rope " + index;

        // Create First section and remove its joint
        RopeSection lastSection = Instantiate(sectionPrefab, new Vector3(ropeEnds.x, transform.position.y, 0), Quaternion.identity) as RopeSection;

        // Connect to Rope Container
        ropeContainer.AddSection(lastSection);

        // Count variables and section length
        float offset        = 0f;
        float sectionLength = lastSection.transform.localScale.x - 0.05f;

        // Calculate number of sections based on draw length
        float distance = ropeEnds.y - ropeEnds.x;
        int   num      = Mathf.CeilToInt(distance / sectionLength);

        while (num > 0)
        {
            // Count
            num--;
            offset += sectionLength;

            // Add new Section
            RopeSection newSection = Instantiate(sectionPrefab, new Vector3(ropeEnds.x + offset, transform.position.y, 0), Quaternion.identity) as RopeSection;
            newSection.ConnectTo(lastSection);

            // Add to Rope Container
            ropeContainer.AddSection(newSection);

            // Reset for next iteration
            lastSection = newSection;
        }

        return(ropeContainer);
    }
    protected override void CustomizeRope(Rope rope)
    {
        RopeSection weight1 = Instantiate(weightPrefab, rope.sections[0].transform.position - Vector3.right * Utility.LINE_SECTION_WIDTH, Quaternion.identity);

        rope.sections[0].ConnectTo(weight1);
        rope.InsertSection(weight1, 0);

        Destroy(weight1.GetComponent <ConfigurableJoint>());

        int         numSections = rope.sections.Count;
        RopeSection weight2     = Instantiate(weightPrefab, rope.sections[numSections - 1].transform.position + Vector3.right * Utility.LINE_SECTION_WIDTH, Quaternion.identity);

        weight2.ConnectTo(rope.sections[numSections - 1]);
        rope.AddSection(weight2);
    }