Exemple #1
0
 virtual protected void OnEnable()
 {
     _jointObject   = target as b2JointObject;
     _targetGameObj = _jointObject.gameObject;
     //
     _oldEnableCollision       = _jointObject.enableCollision;
     _oldConnectedB2BodyObject = _jointObject.connectedB2BodyObject;
 }
Exemple #2
0
    /**解析b2BodyObject*/
    private static void parseB2BodyObject(b2BodyObject bodyObj, XmlElement componentElement, XmlDocument xml)
    {
        //LinearDamping
        XmlElement linearDampingElement = xml.CreateElement("LinearDamping");

        linearDampingElement.InnerText = bodyObj.linearDamping.ToString();
        componentElement.AppendChild(linearDampingElement);
        //AngularDamping
        XmlElement angularDampingElement = xml.CreateElement("AngularDamping");

        angularDampingElement.InnerText = bodyObj.angularDamping.ToString();
        componentElement.AppendChild(angularDampingElement);
        //InertiaScale
        XmlElement inertiaScaleElement = xml.CreateElement("InertiaScale");

        inertiaScaleElement.InnerText = bodyObj.inertiaScale.ToString();
        componentElement.AppendChild(inertiaScaleElement);
        //AllowBevelSlither
        XmlElement allowBevelSlitherElement = xml.CreateElement("AllowBevelSlither");

        allowBevelSlitherElement.InnerText = bodyObj.allowBevelSlither.ToString();
        componentElement.AppendChild(allowBevelSlitherElement);
        //AllowMovement
        XmlElement allowMovementElement = xml.CreateElement("AllowMovement");

        allowMovementElement.InnerText = bodyObj.allowMovement.ToString();
        componentElement.AppendChild(allowMovementElement);
        //AllowSleep
        XmlElement allowSleepElement = xml.CreateElement("AllowSleep");

        allowSleepElement.InnerText = bodyObj.allowSleep.ToString();
        componentElement.AppendChild(allowSleepElement);
        //Bullet
        XmlElement bulletElement = xml.CreateElement("Bullet");

        bulletElement.InnerText = bodyObj.bullet.ToString();
        componentElement.AppendChild(bulletElement);
        //FixedRotation
        XmlElement fixedRotationElement = xml.CreateElement("FixedRotation");

        fixedRotationElement.InnerText = bodyObj.fixedRotation.ToString();
        componentElement.AppendChild(fixedRotationElement);
        //IsIgnoreFrictionX
        XmlElement isIgnoreFrictionXElement = xml.CreateElement("IsIgnoreFrictionX");

        isIgnoreFrictionXElement.InnerText = bodyObj.isIgnoreFrictionX.ToString();
        componentElement.AppendChild(isIgnoreFrictionXElement);
        //IsIgnoreFrictionY
        XmlElement isIgnoreFrictionYElement = xml.CreateElement("IsIgnoreFrictionY");

        isIgnoreFrictionYElement.InnerText = bodyObj.isIgnoreFrictionY.ToString();
        componentElement.AppendChild(isIgnoreFrictionYElement);
        //Type
        XmlElement typeElement = xml.CreateElement("Type");

        typeElement.InnerText = ((int)bodyObj.type).ToString();
        componentElement.AppendChild(typeElement);
    }
Exemple #3
0
    void OnEnable()
    {
        _bodyObj = target as b2BodyObject;
        _targetT = _bodyObj.GetComponent <Transform>();

        _oldPosition    = _targetT.position;
        _oldEulerAngles = _targetT.rotation.eulerAngles;
        _oldScale       = _targetT.localScale;
    }
 override protected void onChangeConnectedB2BodyObject(b2BodyObject oldConnectedB2BodyObject, b2BodyObject newConnectedB2BodyObject)
 {
     //变更链接的刚体时,移除、添加
     if (oldConnectedB2BodyObject != null)
     {
         oldConnectedB2BodyObject.removeJointObject(_revoluteJointObject);
     }
     if (newConnectedB2BodyObject != null)
     {
         newConnectedB2BodyObject.addJointObject(_revoluteJointObject);
     }
     fixAutoAnchor();
 }
Exemple #5
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (!_jointObject.enabled)
        {
            return;
        }

        bool isChanged  = false;
        bool isReCreate = false;

        if (_oldEnableCollision != _jointObject.enableCollision)
        {
            isChanged           = true;
            _oldEnableCollision = _jointObject.enableCollision;
        }
        if (_oldConnectedB2BodyObject != _jointObject.connectedB2BodyObject)
        {
            isReCreate = true;
            //不能设置为bodyA
            if (_jointObject.connectedB2BodyObject != null)
            {
                b2BodyObject bodyObjectA = _jointObject.GetComponent <b2BodyObject>();
                if (bodyObjectA == _jointObject.connectedB2BodyObject)
                {
                    _jointObject.connectedB2BodyObject = null;
                    Debug.LogError("cannot be set to itself");
                }
            }
            onChangeConnectedB2BodyObject(_oldConnectedB2BodyObject, _jointObject.connectedB2BodyObject);
            _oldConnectedB2BodyObject = _jointObject.connectedB2BodyObject;
        }

        if (isReCreate)
        {
            sendReCreateMessage();
        }
        else if (isChanged)
        {
            sendChangeMessage();
        }
    }
Exemple #6
0
 /**在改变链接的刚体之前*/
 virtual protected void onChangeConnectedB2BodyObject(b2BodyObject oldConnectedB2BodyObject, b2BodyObject newConnectedB2BodyObject)
 {
 }