コード例 #1
0
        public void OnEditorAttach()
        {
            Debug.Log("BDADJ oneditorattach");
            foreach (Part pSym in part.symmetryCounterparts)
            {
                if (pSym != part && isMirrored == false)
                {
                    pSym.FindModuleImplementing <BDAdjustableLandingGear>().isMirrored = true;
                }
                else if (pSym != part && isMirrored == true)
                {
                    BDAdjustableLandingGear symGear = pSym.FindModuleImplementing <BDAdjustableLandingGear>();
                    symGear.isMirrored = false;
                    float tiltAngle = Quaternion.Angle(symGear.tiltRetractTargetTransform.localRotation, symGear.tiltTargetTransform.localRotation);

                    tiltTargetTransform.localRotation = tiltRetractTargetTransform.localRotation * Quaternion.AngleAxis(-tiltAngle, Vector3.up);

                    ///wheel angle target stuff
                    float localYrot = isMirrored ? wheelAngle : -wheelAngle;
                    float localZrot = isMirrored && mirrorDeployedWheel ? 180 : 0;
                    deployedWheelTargetTransform.localRotation = Quaternion.Euler(0, localYrot, localZrot);

                    if (wheelHeight < symGear.wheelHeight)
                    {
                        wheelHeight = symGear.wheelHeight;
                    }
                    else
                    {
                        symGear.wheelHeight = wheelHeight;
                    }
                }
            }
            if (CurrentState == GearStates.Deployed || CurrentState == GearStates.Deploying)
            {
                wheelHingeTransform.localRotation = deployedWheelTargetTransform.localRotation;
                tiltTransform.localRotation       = tiltTargetTransform.localRotation;
            }
        }
