public override void OnStart(StartState state) { GameEvents.onVesselWasModified.Add(OnVesselWasModified); saveHeatConductivity = part.heatConductivity; saveSkinInternalConductionMult = part.skinInternalConductionMult; saveEmissiveConstant = part.emissiveConstant; saveAbsorptiveConstant = part.absorptiveConstant; CelestialBody homeWorld = FlightGlobals.GetHomeBody(); if (homeWorld != null) { dayLength = homeWorld.solarDayLength; } if (insulationDeployModuleIndex >= 0 && part.Modules.Count > insulationDeployModuleIndex) { if (part.Modules[insulationDeployModuleIndex] is IScalarModule) { insulationScalarModule = part.Modules[insulationDeployModuleIndex] as IScalarModule; insulationScalarModule.OnStop.Add(OnInsulationChanged); } } UpdateResources(); UpdatePreLaunch(); UpdateUI(); }
public AntennaDevice(ModuleDataTransmitter module) : base(module) { List <IScalarModule> deployFxModules = Lib.ReflectionValue <List <IScalarModule> >(module, "deployFxModules"); if (deployFxModules != null && deployFxModules.Count > 0) { deployFxModule = deployFxModules[0]; } }
private IEnumerator WaitForBayDoors(IScalarModule scalar, float limit) { if (scalar == null) { yield break; } while (scalar.GetScalar < limit) { yield return(null); } base.deployEvent(); }
public override void OnStart(StartState state) { base.OnStart(state); deployModule = part.Modules[DeployModuleIndex] as IScalarModule; surfaces = part.FindModulesImplementing <ModuleLiftingSurface>().ToArray(); for (int i = 0; i < surfaces.Length; i++) { lifts.Add(surfaces[i].deflectionLiftCoeff); if (surfaces[i].GetType() == typeof(ModuleControlSurface) | surfaces[i].GetType() == typeof(ModuleAeroSurface)) { ModuleControlSurface srf = surfaces[i] as ModuleControlSurface; ranges.Add(srf.ctrlSurfaceRange); } } deployModule.OnStop.Add(UpdateSurfaces); UpdateSurfaces(deployModule.GetScalar); }
public void FixedUpdate() { if (HighLogic.LoadedSceneIsEditor) { // if (this.part.Resources.Contains("SpareParts")) if (this.part.Resources.Contains(Spares.Name)) { // this.part.Resources["SpareParts"].amount = Math.Round(this.part.Resources["SpareParts"].amount); this.part.Resources[Spares.Name].amount = Math.Round(this.part.Resources[Spares.Name].amount); } } else { if (this.cargoModule == null) { cargoModule = base.part.FindModuleImplementing <ModuleCargoBay>(); if (cargoModule != null) { deployModule = this.findModule(cargoModule.DeployModuleIndex); } } if (cargoModule != null && deployModule != null) { Logger.Info("Cargo bay found"); if (cargoModule.ClosedAndLocked() || this.deployModule.IsMoving()) { Events["DepositParts"].active = false; Events["TakeParts"].active = false; } else { if (!this.deployModule.IsMoving()) { Events["DepositParts"].active = true; Events["TakeParts"].active = true; } } } } }
public override void deployEvent() { IScalarModule scalar = null; float deployLimit = 0; RaycastHit hit; if (_raySource != null && Physics.Raycast(_raySource.position, _raySource.forward, out hit, 1f, LayerUtil.DefaultEquivalent)) { if (hit.collider != null) { bool primary = false; bool secondary = false; if (hit.collider.gameObject.name == "PrimaryDoorCollider") { primary = true; } else if (hit.collider.gameObject.name == "SecondaryDoorCollider") { secondary = true; } if (primary || secondary) { Part p = Part.GetComponentUpwards <Part>(hit.collider.gameObject); if (p != null) { PartModule USAnimate = null; for (int i = p.Modules.Count - 1; i >= 0; i--) { if (p.Modules[i].moduleName == "USAnimateGeneric") { USAnimate = p.Modules[i]; if (USAnimate is IScalarModule) { scalar = USAnimate as IScalarModule; } break; } } if (USAnimate != null) { BaseEvent doorEvent = null; BaseField doorLimit = null; if (primary) { doorEvent = USAnimate.Events["toggleEventPrimary"]; doorLimit = USAnimate.Fields["primaryDeployLimit"]; } else if (secondary) { doorEvent = USAnimate.Events["toggleEventSecondary"]; doorLimit = USAnimate.Fields["secondaryDeployLimit"]; } if (doorLimit != null) { deployLimit = doorLimit.GetValue <float>(USAnimate) * 0.01f; } else { deployLimit = 1; } if (doorEvent != null) { if (doorEvent.active && doorEvent.guiActive) { doorEvent.Invoke(); StartCoroutine(WaitForBayDoors(scalar, deployLimit)); } else { base.deployEvent(); } } else { base.deployEvent(); } } else { base.deployEvent(); } } else { base.deployEvent(); } } else { var ownColliders = part.GetComponentsInChildren <Collider>(); bool flag = false; for (int i = ownColliders.Length - 1; i >= 0; i--) { if (hit.collider == ownColliders[i]) { flag = true; break; } } if (flag) { base.deployEvent(); } else { ScreenMessages.PostScreenMessage( string.Format( "<b><color=orange>Obstruction detected preventing {0} from being deployed.</color></b>" , part.partInfo.title) , 5f, ScreenMessageStyle.UPPER_CENTER); } } } } else { base.deployEvent(); } }
private IEnumerator deployEvent() { if (USTwoScience) { RaycastHit hit; if (_raySource != null && Physics.Raycast(_raySource.position, _raySource.forward, out hit, 1f, LayerUtil.DefaultEquivalent)) { if (hit.collider != null) { bool primary = false; bool secondary = false; if (hit.collider.gameObject.name == "PrimaryDoorCollider") { primary = true; } else if (hit.collider.gameObject.name == "SecondaryDoorCollider") { secondary = true; } if (primary || secondary) { Part p = FlightGlobals.GetPartUpwardsCached(hit.collider.gameObject);// Part.GetComponentUpwards<Part>(hit.collider.gameObject); if (p != null) { IScalarModule scalar = null; float deployLimit = 1; PartModule USAnimate = null; for (int i = p.Modules.Count - 1; i >= 0; i--) { if (p.Modules[i].moduleName == "USAnimateGeneric") { USAnimate = p.Modules[i]; if (USAnimate is IScalarModule) { scalar = USAnimate as IScalarModule; } break; } } if (USAnimate != null && scalar != null) { BaseEvent doorEvent = null; BaseField doorLimit = null; if (primary) { doorEvent = USAnimate.Events["toggleEventPrimary"]; doorLimit = USAnimate.Fields["primaryDeployLimit"]; } else if (secondary) { doorEvent = USAnimate.Events["toggleEventSecondary"]; doorLimit = USAnimate.Fields["secondaryDeployLimit"]; } if (doorLimit != null) { deployLimit = doorLimit.GetValue <float>(USAnimate) * 0.01f; } if (doorEvent != null) { if (doorEvent.active && doorEvent.guiActive) { doorEvent.Invoke(); DMUtils.Logging("Door Invoked"); while (scalar.GetScalar < deployLimit) { yield return(null); } } } } } } else { var ownColliders = part.GetComponentsInChildren <Collider>(); bool flag = false; for (int i = ownColliders.Length - 1; i >= 0; i--) { if (hit.collider == ownColliders[i]) { flag = true; break; } } if (!flag) { ScreenMessages.PostScreenMessage( string.Format( "<b><color=orange>Obstruction detected preventing {0} from being deployed.</color></b>" , part.partInfo.title) , 5f, ScreenMessageStyle.UPPER_CENTER); yield break; } } } } } IsDeployed = true; animator(1f, 0f, Anim, animationName); if (USScience) { animator(1f, 0f, USAnim, USBayAnimation); } yield return(new WaitForSeconds(Anim[animationName].length)); fullyDeployed = true; }
public override void OnStart(StartState state) { int moduleCount = actionModuleIndex; bool found = false; foreach (PartModule p in this.part.Modules) { if (p.moduleName == actionModuleName) { if (moduleCount > 0) { moduleCount--; } else { found = true; anim = p as IScalarModule; if (anim != null) { anim.OnMoving.Add(OnMoving); anim.OnStop.Add(OnStop); } else { Debug.LogErrorFormat("ModuleBdbAnimationMass: Module [{0}] index [{1}] does not impliment IScalarModule", actionModuleName, actionModuleIndex); } break; } } } if (!found) { Debug.LogErrorFormat("ModuleBdbAnimationMass: Module [{0}] index [{1}] not found", actionModuleName, actionModuleIndex); } _origComOffset = part.CoMOffset; _origCopOffset = part.CoPOffset; _origColOffset = part.CoLOffset; string[] sArray = extent.Split(','); if (sArray.Length > 0) { extentV.x = float.Parse(sArray[0]); } if (sArray.Length > 1) { extentV.y = float.Parse(sArray[1]); } if (sArray.Length > 2) { extentV.z = float.Parse(sArray[2]); } Fields["weight"].guiActiveEditor = enableWeight; if (enableWeight) { UI_FloatRange edt = (Fields["weight"].uiControlEditor as UI_FloatRange); edt.minValue = part.prefabMass * 1000; if (weight < edt.minValue) { weight = edt.minValue; } } }