Ejemplo n.º 1
0
    /// <summary>
    /// find all the children with joint in the name.
    /// </summary>
    /// <param name="parent">transform to search</param>
    /// <param name="nestedId">the depth of child in hierarchy from objects root</param>
    /// <returns></returns>
    List <Pancake_joint> FindChildrenWithJoints(Transform parent, int nestedId = 0)             // TODO: i havent set the depth anywhere yet :|
    {
        List <Pancake_joint> pancakeJoints = new List <Pancake_joint>();

        for (int i = 0; i < parent.childCount; i++)
        {
            Transform child = parent.GetChild(i);

            if (child.childCount > 0)
            {
                pancakeJoints.AddRange(FindChildrenWithJoints(child, nestedId + 1));
            }

            if (!child.name.Contains("joint"))
            {
                continue;
            }

            float jointWeight = nestedId < jointDepthWeight.Length ? jointDepthWeight[nestedId] : 1f;

            Pancake_jointDistance distanceJoint = child.gameObject.AddComponent <Pancake_jointDistance>();
            distanceJoint.Setup(transform, transformForceDistance, GetComponent <Pancake_panCollision>());

            Pancake_joint childJoint = child.gameObject.AddComponent <Pancake_joint>();
            childJoint.SetupColliderData(colliderCurve, maxDistanceFromCenter);
            childJoint.SetupJointData(maxJointRotation * jointWeight, maxPositionOffset, flattenSpeed_rotation, flattenSpeed_position);
            pancakeState.OnSideChanged += childJoint.OnPancakeSideChanged;              // reg onto the side change callback, to make sure the joints are being rotated in the correct diection.


            pancakeJoints.Add(childJoint);
        }

        return(pancakeJoints);
    }
Ejemplo n.º 2
0
 public void SetupColliderData(AnimationCurve collCurve, float maxDistance)
 {
     jointDistance         = GetComponent <Pancake_jointDistance>();
     colliderCurve         = collCurve;
     maxDistanceFromCenter = maxDistance;
 }