protected override void OnEnable()
    {
        base.OnEnable();
        _revoluteJointObject = _jointObject as b2RevoluteJointObject;

        _oldAutoConfigureAnchor = _revoluteJointObject.autoConfigureAnchor;
        fixAutoAnchor();

        _oldLocalAnchor1.SetV(_revoluteJointObject.localAnchor1);
        _oldLocalAnchor2.SetV(_revoluteJointObject.localAnchor2);

        _oldEnableLimit    = _revoluteJointObject.enableLimit;
        _oldReferenceAngle = _revoluteJointObject.referenceAngle;
        _oldLowerAngle     = _revoluteJointObject.lowerAngle;
        _oldUpperAngle     = _revoluteJointObject.upperAngle;

        _oldEnableMotor    = _revoluteJointObject.enableMotor;
        _oldMotorSpeed     = _revoluteJointObject.motorSpeed;
        _oldMaxMotorTorque = _revoluteJointObject.maxMotorTorque;

        //添加到链接的bodyObject关节列表
        if (_revoluteJointObject.connectedB2BodyObject != null)
        {
            _revoluteJointObject.connectedB2BodyObject.addJointObject(_revoluteJointObject);
        }
    }
Ejemplo n.º 2
0
    /**修复b2RevoluteJoint*/
    private static void fixB2RevoluteJointWithTransform(Transform transform)
    {
        b2RevoluteJointObject revoluteJointObj = transform.GetComponent <b2RevoluteJointObject>();

        if (revoluteJointObj != null)
        {
            revoluteJointObj.updateAutoAnchor();
        }

        for (int i = 0; i < transform.childCount; i++)
        {
            fixB2RevoluteJointWithTransform(transform.GetChild(i));
        }
    }
Ejemplo n.º 3
0
    /**解析b2RevoluteJointObject*/
    private static void parseB2RevoluteJointObject(b2RevoluteJointObject revoluteJointObject, XmlElement componentElement, XmlDocument xml)
    {
        //EnableCollision
        XmlElement enableCollisionElement = xml.CreateElement("EnableCollision");

        enableCollisionElement.InnerText = revoluteJointObject.enableCollision.ToString();
        componentElement.AppendChild(enableCollisionElement);
        //ConnectedB2BodyObject    "null"/"instanceID"
        XmlElement connectedB2BodyObjectElement = xml.CreateElement("ConnectedB2BodyObject");

        if (revoluteJointObject.connectedB2BodyObject == null)
        {
            connectedB2BodyObjectElement.InnerText = "null";
        }
        else
        {
            connectedB2BodyObjectElement.InnerText = revoluteJointObject.connectedB2BodyObject.GetInstanceID().ToString();
        }
        componentElement.AppendChild(connectedB2BodyObjectElement);
        //AutoConfigureAnchor
        XmlElement autoConfigureAnchorElement = xml.CreateElement("AutoConfigureAnchor");

        autoConfigureAnchorElement.InnerText = revoluteJointObject.autoConfigureAnchor.ToString();
        componentElement.AppendChild(autoConfigureAnchorElement);
        //LocalAnchor1
        XmlElement localAnchor1Element = xml.CreateElement("LocalAnchor1");

        localAnchor1Element.SetAttribute("x", revoluteJointObject.localAnchor1.x.ToString());
        localAnchor1Element.SetAttribute("y", revoluteJointObject.localAnchor1.y.ToString());
        componentElement.AppendChild(localAnchor1Element);
        //LocalAnchor2
        XmlElement localAnchor2Element = xml.CreateElement("LocalAnchor2");

        localAnchor2Element.SetAttribute("x", revoluteJointObject.localAnchor2.x.ToString());
        localAnchor2Element.SetAttribute("y", revoluteJointObject.localAnchor2.y.ToString());
        componentElement.AppendChild(localAnchor2Element);
        //EnableLimit
        XmlElement enableLimitElement = xml.CreateElement("EnableLimit");

        enableLimitElement.InnerText = revoluteJointObject.enableLimit.ToString();
        componentElement.AppendChild(enableLimitElement);
        //ReferenceAngle
        XmlElement referenceAngleElement = xml.CreateElement("ReferenceAngle");

        referenceAngleElement.InnerText = revoluteJointObject.referenceAngle.ToString();
        componentElement.AppendChild(referenceAngleElement);
        //LowerAngle
        XmlElement lowerAngleElement = xml.CreateElement("LowerAngle");

        lowerAngleElement.InnerText = revoluteJointObject.lowerAngle.ToString();
        componentElement.AppendChild(lowerAngleElement);
        //UpperAngle
        XmlElement upperAngleElement = xml.CreateElement("UpperAngle");

        upperAngleElement.InnerText = revoluteJointObject.upperAngle.ToString();
        componentElement.AppendChild(upperAngleElement);
        //EnableMotor
        XmlElement enableMotorElement = xml.CreateElement("EnableMotor");

        enableMotorElement.InnerText = revoluteJointObject.enableMotor.ToString();
        componentElement.AppendChild(enableMotorElement);
        //MotorSpeed
        XmlElement motorSpeedElement = xml.CreateElement("MotorSpeed");

        motorSpeedElement.InnerText = revoluteJointObject.motorSpeed.ToString();
        componentElement.AppendChild(motorSpeedElement);
        //MaxMotorTorque
        XmlElement maxMotorTorqueElement = xml.CreateElement("MaxMotorTorque");

        maxMotorTorqueElement.InnerText = revoluteJointObject.maxMotorTorque.ToString();
        componentElement.AppendChild(maxMotorTorqueElement);
    }