コード例 #2
0
    public override void OnStart(PartModule.StartState state)
    {
        try
        {
            deploymentStateEnum = (DeploymentStates)Enum.Parse(typeof(DeploymentStates), deploymentState);
        }
        catch
        {
            Debug.Log("FSwheel: Could not set deployment state " + deploymentState);
        }

        #region animation

        anim = part.FindModelAnimators(animationName).FirstOrDefault();
        if (anim != null)
        {
            hasAnimation = true;
            anim[animationName].layer = animationLayer;
            float startAnimTime = 0f;
            if (deploymentStateEnum == DeploymentStates.Retracted)
            {
                startAnimTime = 1f;
                animSpeed     = 1f * customAnimationSpeed;
            }
            else
            {
                animSpeed = -1f * customAnimationSpeed;
            }
            anim[animationName].normalizedTime = startAnimTime;
            anim[animationName].speed          = animSpeed;
            anim.Play(animationName);
        }
        #endregion

        #region In flight
        if (HighLogic.LoadedSceneIsFlight)
        {
            #region create wheel setup
            List <WheelCollider> colliderList   = new List <WheelCollider>();
            List <Transform>     wheelMeshList  = new List <Transform>();
            List <Transform>     suspensionList = new List <Transform>();

            for (int i = 0; i < numberOfWheels; i++)
            {
                string suffix = (i + 1).ToString(); // the names used are e.g. "Wheel", "Wheel2", "Wheel3", to remain compatible with stock wheels
                if (i == 0)
                {
                    suffix = "";
                }
                Transform colliderTransform = part.FindModelTransform(wheelColliderName + suffix);
                if (colliderTransform != null)
                {
                    WheelCollider collider = colliderTransform.GetComponent <WheelCollider>();
                    if (collider != null)
                    {
                        colliderList.Add(collider);
                    }
                }
                else
                {
                    Debug.Log("FSwheel: missing wheel collider " + wheelColliderName + suffix);
                }

                Transform wheelMeshTransform = part.FindModelTransform(wheelMeshName + suffix);
                if (wheelMeshTransform != null)
                {
                    wheelMeshList.Add(wheelMeshTransform);
                }
                else
                {
                    Debug.Log("FSwheel: missing wheel mesh " + wheelMeshName + suffix);
                }

                Transform suspensionTransform = part.FindModelTransform(suspensionParentName + suffix);
                if (suspensionTransform != null)
                {
                    suspensionList.Add(suspensionTransform);
                }
                else
                {
                    Debug.Log("FSwheel: missing suspensionParent " + suspensionParentName + suffix);
                }
            }

            wheelList.Create(colliderList, wheelMeshList, suspensionList);
            if (wheelList != null)
            {
                if (!wheelList.enabled)
                {
                    wheelList.enabled = true;
                }
            }

            // set the motor direction based on the first found wheelColliders orientation
            //Debug.Log("FSwheel: wheelist count is " + wheelList.wheels.Count);
            if (wheelList.wheels.Count > 0)
            {
                Debug.Log("FSwheel: reversemotorset: " + reverseMotorSet);
                if (!reverseMotorSet)                                                                                           //run only the first time the craft is loaded
                {
                    float dot = Vector3.Dot(wheelList.wheels[0].wheelCollider.transform.forward, vessel.ReferenceTransform.up); // up is forward
                    if (dot < 0)                                                                                                // below 0 means the engine is on the left side of the craft
                    {
                        reverseMotor = true;
                        //Debug.Log("FSwheel: Reversing motor, dot: " + dot);
                    }
                    else
                    {
                        reverseMotor = false;
                        //Debug.Log("FSwheel: Motor reversing skipped, dot: " + dot);
                    }
                    if (motorStartsReversed)
                    {
                        reverseMotor = !reverseMotor;
                    }
                    reverseMotorSet = true;
                }
            }

            if (disableColliderWhenRetracted)
            {
                if (deploymentStateEnum == DeploymentStates.Retracted)
                {
                    wheelList.enabled = false;
                }
            }

            //friction override
            if (overrideModelFrictionValues)
            {
                wheelList.forwardStiffness       = forwardsStiffness;
                wheelList.forwardsAsymptoteSlip  = forwardsAsymptoteSlip;
                wheelList.forwardsAsymptoteValue = forwardsAsymptoteValue;
                wheelList.forwardsExtremumSlip   = forwardsExtremumSlip;
                wheelList.forwardsExtremumValue  = forwardsExtremumValue;
                wheelList.sidewaysStiffness      = sidewaysStiffness;
                wheelList.sidewaysAsymptoteSlip  = sidewaysAsymptoteSlip;
                wheelList.sidewaysAsymptoteValue = sidewaysAsymptoteValue;
                wheelList.sidewaysExtremumSlip   = sidewaysExtremumSlip;
                wheelList.sidewaysExtremumValue  = sidewaysExtremumValue;
                wheelList.updateWheelFriction();
            }

            //optionally set collider and spring values
            if ((suspensionSpring >= 0f && suspensionDamper >= 0f && suspensionTargetPosition >= 0f) || overrideModelSpringValues)
            {
                wheelList.updateSpring(suspensionSpring, suspensionDamper, suspensionTargetPosition);
            }
            if (wheelColliderRadius >= 0f)
            {
                wheelList.radius = wheelColliderRadius;
            }
            else
            {
                wheelColliderRadius = wheelList.radius;
            }
            if (wheelColliderMass >= 0f)
            {
                wheelList.mass = wheelColliderMass;
            }
            if (wheelColliderSuspensionDistance >= 0f || overrideSuspensionDistance)
            {
                wheelList.suspensionDistance = wheelColliderSuspensionDistance;
            }
            else
            {
                wheelColliderSuspensionDistance = wheelList.suspensionDistance;
            }

            #endregion

            #region GUI popup

            /*
             * popup = new FSGUIPopup(part, "FSwheel", moduleID, FSGUIwindowID.wheel, new Rect(500f, 300f, 250f, 100f), "Wheel settings", new PopupElement("Suspension Settings:"));
             * popup.useInFlight = true;
             * wheelRadiusElement = new PopupElement("Radius", wheelColliderRadius.ToString());
             * suspensionDistanceElement = new PopupElement("Distance", wheelColliderSuspensionDistance.ToString());
             * suspensionSpringElement = new PopupElement("Spring", suspensionSpring.ToString());
             * suspensionDamperElement = new PopupElement("Damper", suspensionDamper.ToString());
             * suspensionTargetPositionElement = new PopupElement("Target pos", suspensionTargetPosition.ToString());
             * popup.sections[0].elements.Add(wheelRadiusElement);
             * popup.sections[0].elements.Add(suspensionDistanceElement);
             * popup.sections[0].elements.Add(suspensionSpringElement);
             * popup.sections[0].elements.Add(suspensionDamperElement);
             * popup.sections[0].elements.Add(suspensionTargetPositionElement);
             *
             * suspensionUpdateElement = new PopupElement(new PopupButton("Update", 0f, popupUpdateSuspension));
             * popup.sections[0].elements.Add(suspensionUpdateElement);
             */
            #endregion

            if (brakeEmissiveObjectName != string.Empty)
            {
                brakeEmissiveObject = part.FindModelTransform(brakeEmissiveObjectName);
            }
            setBrakeLight(brakesEngaged);

            #region set up fx
            if (useCustomParticleFX)
            {
                smokeFXtexture = GameDatabase.Instance.GetTexture(smokeFXtextureName, false);
                if (smokeFXtexture == null)
                {
                    useCustomParticleFX = false;
                }
                else
                {
                    for (int i = 0; i < wheelList.wheels.Count; i++)
                    {
                        wheelList.wheels[i].smokeFX = new FSBDparticleFX(wheelList.wheels[i].fxLocation, smokeFXtexture);
                        wheelList.wheels[i].smokeFX.AnimatorColor0 = new Color(1.0f, 1.0f, 1.0f, 0.8f);
                        wheelList.wheels[i].smokeFX.AnimatorColor1 = new Color(1.0f, 1.0f, 1.0f, 0.5f);
                        wheelList.wheels[i].smokeFX.AnimatorColor2 = new Color(1.0f, 1.0f, 1.0f, 0.2f);
                        wheelList.wheels[i].smokeFX.AnimatorColor3 = new Color(1.0f, 1.0f, 1.0f, 0.1f);
                        wheelList.wheels[i].smokeFX.AnimatorColor4 = new Color(1.0f, 1.0f, 1.0f, 0.0f);

                        wheelList.wheels[i].smokeFX.EmitterMinSize     = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMaxSize     = 0.5f;
                        wheelList.wheels[i].smokeFX.EmitterMinEnergy   = 0.1f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEnergy   = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMinEmission = 0f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEmission = 0f;
                        wheelList.wheels[i].smokeFX.AnimatorSizeGrow   = 0.1f;

                        wheelList.wheels[i].smokeFX.setupFXValues();
                    }
                }
            }

            #endregion


            //alg
            alg = GetComponent <BDAnimationModules.BDAdjustableLandingGear>();
        }

        #endregion

        #region GUI element changes
        Events["RaiseGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["RaiseGear"].unfocusedRange     = unfocusedRange;

        Events["LowerGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["LowerGear"].unfocusedRange     = unfocusedRange;

        Events["EnableMotorEvent"].guiActive        = !motorEnabled;
        Events["DisableMotorEvent"].guiActive       = motorEnabled;
        Events["EnableMotorEvent"].guiActiveEditor  = !motorEnabled;
        Events["DisableMotorEvent"].guiActiveEditor = motorEnabled;

        Events["brakesOnEvent"].guiActive        = !brakesEngaged;
        Events["brakesOffEvent"].guiActive       = brakesEngaged;
        Events["brakesOnEvent"].guiActiveEditor  = !brakesEngaged;
        Events["brakesOffEvent"].guiActiveEditor = brakesEngaged;

        Events["EnableReverseMotorEvent"].guiActive        = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActive       = reverseMotor;
        Events["EnableReverseMotorEvent"].guiActiveEditor  = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActiveEditor = reverseMotor;

        Events["brakesOnEvent"].guiActiveUnfocused  = guiActiveUnfocused;
        Events["brakesOffEvent"].guiActiveUnfocused = guiActiveUnfocused;

        if (!hasMotor)
        {
            //Events["EnableMotorEvent"].guiActive = false;
            //Events["DisableMotorEvent"].guiActive = false;
            Events["EnableMotorEvent"].active         = false;
            Events["DisableMotorEvent"].active        = false;
            Events["EnableReverseMotorEvent"].active  = false;
            Events["DisableReverseMotorEvent"].active = false;
        }
        if (!hasAnimation)
        {
            Events["RaiseGear"].active = false;
            Events["LowerGear"].active = false;
        }
        if (debugMode)
        {
            Events["increaseFrictionEvent"].guiActive = true;
            Events["decreaseFrictionEvent"].guiActive = true;
            Events["suspensionGUIEvent"].guiActive    = true;
        }

        if (brakesLockedOn)
        {
            Events["brakesOnEvent"].guiActive           = false;
            Events["brakesOffEvent"].guiActive          = false;
            Events["brakesOnEvent"].guiActiveUnfocused  = false;
            Events["brakesOffEvent"].guiActiveUnfocused = false;
        }

        #endregion
    }
コード例 #3
0
    public override void OnStart(PartModule.StartState state)
    {
        try
        {
            deploymentStateEnum = (DeploymentStates)Enum.Parse(typeof(DeploymentStates), deploymentState);
        }
        catch
        {
            Debug.Log("FSwheel: Could not set deployment state " + deploymentState);
        }

        #region animation

        anim = part.FindModelAnimators(animationName).FirstOrDefault();
        if (anim != null)
        {
            hasAnimation = true;
            anim[animationName].layer = animationLayer;
            float startAnimTime = 0f;
            if (deploymentStateEnum == DeploymentStates.Retracted)
            {
                startAnimTime = 1f;
                animSpeed = 1f * customAnimationSpeed;
            }
            else
            {
                animSpeed = -1f * customAnimationSpeed;
            }
            anim[animationName].normalizedTime = startAnimTime;
            anim[animationName].speed = animSpeed;
            anim.Play(animationName);
        }
        #endregion

        #region In flight
        if (HighLogic.LoadedSceneIsFlight)
        {

            #region create wheel setup
            List<WheelCollider> colliderList = new List<WheelCollider>();
            List<Transform> wheelMeshList = new List<Transform>();
            List<Transform> suspensionList = new List<Transform>();

            for (int i = 0; i < numberOfWheels; i++)
            {
                string suffix = (i + 1).ToString(); // the names used are e.g. "Wheel", "Wheel2", "Wheel3", to remain compatible with stock wheels
                if (i == 0)
                    suffix = "";
                Transform colliderTransform = part.FindModelTransform(wheelColliderName + suffix);
                if (colliderTransform != null)
                {
                    WheelCollider collider = colliderTransform.GetComponent<WheelCollider>();
                    if (collider != null)
                    {
                        colliderList.Add(collider);
                    }
                }
                else
                {
                    Debug.Log("FSwheel: missing wheel collider " + wheelColliderName + suffix);
                }

                Transform wheelMeshTransform = part.FindModelTransform(wheelMeshName + suffix);
                if (wheelMeshTransform != null)
                {
                    wheelMeshList.Add(wheelMeshTransform);
                }
                else
                {
                    Debug.Log("FSwheel: missing wheel mesh " + wheelMeshName + suffix);
                }

                Transform suspensionTransform = part.FindModelTransform(suspensionParentName + suffix);
                if (suspensionTransform != null)
                {
                    suspensionList.Add(suspensionTransform);
                }
                else
                {
                    Debug.Log("FSwheel: missing suspensionParent " + suspensionParentName + suffix);
                }

            }

            wheelList.Create(colliderList, wheelMeshList, suspensionList);
            if (wheelList != null)
            {
                if (!wheelList.enabled)
                {
                    wheelList.enabled = true;
                }
            }

            // set the motor direction based on the first found wheelColliders orientation
            //Debug.Log("FSwheel: wheelist count is " + wheelList.wheels.Count);
            if (wheelList.wheels.Count > 0)
            {
                Debug.Log("FSwheel: reversemotorset: " + reverseMotorSet);
                if (!reverseMotorSet) //run only the first time the craft is loaded
                {
                    float dot = Vector3.Dot(wheelList.wheels[0].wheelCollider.transform.forward, vessel.ReferenceTransform.up); // up is forward
                    if (dot < 0) // below 0 means the engine is on the left side of the craft
                    {
                        reverseMotor = true;
                        //Debug.Log("FSwheel: Reversing motor, dot: " + dot);
                    }
                    else
                    {
                        reverseMotor = false;
                        //Debug.Log("FSwheel: Motor reversing skipped, dot: " + dot);
                    }
                    if (motorStartsReversed)
                        reverseMotor = !reverseMotor;
                    reverseMotorSet = true;
                }
            }

            if (disableColliderWhenRetracted)
            {
                if (deploymentStateEnum == DeploymentStates.Retracted)
                {
                    wheelList.enabled = false;
                }
            }

            //friction override
            if (overrideModelFrictionValues)
            {
                wheelList.forwardStiffness = forwardsStiffness;
                wheelList.forwardsAsymptoteSlip = forwardsAsymptoteSlip;
                wheelList.forwardsAsymptoteValue = forwardsAsymptoteValue;
                wheelList.forwardsExtremumSlip = forwardsExtremumSlip;
                wheelList.forwardsExtremumValue = forwardsExtremumValue;
                wheelList.sidewaysStiffness = sidewaysStiffness;
                wheelList.sidewaysAsymptoteSlip = sidewaysAsymptoteSlip;
                wheelList.sidewaysAsymptoteValue = sidewaysAsymptoteValue;
                wheelList.sidewaysExtremumSlip = sidewaysExtremumSlip;
                wheelList.sidewaysExtremumValue = sidewaysExtremumValue;
                wheelList.updateWheelFriction();
            }

            //optionally set collider and spring values
            if ((suspensionSpring >= 0f && suspensionDamper >= 0f && suspensionTargetPosition >= 0f) || overrideModelSpringValues)
            {
                wheelList.updateSpring(suspensionSpring, suspensionDamper, suspensionTargetPosition);
            }
            if (wheelColliderRadius >= 0f) wheelList.radius = wheelColliderRadius;
            else
                wheelColliderRadius = wheelList.radius;
            if (wheelColliderMass >= 0f) wheelList.mass = wheelColliderMass;
            if (wheelColliderSuspensionDistance >= 0f || overrideSuspensionDistance) wheelList.suspensionDistance = wheelColliderSuspensionDistance;
            else
                wheelColliderSuspensionDistance = wheelList.suspensionDistance;

            #endregion

            #region GUI popup
            /*
            popup = new FSGUIPopup(part, "FSwheel", moduleID, FSGUIwindowID.wheel, new Rect(500f, 300f, 250f, 100f), "Wheel settings", new PopupElement("Suspension Settings:"));
            popup.useInFlight = true;
            wheelRadiusElement = new PopupElement("Radius", wheelColliderRadius.ToString());
            suspensionDistanceElement = new PopupElement("Distance", wheelColliderSuspensionDistance.ToString());
            suspensionSpringElement = new PopupElement("Spring", suspensionSpring.ToString());
            suspensionDamperElement = new PopupElement("Damper", suspensionDamper.ToString());
            suspensionTargetPositionElement = new PopupElement("Target pos", suspensionTargetPosition.ToString());
            popup.sections[0].elements.Add(wheelRadiusElement);
            popup.sections[0].elements.Add(suspensionDistanceElement);
            popup.sections[0].elements.Add(suspensionSpringElement);
            popup.sections[0].elements.Add(suspensionDamperElement);
            popup.sections[0].elements.Add(suspensionTargetPositionElement);

            suspensionUpdateElement = new PopupElement(new PopupButton("Update", 0f, popupUpdateSuspension));
            popup.sections[0].elements.Add(suspensionUpdateElement);
             */
            #endregion

            if (brakeEmissiveObjectName != string.Empty)
            {
                brakeEmissiveObject = part.FindModelTransform(brakeEmissiveObjectName);
            }
            setBrakeLight(brakesEngaged);

            #region set up fx
            if (useCustomParticleFX)
            {
                smokeFXtexture = GameDatabase.Instance.GetTexture(smokeFXtextureName, false);
                if (smokeFXtexture == null)
                {
                    useCustomParticleFX = false;
                }
                else
                {
                    for (int i = 0; i < wheelList.wheels.Count; i++)
                    {
                        wheelList.wheels[i].smokeFX = new FSBDparticleFX(wheelList.wheels[i].fxLocation, smokeFXtexture);
                        wheelList.wheels[i].smokeFX.AnimatorColor0 = new Color(1.0f, 1.0f, 1.0f, 0.8f);
                        wheelList.wheels[i].smokeFX.AnimatorColor1 = new Color(1.0f, 1.0f, 1.0f, 0.5f);
                        wheelList.wheels[i].smokeFX.AnimatorColor2 = new Color(1.0f, 1.0f, 1.0f, 0.2f);
                        wheelList.wheels[i].smokeFX.AnimatorColor3 = new Color(1.0f, 1.0f, 1.0f, 0.1f);
                        wheelList.wheels[i].smokeFX.AnimatorColor4 = new Color(1.0f, 1.0f, 1.0f, 0.0f);

                        wheelList.wheels[i].smokeFX.EmitterMinSize = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMaxSize = 0.5f;
                        wheelList.wheels[i].smokeFX.EmitterMinEnergy = 0.1f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEnergy = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMinEmission = 0f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEmission = 0f;
                        wheelList.wheels[i].smokeFX.AnimatorSizeGrow = 0.1f;

                        wheelList.wheels[i].smokeFX.setupFXValues();
                    }
                }
            }

            #endregion

            //alg
            alg = GetComponent<BDAnimationModules.BDAdjustableLandingGear>();

        }

        #endregion

        #region GUI element changes
        Events["RaiseGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["RaiseGear"].unfocusedRange = unfocusedRange;

        Events["LowerGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["LowerGear"].unfocusedRange = unfocusedRange;

        Events["EnableMotorEvent"].guiActive = !motorEnabled;
        Events["DisableMotorEvent"].guiActive = motorEnabled;
        Events["EnableMotorEvent"].guiActiveEditor = !motorEnabled;
        Events["DisableMotorEvent"].guiActiveEditor = motorEnabled;

        Events["brakesOnEvent"].guiActive = !brakesEngaged;
        Events["brakesOffEvent"].guiActive = brakesEngaged;
        Events["brakesOnEvent"].guiActiveEditor = !brakesEngaged;
        Events["brakesOffEvent"].guiActiveEditor = brakesEngaged;

        Events["EnableReverseMotorEvent"].guiActive = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActive = reverseMotor;
        Events["EnableReverseMotorEvent"].guiActiveEditor = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActiveEditor = reverseMotor;

        Events["brakesOnEvent"].guiActiveUnfocused = guiActiveUnfocused;
        Events["brakesOffEvent"].guiActiveUnfocused = guiActiveUnfocused;

        if (!hasMotor)
        {
            //Events["EnableMotorEvent"].guiActive = false;
            //Events["DisableMotorEvent"].guiActive = false;
            Events["EnableMotorEvent"].active = false;
            Events["DisableMotorEvent"].active = false;
            Events["EnableReverseMotorEvent"].active = false;
            Events["DisableReverseMotorEvent"].active = false;
        }
        if (!hasAnimation)
        {
            Events["RaiseGear"].active = false;
            Events["LowerGear"].active = false;
        }
        if (debugMode)
        {
            Events["increaseFrictionEvent"].guiActive = true;
            Events["decreaseFrictionEvent"].guiActive = true;
            Events["suspensionGUIEvent"].guiActive = true;
        }

        if (brakesLockedOn)
        {
            Events["brakesOnEvent"].guiActive = false;
            Events["brakesOffEvent"].guiActive = false;
            Events["brakesOnEvent"].guiActiveUnfocused = false;
            Events["brakesOffEvent"].guiActiveUnfocused = false;
        }

        #endregion
    }