protected override Joint ApplyJoint(GameObject rigidbodyGo, PartConfig config, GameObject target)
    {
        var joint = rigidbodyGo.AddComponent <HingeJoint>();

        // add motor
        var applyMotor = motor;

        if (config != null && config.Has(ConfigTag.MotorEnable) && !config.Get <bool>(ConfigTag.MotorEnable))    // config override
        {
            applyMotor = false;
        }
        if (applyMotor)
        {
            var motorActuator = rigidbodyGo.AddComponent <MotorActuator>();
            motorActuator.maxTorque = motorMaxTorque;
            motorActuator.maxSpeed  = motorMaxSpeed;
            motorActuator.motorSfx  = motorSfx;
            // apply motor.left from config
            if (config != null && config.Get <bool>(ConfigTag.MotorLeft))
            {
                motorActuator.isLeft = true;
            }
            // apply motor.left from config
            if (config != null && config.Get <bool>(ConfigTag.MotorReverse))
            {
                motorActuator.reverse = true;
            }
        }
        return(joint);
    }
Beispiel #2
0
    public static GameObject BuildGo(
        PartConfig config,
        GameObject root,
        string label,
        params Type[] components
        )
    {
        // create empty game object w/ rigidbody component
        var go = new GameObject(label, components);

        if (root != null)
        {
            go.transform.parent        = root.transform;
            go.transform.localPosition = Vector3.zero;
            go.transform.localRotation = Quaternion.identity;
        }

        // look in config to determine if we are in display or build mode
        if (config != null && config.Get <bool>(ConfigTag.PartHide))
        {
            go.hideFlags |= HideFlags.HideInHierarchy;
        }
        if (config != null && config.Get <bool>(ConfigTag.PartDontSave))
        {
            go.hideFlags |= HideFlags.DontSave;
        }
        if (config != null && config.Get <bool>(ConfigTag.PartReadOnly))
        {
            go.hideFlags |= HideFlags.NotEditable;
        }
        return(go);
    }
    protected override Joint ApplyJoint(GameObject rigidbodyGo, PartConfig config, GameObject target)
    {
        // add fixed joint component to target
        var joint = rigidbodyGo.AddComponent <HingeJoint>();

        // add steering actuator
        var steering = rigidbodyGo.AddComponent <SteeringActuator>();

        if (config != null && config.Get <bool>(ConfigTag.SteeringReverse))
        {
            steering.reverse = true;
        }
        else
        {
            steering.reverse = false;
        }
        steering.maxTurnAngle = maxTurnAngle;

        // apply hinge properties
        joint.axis = new Vector3(0, 1, 0);
        var limits = joint.limits;

        limits.min      = -maxTurnAngle;
        limits.max      = maxTurnAngle;
        joint.limits    = limits;
        joint.useLimits = true;
        var hingeSpring = joint.spring;

        hingeSpring.spring         = steeringTorque;
        hingeSpring.damper         = steeringDamper;
        hingeSpring.targetPosition = 0;
        joint.spring    = hingeSpring;
        joint.useSpring = true;

        return(joint);
    }
    public override void Apply(PartConfig config, GameObject target)
    {
        // find rigid body gameobject under target
        if (target == null)
        {
            return;
        }
        //var rigidbodyGo = PartUtil.GetBodyGo(target);
        //if (rigidbodyGo == null) return;

        // apply panels based on config
        if (top != null && config != null && config.Get <bool>(ConfigTag.PanelTop))
        {
            top.Build(config, target, "top");
        }
        if (bottom != null && config != null && config.Get <bool>(ConfigTag.PanelBottom))
        {
            bottom.Build(config, target, "bottom");
        }
        if (left != null && config != null && config.Get <bool>(ConfigTag.PanelLeft))
        {
            left.Build(config, target, "left");
        }
        if (right != null && config != null && config.Get <bool>(ConfigTag.PanelRight))
        {
            right.Build(config, target, "right");
        }
        if (front != null && config != null && config.Get <bool>(ConfigTag.PanelFront))
        {
            front.Build(config, target, "front");
        }
        if (back != null && config != null && config.Get <bool>(ConfigTag.PanelBack))
        {
            back.Build(config, target, "back");
        }
    }