示例#1
0
    void SetupPhysicsBones()
    {
        MetaballCellObject rootObj = seed.boneRoot.GetComponentInChildren <MetaballCellObject>();

        if (rootObj != null)
        {
            SetupPhysicsBonesRecursive(rootObj, true);
        }
    }
    private void SetupPhysicsBones()
    {
        MetaballCellObject componentInChildren = (MetaballCellObject)((Component)this.seed.boneRoot).GetComponentInChildren <MetaballCellObject>();

        if (!Object.op_Inequality((Object)componentInChildren, (Object)null))
        {
            return;
        }
        this.SetupPhysicsBonesRecursive(componentInChildren, true);
    }
示例#3
0
    void SetupPhysicsBonesRecursive(MetaballCellObject obj, bool bRoot = false)
    {
        Rigidbody r = obj.GetComponent <Rigidbody>();

        if (r == null)
        {
            r = obj.gameObject.AddComponent <Rigidbody>();
        }
        r.useGravity = false;

        if (bRoot)
        {
            FixedJoint j = obj.GetComponent <FixedJoint>();
            if (j == null)
            {
                j = obj.gameObject.AddComponent <FixedJoint>();
            }
            j.connectedBody = seed.GetComponent <Rigidbody>();
        }
        else
        {
            {
                HingeJoint j = obj.GetComponent <HingeJoint>();
                if (j == null)
                {
                    j = obj.gameObject.AddComponent <HingeJoint>();
                }
                j.connectedBody = obj.transform.parent.GetComponent <Rigidbody>();
                j.useLimits     = true;
                j.limits        = new JointLimits()
                {
                    max = 30.0f, min = -30.0f
                };
            }
        }

        for (int i = 0; i < obj.transform.childCount; ++i)
        {
            Transform c = obj.transform.GetChild(i);

            MetaballCellObject childObj = c.GetComponent <MetaballCellObject>();
            if (childObj != null)
            {
                SetupPhysicsBonesRecursive(childObj);
            }
        }
    }
    private void SetupPhysicsBonesRecursive(MetaballCellObject obj, bool bRoot = false)
    {
        Rigidbody rigidbody = (Rigidbody)((Component)obj).GetComponent <Rigidbody>();

        if (Object.op_Equality((Object)rigidbody, (Object)null))
        {
            rigidbody = (Rigidbody)((Component)obj).get_gameObject().AddComponent <Rigidbody>();
        }
        rigidbody.set_useGravity(false);
        if (bRoot)
        {
            FixedJoint fixedJoint = (FixedJoint)((Component)obj).GetComponent <FixedJoint>();
            if (Object.op_Equality((Object)fixedJoint, (Object)null))
            {
                fixedJoint = (FixedJoint)((Component)obj).get_gameObject().AddComponent <FixedJoint>();
            }
            ((Joint)fixedJoint).set_connectedBody((Rigidbody)((Component)this.seed).GetComponent <Rigidbody>());
        }
        else
        {
            HingeJoint hingeJoint1 = (HingeJoint)((Component)obj).GetComponent <HingeJoint>();
            if (Object.op_Equality((Object)hingeJoint1, (Object)null))
            {
                hingeJoint1 = (HingeJoint)((Component)obj).get_gameObject().AddComponent <HingeJoint>();
            }
            ((Joint)hingeJoint1).set_connectedBody((Rigidbody)((Component)((Component)obj).get_transform().get_parent()).GetComponent <Rigidbody>());
            hingeJoint1.set_useLimits(true);
            HingeJoint  hingeJoint2  = hingeJoint1;
            JointLimits jointLimits1 = (JointLimits)null;
            ((JointLimits) ref jointLimits1).set_max(30f);
            ((JointLimits) ref jointLimits1).set_min(-30f);
            JointLimits jointLimits2 = jointLimits1;
            hingeJoint2.set_limits(jointLimits2);
        }
        for (int index = 0; index < ((Component)obj).get_transform().get_childCount(); ++index)
        {
            MetaballCellObject component = (MetaballCellObject)((Component)((Component)obj).get_transform().GetChild(index)).GetComponent <MetaballCellObject>();
            if (Object.op_Inequality((Object)component, (Object)null))
            {
                this.SetupPhysicsBonesRecursive(component, false);
            }
        }
    }