Пример #1
0
    void CreateTowelLimit()
    {
        ChainFinder leftChain  = leftGrabbed.GetComponent <ChainFinder>();
        ChainFinder rightChain = rightGrabbed.GetComponent <ChainFinder>();

        Transform[] chain;
        float       lengthLimit = 0;

        if (leftChain.index > rightChain.index)
        {
            chain       = rightChain.GetChainToIndex(leftChain.index);
            lengthLimit = rightChain.GetMaxLengthToIndex(leftChain.index);
        }
        else
        {
            chain       = leftChain.GetChainToIndex(rightChain.index);
            lengthLimit = leftChain.GetMaxLengthToIndex(rightChain.index);
        }
        foreach (Transform link in chain)
        {
            link.BroadcastMessage("SetGrabbed", true);
        }

        debugList = chain;
        MovementLimiter limiter = new MovementLimiter(leftHand, rightHand, lengthLimit, true, true, chain, 0.175f * 2f);

        handsLimiter = limiter;
        // Debug.Log("created towel limit");
    }
Пример #2
0
    void GetChains()
    {
        List <Transform> tempAbove = new List <Transform>();
        List <Transform> tempBelow = new List <Transform>();

        tempAbove.Add(transform);
        tempBelow.Add(transform);
        int aboveIndex = index;
        int belowIndex = index;

        HingeJoint2D[] hinges = transform.GetComponents <HingeJoint2D>();
        if (hinges.Length < 2)
        {
            end = true;
        }

        bool foundEnds = false;

        while (!foundEnds)
        {
            List <HingeJoint2D> tempHingeList = new List <HingeJoint2D>();

            foreach (HingeJoint2D hinge in hinges)
            {
                ChainFinder chain = hinge.connectedBody.GetComponent <ChainFinder>();

                if (chain.index > aboveIndex) // if this chain is above in index, add it to the above array and iterate on it
                {
                    tempAbove.Add(chain.transform);
                    aboveIndex = chain.index;
                    tempHingeList.AddRange(chain.GetComponents <HingeJoint2D>());
                }

                if (chain.index < belowIndex) // if this chain is below in index, add it to the below array and iterate on it
                {
                    tempBelow.Add(chain.transform);
                    belowIndex = chain.index;
                    tempHingeList.AddRange(chain.GetComponents <HingeJoint2D>());
                }
            }

            if (tempHingeList.Count == 0) // if there are no more arrays end
            {
                foundEnds = true;
            }
            else
            {
                hinges = tempHingeList.ToArray();
            }
        }

        above = tempAbove;
        below = tempBelow;
    }