public void SetupObjects() { #if DEBUG KFLog.Log("Setting up objects."); #endif rotators.Clear(); targets.Clear(); for (int i = 0; i < rotatorList.Count(); i++) { rotators.Add(transform.SearchStartsWith(rotatorList[i])); #if DEBUG KFLog.Log(string.Format("Iterated rotators: {0}", rotatorList.Count())); #endif } for (int i = 0; i < targetList.Count(); i++) { targets.Add(transform.SearchStartsWith(targetList[i])); #if DEBUG KFLog.Log(string.Format("Iterated targets: {0}", targetList.Count())); #endif } objectCount = rotators.Count(); countAgrees |= Equals(objectCount, targets.Count()); }
/// <summary> /// Called when the ApplicationLauncher is unreadifying, just before a scene switch. /// </summary> /// <param name="data"></param> void OnGUIUnready(GameScenes data) { if (KFPersistenceManager.isGUIEnabled) { #if DEBUG KFLog.Log("OnGUIUnready()"); #endif DestroyAppButton(); } }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); if (HighLogic.LoadedSceneIsEditor) { foreach (ModuleAnimateGeneric ma in part.FindModulesImplementing <ModuleAnimateGeneric>()) { ma.Actions["ToggleAction"].active = false; ma.Events["Toggle"].guiActive = false; ma.Events["Toggle"].guiActiveEditor = false; } } if (HighLogic.LoadedSceneIsFlight) { #if DEBUG KFLog.Log("Repulsor Wheel started"); #endif foreach (ModuleAnimateGeneric ma in part.FindModulesImplementing <ModuleAnimateGeneric>()) { ma.Events["Toggle"].guiActive = false; } _moduleWheel = part.GetComponentInChildren <KFModuleWheel>(); _moduleWheel.Events["ApplySettings"].guiActive = false; foreach (WheelCollider wc in part.GetComponentsInChildren <WheelCollider>()) { wcList.Add(wc); } for (int i = 0; i < wcList.Count(); i++) { wfForwardList.Add(wcList[i].forwardFriction.stiffness); wfSideList.Add(wcList[i].sidewaysFriction.stiffness); susDistList.Add(wcList[i].suspensionDistance); } if (repulsorMode) { UpdateColliders("repulsor"); } if (!repulsorMode) { UpdateColliders("wheel"); } effectPowerMax = resourceConsumptionRate * Time.deltaTime; KFLog.Log(string.Format("\"effectPowerMax\" = {0}", effectPowerMax)); } }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); isDeployed = true; if ((Equals(resourceName, "none") || Equals(resourceConsumptionRate, 0f)) && usesResources) { usesResources = false; } fSusInc = KFPersistenceManager.suspensionIncrement; if (HighLogic.LoadedSceneIsFlight && (!Equals(vessel.vesselType, VesselType.Debris) && !Equals(vessel.vesselType, VesselType.EVA))) { _grid = transform.Search(gridName); _gridScale = _grid.transform.localScale; _gimbal = transform.Search(gimbalName); foreach (WheelCollider foundCollider in part.GetComponentsInChildren <WheelCollider>()) { fAttractorCount++; userspring = foundCollider.suspensionSpring; userspring.spring = springRate; userspring.damper = damperRate; foundCollider.suspensionSpring = userspring; foundCollider.suspensionDistance = 2.5f; wcList.Add(foundCollider); } #if DEBUG KFLog.Log(string.Format("Repulsor Count: {0}", repulsorCount)); #endif if (pointDown) { StopAllCoroutines(); StartCoroutine("LookAt"); } fAppliedRideHeight = fRideHeight; StartCoroutine("UpdateHeight"); SetupDust(state); SetupWaterSlider(); isReady = true; } DestroyBounds(); GameEvents.onGamePause.Add(OnPause); GameEvents.onGameUnpause.Add(OnUnpause); }
/// <summary>Takes a vector (usually from a parts axis) and a transform, plus an index giving which axis to use for the scalar product of the two.</summary> /// <param name="transformVector">Vector of the transform.</param> /// <param name="referenceVector">Reference vector.</param> /// <param name="directionIndex">Direction index.</param> /// <returns>A value of -1 or 1, depending on whether the product is positive or negative.</returns> public static int GetCorrector(Vector3 transformVector, Transform referenceVector, int directionIndex) { int corrector = 1; float dot = 0; switch (directionIndex) { case 0: dot = Vector3.Dot(transformVector, referenceVector.right); break; case 1: dot = Vector3.Dot(transformVector, referenceVector.up); break; case 2: dot = Vector3.Dot(transformVector, referenceVector.forward); break; } #if DEBUG KFLog.Log(string.Format("\"dot\" = {0}", dot)); #endif corrector = dot < 0 ? -1 : 1; return(corrector); }
/// <summary>Finds all KF parts which part icons need to be fixed</summary> /// <returns>List of parts with KFIconOverride configNode</returns> List <AvailablePart> FindKFPartsToFix() { List <AvailablePart> KFPartsList = PartLoader.LoadedPartsList.FindAll(IsAKFPart); #if DEBUG KFLog.Log("\nAll KF Parts:"); KFPartsList.ForEach(part => KFLog.Log(string.Format(" {0}", part.name))); #endif List <AvailablePart> KFPartsToFixList = KFPartsList.FindAll(HasKFIconOverrideModule); #if DEBUG KFLog.Log("\nKF Parts which need an icon fix:"); KFPartsToFixList.ForEach(part => KFLog.Log(string.Format(" {0}", part.name))); #endif return(KFPartsToFixList); }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); bPrecisionModeActive = false; _KFModuleWheel = part.GetComponent <KFModuleWheel>(); originalSmoothSpeed = _KFModuleWheel.smoothSpeed; appliedSmoothSpeed = originalSmoothSpeed; originalResourceConsumption = _KFModuleWheel.resourceConsumptionRate; appliedResourceConsumption = originalResourceConsumption; #if DEBUG KFLog.Log(string.Format("Original Smooth Speed = {0}", originalSmoothSpeed)); KFLog.Log(string.Format("Boosted Smooth Speed = {0}", (originalSmoothSpeed * smoothSpeedMult))); #endif }
/// <summary>Makes sure the global configuration is good to go.</summary> /// <remarks>This is a static constructor. It's called once when the class is loaded by Mono.</remarks> static KFPersistenceManager() { writeToLogFile = false; // This makes sure that the logging thread can't start before all of the configuration is read or bad things will happen. KFLogInit = new KFLogUtil(); KFLogInit.Log(string.Format("Version: {0}", KFVersion.versionString)); ReadConfigFile(); ReadDustColor(); }
/// <summary>Makes sure the global configuration is good to go.</summary> /// <remarks>This is a static constructor. It's called once when the class is loaded by Mono.</remarks> static KFPersistenceManager() { writeToLogFile = false; // This makes sure that the logging thread can't start before all of the configuration is read or bad things will happen KFLog = new KFLogUtil(strClassName); KFLogInit = new KFLogUtil(); KFLogInit.Log(string.Format("Version: {0}", KFVersion.versionString)); ReadConfigFile(); ReadDustColor(); }
public override void OnStart(PartModule.StartState state) { if (!HighLogic.LoadedSceneIsFlight || (Equals(vessel.vesselType, VesselType.Debris) || Equals(vessel.vesselType, VesselType.EVA))) { return; } #if DEBUG KFLog.Log("ModulePropeller called."); #endif _KFModuleWheel = part.GetComponentInChildren <KFModuleWheel>(); base.OnStart(state); }
public void StartUp() { #if DEBUG KFLog.Warning("ModuleCamerashot Start"); #endif if (!Equals(KFPersistenceManager.cameraRes, null)) { fResWidth = KFPersistenceManager.cameraRes; fResHeight = KFPersistenceManager.cameraRes; } if (!Equals(KFPersistenceManager.cameraFramerate, null)) { fFrameThreshHold = KFPersistenceManager.cameraFramerate; } _vessel = GetComponent <Vessel>(); foreach (Part PA in _vessel.parts) { // disable UnusedVariable.Compiler foreach (KFRepulsor RA in PA.GetComponentsInChildren <KFRepulsor>()) { kFPartCount++; } foreach (KFModuleWheel RA in PA.GetComponentsInChildren <KFModuleWheel>()) { kFPartCount++; } } if (kFPartCount > 1) { #if DEBUG KFLog.Log("Starting camera"); #endif _cameraObject = new GameObject("ColourCam"); _cameraObject.transform.parent = _vessel.transform; _cameraObject.transform.LookAt(_vessel.mainBody.transform.position); _cameraObject.transform.Translate(new Vector3(0, 0, -10)); _camera = _cameraObject.AddComponent <Camera>(); _camera.targetTexture = renderTexture; _camera.cullingMask = cameraMask; _camera.enabled = false; renderTexture = new RenderTexture(Convert.ToInt32(fResWidth), Convert.ToInt32(fResHeight), 24); groundShot = new Texture2D(Convert.ToInt32(fResWidth), Convert.ToInt32(fResHeight), TextureFormat.RGB24, false); dustCamEnabled = KFPersistenceManager.isDustCameraEnabled; isReady = true; } }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); #if DEBUG KFLog.Log(string.Format("{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version)); #endif FindEngine(); if (HighLogic.LoadedSceneIsFlight) { part.force_activate(); } }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); Transform destroyedObject = transform.Search(objectName); if (!Equals(destroyedObject, null)) { UnityEngine.Object.Destroy(destroyedObject.gameObject); #if DEBUG KFLog.Log(string.Format("Destroying: {0}", objectName)); #endif } else { KFLog.Warning(string.Format("Could not find object named \"{0}\" to destroy.", objectName)); } }
public void StartUp() { #if DEBUG KFLog.Log("WaterSlider start."); #endif _vessel = GetComponent <Vessel>(); _collider = new GameObject("KFModuleWaterSlider.Collider"); waterSliderSurface = GameObject.CreatePrimitive(PrimitiveType.Cube); waterSliderSurface.transform.parent = _collider.transform; waterSliderSurface.transform.localScale = boxSize; waterSliderSurface.renderer.enabled = KFPersistenceManager.isWaterColliderVisible; var box = (BoxCollider)_collider.AddComponent("BoxCollider"); box.size = boxSize; var rb = (Rigidbody)_collider.AddComponent("Rigidbody"); rb.rigidbody.isKinematic = true; _collider.SetActive(true); UpdatePosition(); isReady = true; }
public override void OnStart(PartModule.StartState state) { _KFModuleWheel = part.GetComponentInChildren <KFModuleWheel>(); tweakScaleCorrector = _KFModuleWheel.tweakScaleCorrector; if (!isConfigured) { foreach (WheelCollider wc in part.GetComponentsInChildren <WheelCollider>()) { if (wc.name.StartsWith(colliderName, StringComparison.Ordinal)) { _wheelCollider = wc; fSuspensionDistance = wc.suspensionDistance; #if DEBUG KFLog.Log(string.Format("SuspensionDistance is: {0}.", suspensionDistance)); #endif isConfigured = true; } } } if (HighLogic.LoadedSceneIsFlight && !Equals(vessel.vesselType, VesselType.Debris)) { GameEvents.onGamePause.Add(new EventVoid.OnEvent(OnPause)); GameEvents.onGameUnpause.Add(new EventVoid.OnEvent(OnUnPause)); // Find named onjects in part. foreach (WheelCollider wc in part.GetComponentsInChildren <WheelCollider>()) { if (wc.name.StartsWith(colliderName, StringComparison.Ordinal)) { _wheelCollider = wc; } } foreach (Transform tr in part.GetComponentsInChildren <Transform>()) { if (tr.name.StartsWith(wheelName, StringComparison.Ordinal)) { _wheel = tr; } if (tr.name.StartsWith(steeringName, StringComparison.Ordinal)) { _trackSteering = tr; } if (tr.name.StartsWith(sustravName, StringComparison.Ordinal)) { _susTrav = tr; } } initialPosition = _susTrav.localPosition; susTravIndex = susTravAxis.SetAxisIndex(); steeringIndex = steeringAxis.SetAxisIndex(); if (_KFModuleWheel.hasSteering) { initialSteeringAngles = _trackSteering.transform.localEulerAngles; #if DEBUG KFLog.Log(string.Format("initial steering angles are \"{0}\"", initialSteeringAngles)); #endif } directionCorrector = useDirectionCorrector ? _KFModuleWheel.directionCorrector : 1; _wheelRotation = new Vector3(wheelRotationX, wheelRotationY, wheelRotationZ); if (Equals(lastFrameTraverse, 0)) //check to see if we have a value in persistance { #if DEBUG KFLog.Log("Last frame = 0. Setting suspension distance."); #endif lastFrameTraverse = _wheelCollider.suspensionDistance; } #if DEBUG KFLog.Log(string.Format("Last frame = {0}", lastFrameTraverse)); #endif couroutinesActive = true; MoveSuspension(susTravIndex, -lastFrameTraverse, _susTrav); //to get the initial stuff correct if (_KFModuleWheel.hasSteering) { StartCoroutine("Steering"); #if DEBUG KFLog.Log("Starting steering coroutine."); #endif } if (trackedWheel) { StartCoroutine("TrackedWheel"); } else { StartCoroutine("IndividualWheel"); } if (hasSuspension) { KFLog.Warning("KFWheel suspension module is deprecated. Please use KFSuspension."); StartCoroutine("Suspension"); } part.force_activate(); } base.OnStart(state); }
/// <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); }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); leftList = leftObjectName.Split(new[] { ',', ' ', '|' }, StringSplitOptions.RemoveEmptyEntries); //Thanks, Mihara! rightList = rightObjectName.Split(new[] { ',', ' ', '|' }, StringSplitOptions.RemoveEmptyEntries); #if DEBUG KFLog.Log(string.Format("{0} {1}", leftList[0], leftList.Count())); KFLog.Log(string.Format("{0} {1}", rightList[0], rightList.Count())); #endif for (int i = 0; i < leftList.Count(); i++) { leftObject.Add(transform.Search(leftList[i])); #if DEBUG KFLog.Log(string.Format("Iterated left: {0}", i)); #endif } for (int i = 0; i < rightList.Count(); i++) { rightObject.Add(transform.Search(rightList[i])); #if DEBUG KFLog.Log(string.Format("Iterated right: {0}", i)); #endif } #if DEBUG KFLog.Log("Loaded scene is editor."); KFLog.Log(string.Format("\"flightside\" = {0}", flightSide)); #endif FindClone(); if (!Equals(clone, null)) { #if DEBUG KFLog.Log("Part is clone."); #endif SetSide(clone.cloneSide); } if (Equals(flightSide, string.Empty)) { #if DEBUG KFLog.Log(string.Format("No flightSide value in persistence. Sertting default: {0}", part.isClone)); #endif LeftSide(); } else { #if DEBUG KFLog.Log("Setting value from persistence."); #endif SetSide(flightSide); } if (HighLogic.LoadedSceneIsFlight) // do this last. { #if DEBUG KFLog.Log("Loaded scene is flight."); #endif if (Equals(flightSide, LEFT)) { for (int i = 0; i < rightObject.Count(); i++) { #if DEBUG KFLog.Log(string.Format("Destroying Right object: {0}", rightList[i])); #endif leftObject[i].gameObject.SetActive(true); UnityEngine.Object.DestroyImmediate(rightObject[i].gameObject); } } if (Equals(flightSide, RIGHT)) { for (int i = 0; i < leftObject.Count(); i++) { #if DEBUG KFLog.Log(string.Format("Destroying left object: {0}", leftList[i])); #endif rightObject[i].gameObject.SetActive(true); UnityEngine.Object.DestroyImmediate(leftObject[i].gameObject); } } } }
static void LogConfigValues() { KFLog.Log("Configuration Settings are:"); KFLog.Log(string.Format(" isDustEnabled = {0}", isDustEnabled)); KFLog.Log(string.Format(" isDustCameraEnabled = {0}", isDustCameraEnabled)); KFLog.Log(string.Format(" isMarkerEnabled = {0}", isMarkerEnabled)); KFLog.Log(string.Format(" isRepLightEnabled = {0}", isRepLightEnabled)); KFLog.Log(string.Format(" dustamount = {0}", dustAmount)); KFLog.Log(string.Format(" suspensionIncrement = {0}", suspensionIncrement)); KFLog.Log(string.Format(" isDebugEnabled = {0}", isDebugEnabled)); KFLog.Log(string.Format(" debugIsWaterColliderVisible = {0}", isWaterColliderVisible)); KFLog.Log(string.Format(" cameraRes = {0}", cameraRes)); KFLog.Log(string.Format(" cameraFramerate = {0}", cameraFramerate)); KFLog.Log(string.Format(" writeToLogFile = {0}", writeToLogFile)); KFLog.Log(string.Format(" logFilePath = {0}", logFilePath)); KFLog.Log(string.Format(" isGUIEnabled = {0}", isGUIEnabled)); }