// Runs on PartModule startup. public override void OnStart(StartState state) { this.LogDebug("ModuleTweakableDeployablePanel.OnStart"); // Startup the PartModule stuff first. base.OnStart(state); // Fetch the solar panel module from the part. if (this.part.tryGetFirstModuleByName(this.moduleType, out this.panelModule)) { // Set our state trackers to the opposite of our states, to force first-run updates. this.sunTrackingState = !this.sunTrackingEnabled; // Fetch the UnityEngine.Animation object from the solar panel module. Animation anim = this.panelModule.GetComponentInChildren <Animation>(); // If the animation is null, bailout. if (anim != null) { this.LogDebug("Animation is not null; wrapping."); if (animationNameField == null) { animationNameField = this.panelModule.GetType().GetField("animationName"); } // Build an ToadicusTools. this.panelAnimation = new ToadicusTools.AnimationWrapper( anim, (string)animationNameField.GetValue(this.panelModule), ToadicusTools.PlayDirection.Forward ); } // Yay debugging! this.LogDebug("panelAnimation: " + this.panelAnimation); // If we are in the editor and have an animation... if (HighLogic.LoadedSceneIsEditor && this.panelAnimation != null) { // ...pre-set the panel's currentRotation... if (originalRotationField == null) { originalRotationField = this.panelModule.GetType().GetField("originalRotation"); } if (currentRotationField == null) { currentRotationField = this.panelModule.GetType().GetField("currentRotation"); } currentRotationField.SetValue(this.panelModule, originalRotationField.GetValue(this.panelModule)); } /* * Checks whether this panel is a sun tracking panel or not. Despite its name, ModuleDeployableSolarPanel * is used for all (most?) solar panels, even those that don't deploy or rotate. * */ // If the panel is sun tracking panel... if (sunTrackingField == null) { sunTrackingField = this.panelModule.GetType().GetField("isTracking"); } bool moduleIsSunTracking = false; if (sunTrackingField != null) { moduleIsSunTracking = (bool)sunTrackingField.GetValue(this.panelModule); } Debug.Log("sunTracking 2"); if (moduleIsSunTracking) { if (trackingSpeedField == null) { trackingSpeedField = this.panelModule.GetType().GetField("trackingSpeed"); } // ...go fetch the tracking speed and make sure our tracking tweakable is active. this.baseTrackingSpeed = (float)trackingSpeedField.GetValue(this.panelModule); this.Fields["sunTrackingEnabled"].guiActive = true; this.Fields["sunTrackingEnabled"].guiActiveEditor = true; } else { // ...otherwise, make sure our tracking code and tweakable are inactive. this.sunTrackingEnabled = false; this.sunTrackingState = false; this.Fields["sunTrackingEnabled"].guiActive = false; this.Fields["sunTrackingEnabled"].guiActiveEditor = false; } } }
// Runs on PartModule startup. public override void OnStart(StartState state) { // Startup the PartModule stuff first. base.OnStart(state); // Fetch the solar panel module from the part. if (this.part.tryGetFirstModuleByName(this.moduleType, out this.panelModule)) { // Set our state trackers to the opposite of our states, to force first-run updates. this.sunTrackingState = !this.sunTrackingEnabled; // Fetch the UnityEngine.Animation object from the solar panel module. Animation anim = this.panelModule.GetComponentInChildren<Animation>(); // If the animation is null, bailout. if (anim != null) { this.LogDebug("Animation is not null; wrapping."); if (animationNameField == null) { animationNameField = this.panelModule.GetType().GetField("animationName"); } // Build an ToadicusTools. this.panelAnimation = new ToadicusTools.AnimationWrapper( anim, (string)animationNameField.GetValue(this.panelModule), ToadicusTools.PlayDirection.Forward ); } // Yay debugging! this.LogDebug("panelAnimation: " + this.panelAnimation); // If we are in the editor and have an animation... if (HighLogic.LoadedSceneIsEditor && this.panelAnimation != null) { // ...pre-set the panel's currentRotation... if (originalRotationField == null) { originalRotationField = this.panelModule.GetType().GetField("originalRotation"); } if (currentRotationField == null) { currentRotationField = this.panelModule.GetType().GetField("currentRotation"); } currentRotationField.SetValue(this.panelModule, originalRotationField.GetValue(this.panelModule)); } /* * Checks whether this panel is a sun tracking panel or not. Despite its name, ModuleDeployableSolarPanel * is used for all (most?) solar panels, even those that don't deploy or rotate. * */ // If the panel is sun tracking panel... if (sunTrackingField == null) { sunTrackingField = this.panelModule.GetType().GetField("sunTracking"); } bool moduleIsSunTracking = (bool)sunTrackingField.GetValue(this.panelModule); if (moduleIsSunTracking) { if (trackingSpeedField == null) { trackingSpeedField = this.panelModule.GetType().GetField("trackingSpeed"); } // ...go fetch the tracking speed and make sure our tracking tweakable is active. this.baseTrackingSpeed = (float)trackingSpeedField.GetValue(this.panelModule); this.Fields["sunTrackingEnabled"].guiActive = true; this.Fields["sunTrackingEnabled"].guiActiveEditor = true; } else { // ...otherwise, make sure our tracking code and tweakable are inactive. this.sunTrackingEnabled = false; this.sunTrackingState = false; this.Fields["sunTrackingEnabled"].guiActive = false; this.Fields["sunTrackingEnabled"].guiActiveEditor = false; } } }