Exemplo n.º 1
0
 /// <summary>Detects the DustFX component, or adds it if not detected on the part.</summary>
 /// <param name="state">Current state of the simulation.</param>
 void SetupDust(PartModule.StartState state)
 {
     if (isDustEnabled)
     {
         _dustFX = part.GetComponent <KFDustFX>();
         if (Equals(_dustFX, null))
         {
             _dustFX            = part.gameObject.AddComponent <KFDustFX>();
             _dustFX.isRepulsor = true;
             _dustFX.OnStart(state);
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>Detects the DustFX component, or adds it if not detected on the part.</summary>
 /// <param name="state">Current state of the simulation.</param>
 void SetupDust(PartModule.StartState state)
 {
     _dustFX = part.GetComponent<KFDustFX>();
     if (Equals(_dustFX, null))
     {
         _dustFX = part.gameObject.AddComponent<KFDustFX>();
         _dustFX.isRepulsor = true;
         _dustFX.OnStart(state);
     }
 }
Exemplo n.º 3
0
        //when started
        /// <summary>Configures the part for editor and flight.</summary>
        /// <remarks>
        /// Most importantly, it grabs a list of wheel colliders to be
        /// used later. Also configures visibility of tweakables, figures
        /// out the parts orientation and position in the vessel to calculate
        /// steering angles and sets some defaults.
        /// </remarks>
        /// <param name="state">Start state. Set by KSP to declare the scene it initializes this class in.</param>
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);

            susInc = KFPersistenceManager.suspensionIncrement;

            CustomResourceTextSetup();

            _colliderMass = 10;

            var partOrientationForward = new Vector3(0f, 0f, 0f);
            var partOrientationRight = new Vector3(0f, 0f, 0f);
            var partOrientationUp = new Vector3(0f, 0f, 0f);

            if (!string.Equals(orientationObjectName, "Default"))
            {
                #if DEBUG
                KFLog.Warning("Setting transformed part orientation.");
                #endif

                partOrientationUp = transform.Search(orientationObjectName).up;
                partOrientationForward = transform.Search(orientationObjectName).forward;
                partOrientationRight = transform.Search(orientationObjectName).right;
            }
            else
            {
                #if DEBUG
                KFLog.Warning("Setting default part orientation.");
                #endif

                partOrientationUp = part.transform.up;
                partOrientationForward = part.transform.forward;
                partOrientationRight = part.transform.right;
            }

            if (hasRetractAnimation)
            {
                foreach (ModuleAnimateGeneric ma in part.FindModulesImplementing<ModuleAnimateGeneric>())
                {
                    ma.Actions["ToggleAction"].active = false;
                    ma.Events["Toggle"].guiActive = false;
                    ma.Events["Toggle"].guiActiveEditor = false;
                }
                SetupAnimation();
            }

            //disables tweakables if being used on a passive part (mecannum wheel or skid, for example)
            if (disableTweakables)
            {
                KFLog.Warning("Disabling tweakables.");
                foreach (BaseField k in Fields)
                {
                    #if DEBUG
                    KFLog.Log(string.Format("Found {0}", k.guiName));
                    #endif

                    k.guiActive = false;
                    k.guiActiveEditor = false;
                }
                foreach (BaseAction a in Actions)
                {
                    #if DEBUG
                    KFLog.Log(string.Format("Found {0}", a.guiName));
                    #endif

                    a.active = false;
                }
                foreach (BaseEvent e in Events)
                {
                    #if DEBUG
                    KFLog.Log(string.Format("Found {0}", e.guiName));
                    #endif

                    e.active = false;
                }
            }

            if (startRetracted)
                isRetracted = true;

            if (!isRetracted)
                currentTravel = rideHeight; //set up correct values from persistence
            else
                currentTravel = 0f;

            #if DEBUG
            KFLog.Log(string.Format("\"appliedRideHeight\" = {0}", appliedRideHeight));
            #endif

            // Disable retract tweakables if retract option not specified.
            if (HighLogic.LoadedSceneIsEditor && !hasRetract)
            {
                part.DisableAnimateButton();
                Actions["AGToggleDeployed"].active = false;
                Actions["Deploy"].active = false;
                Actions["Retract"].active = false;
                Fields["startRetracted"].guiActiveEditor = false;
            }

            if (HighLogic.LoadedSceneIsFlight && (!Equals(vessel.vesselType, VesselType.Debris) && !Equals(vessel.vesselType, VesselType.EVA)))
            {
                _dustFX = part.gameObject.GetComponent<KFDustFX>();
                if (Equals(_dustFX, null))
                {
                    _dustFX = part.gameObject.AddComponent<KFDustFX>();
                    _dustFX.OnStart(state);
                    _dustFX.tweakScaleFactor = tweakScaleCorrector;
                }

                appliedTravel = rideHeight / 100f;
                StartCoroutine(StartupStuff());
                maxRPM /= tweakScaleCorrector;
                startRetracted = false;
                if (!hasRetract)
                    part.DisableAnimateButton();

                // Wheel steering ratio setup
                rootIndexLong = WheelUtils.GetRefAxis(part.transform.forward, vessel.rootPart.transform);
                rootIndexLat = WheelUtils.GetRefAxis(part.transform.right, vessel.rootPart.transform);
                rootIndexUp = WheelUtils.GetRefAxis(part.transform.up, vessel.rootPart.transform);

                steeringRatio = WheelUtils.SetupRatios(rootIndexLong, part, vessel, groupNumber);
                GetControlAxis();

                if (torque > 2f)
                    torque /= 100f;

                wheelCount = 0;

                foreach (WheelCollider wheelCollider in part.GetComponentsInChildren<WheelCollider>())
                {
                    wheelCount++;
                    JointSpring userSpring = wheelCollider.suspensionSpring;
                    userSpring.spring = springRate * tweakScaleCorrector;
                    userSpring.damper = damperRate * tweakScaleCorrector;
                    wheelCollider.suspensionSpring = userSpring;
                    wheelCollider.suspensionDistance = wheelCollider.suspensionDistance * appliedTravel;
                    wcList.Add(wheelCollider);
                    suspensionDistance.Add(wheelCollider.suspensionDistance);
                    wheelCollider.enabled = true;
                    wheelCollider.gameObject.layer = 27;
                }

                if (brakesApplied)
                    brakeTorque = brakingTorque; // Were the brakes left applied?

                if (isRetracted)
                    RetractDeploy("retract");
                isReady = true;
            }
            DestroyBounds();
            SetupWaterSlider();
        }
Exemplo n.º 4
0
        /// <summary>Configures the part for editor and flight.</summary>
        /// <remarks>
        /// Most importantly, it grabs a list of wheel colliders to be
        /// used later. Also configures visibility of tweakables, figures
        /// out the parts orientation and position in the vessel to calculate
        /// steering angles and sets some defaults.
        /// </remarks>
        /// <param name="state">Start state. Set by KSP to declare the scene it initializes this class in.</param>
        public override void OnStart(PartModule.StartState state)          //when started
        {
            base.OnStart(state);

            fSusInc = KFPersistenceManager.suspensionIncrement;

            CustomResourceTextSetup();

            fColliderMass = 10;

            var partOrientationForward = new Vector3(0f, 0f, 0f);
            var partOrientationRight   = new Vector3(0f, 0f, 0f);
            var partOrientationUp      = new Vector3(0f, 0f, 0f);

            if (!string.Equals(orientationObjectName, "Default"))
            {
                                #if DEBUG
                KFLog.Warning("Setting transformed part orientation.");
                                #endif

                partOrientationUp      = transform.Search(orientationObjectName).up;
                partOrientationForward = transform.Search(orientationObjectName).forward;
                partOrientationRight   = transform.Search(orientationObjectName).right;
            }
            else
            {
                                #if DEBUG
                KFLog.Warning("Setting default part orientation.");
                                #endif

                partOrientationUp      = part.transform.up;
                partOrientationForward = part.transform.forward;
                partOrientationRight   = part.transform.right;
            }

            if (hasRetractAnimation)
            {
                foreach (ModuleAnimateGeneric ma in part.FindModulesImplementing <ModuleAnimateGeneric>())
                {
                    ma.Actions["ToggleAction"].active   = false;
                    ma.Events["Toggle"].guiActive       = false;
                    ma.Events["Toggle"].guiActiveEditor = false;
                }
                SetupAnimation();
            }

            //disables tweakables if being used on a passive part (mecannum wheel or skid, for example)
            if (disableTweakables)
            {
                KFLog.Warning("Disabling tweakables.");
                foreach (BaseField k in Fields)
                {
                                        #if DEBUG
                    KFLog.Log(string.Format("Found {0}", k.guiName));
                                        #endif

                    k.guiActive       = false;
                    k.guiActiveEditor = false;
                }
                foreach (BaseAction a in Actions)
                {
                                        #if DEBUG
                    KFLog.Log(string.Format("Found {0}", a.guiName));
                                        #endif

                    a.active = false;
                }
                foreach (BaseEvent e in Events)
                {
                                        #if DEBUG
                    KFLog.Log(string.Format("Found {0}", e.guiName));
                                        #endif

                    e.active = false;
                }
            }

            if (fStartRetracted)
            {
                isRetracted = true;
            }

            if (!isRetracted)
            {
                fCurrentTravel = fRideHeight;                 //set up correct values from persistence
            }
            else
            {
                fCurrentTravel = 0f;
            }

                        #if DEBUG
            KFLog.Log(string.Format("\"appliedRideHeight\" = {0}", appliedRideHeight));
                        #endif

            // Disable retract tweakables if retract option not specified.
            if (HighLogic.LoadedSceneIsEditor && !hasRetract)
            {
                part.DisableAnimateButton();
                Actions["AGToggleDeployed"].active       = false;
                Actions["Deploy"].active                 = false;
                Actions["Retract"].active                = false;
                Fields["startRetracted"].guiActiveEditor = false;
            }

            if (HighLogic.LoadedSceneIsFlight && (!Equals(vessel.vesselType, VesselType.Debris) && !Equals(vessel.vesselType, VesselType.EVA)))
            {
                if (isDustEnabled)
                {
                    _dustFX = part.gameObject.GetComponent <KFDustFX>();
                    if (Equals(_dustFX, null))
                    {
                        _dustFX = part.gameObject.AddComponent <KFDustFX>();
                        _dustFX.OnStart(state);
                        _dustFX.tweakScaleFactor = tweakScaleCorrector;
                    }
                }

                fAppliedTravel = fRideHeight / 100f;
                StartCoroutine(StartupStuff());
                maxRPM         /= tweakScaleCorrector;
                fStartRetracted = false;
                if (!hasRetract)
                {
                    part.DisableAnimateButton();
                }

                // Wheel steering ratio setup
                rootIndexLong = WheelUtils.GetRefAxis(part.transform.forward, vessel.rootPart.transform);
                rootIndexLat  = WheelUtils.GetRefAxis(part.transform.right, vessel.rootPart.transform);
                rootIndexUp   = WheelUtils.GetRefAxis(part.transform.up, vessel.rootPart.transform);

                fSteeringRatio = WheelUtils.SetupRatios(rootIndexLong, part, vessel, fGroupNumber);
                GetControlAxis();

                if (fTorque > 2f)
                {
                    fTorque /= 100f;
                }

                wheelCount = 0;

                foreach (WheelCollider wheelCollider in part.GetComponentsInChildren <WheelCollider>())
                {
                    wheelCount++;
                    JointSpring userSpring = wheelCollider.suspensionSpring;
                    userSpring.spring = fSpringRate * tweakScaleCorrector;
                    userSpring.damper = fDamperRate * tweakScaleCorrector;
                    wheelCollider.suspensionSpring   = userSpring;
                    wheelCollider.suspensionDistance = wheelCollider.suspensionDistance * fAppliedTravel;
                    wcList.Add(wheelCollider);
                    suspensionDistance.Add(wheelCollider.suspensionDistance);
                    wheelCollider.enabled          = true;
                    wheelCollider.gameObject.layer = 27;
                }

                if (brakesApplied)
                {
                    fBrakeTorque = brakingTorque;                     // Were the brakes left applied?
                }
                if (isRetracted)
                {
                    RetractDeploy("retract");
                }
                isReady = true;
            }
            DestroyBounds();
            SetupWaterSlider();

            GameEvents.onGamePause.Add(OnPause);
            GameEvents.onGameUnpause.Add(OnUnpause);
        }