public void Update()
		{
			// update RMB ui
			Events["Toggle"].guiName = deployed ? Localizer.Format("#KERBALISM_Generic_RETRACT") : Localizer.Format("#KERBALISM_Generic_DEPLOY");
			Events["Toggle"].active = (deploy.Length > 0) && (part.FindModuleImplementing<Habitat>() == null) && !deploy_anim.Playing() && !waitRotation && ResourceCache.Info(vessel, "ElectricCharge").amount > ec_rate;

			// in flight
			if (Lib.IsFlight())
			{
				// if deployed
				if (deployed)
				{
					// if there is no ec
					if (ResourceCache.Info(vessel, "ElectricCharge").amount < 0.01)
					{
						// pause rotate animation
						// - safe to pause multiple times
						Set_rotation(false);
					}
					// if there is enough ec instead and is not deploying
					else if (Should_start_rotation())
					{
						// resume rotate animation
						// - safe to resume multiple times
						Set_rotation(true);
					}
				}
				// stop loop animation if exist and we are retracting
				else
				{
					// Call transform.stop() if it is rotating and the Stop method wasn't called.
					Set_rotation(false);
				}

				// When is not rotating
				if (waitRotation)
				{
					if (rotateIsTransform && !rotate_transf.IsRotating())
					{
						// start retract animation in the correct direction, when is not rotating
						if (animBackwards) deploy_anim.Play(deployed, false);
						else deploy_anim.Play(!deployed, false);
						waitRotation = false;
					}
					else if (!rotateIsTransform && !rotate_anim.Playing())
					{
						if (animBackwards) deploy_anim.Play(deployed, false);
						else deploy_anim.Play(!deployed, false);
						waitRotation = false;
					}
				}

				if (rotateIsTransform && rotate_transf != null) rotate_transf.DoSpin();
			}
		}
Beispiel #2
0
		public void FixedUpdate()
		{
			// do nothing in the editor
			if (Lib.IsEditor()) return;

			// if deployed
			if (deployed || (animBackwards && !deployed))
			{
				// if there is no ec
				if (ResourceCache.Info(vessel, "ElectricCharge").amount < 0.01)
				{
					// pause rotate animation
					// - safe to pause multiple times
					if (rotateIsTransform && rotate_transf.IsRotating() && !rotate_transf.IsStopping()) rotate_transf.Stop();
					else rotate_anim.pause();
				}
				// if there is enough ec instead and is not deploying
				else if (!deploy_anim.playing())
				{
					// resume rotate animation
					// - safe to resume multiple times
					if (rotateIsTransform && (!rotate_transf.IsRotating() || rotate_transf.IsStopping())) rotate_transf.Play();
					else rotate_anim.resume(false);
				}
			}
			// stop loop animation if exist and we are retracting
			else
			{
				// Call transform.stop() if it is rotating and the Stop method wasn't called.
				if (rotateIsTransform && rotate_transf.IsRotating() && !rotate_transf.IsStopping()) rotate_transf.Stop();
				else rotate_anim.stop();
			}

			// When is not rotating
			if (waitRotation)
			{
				if (rotateIsTransform && !rotate_transf.IsRotating())
				{
					// start retract animation in the correct direction, when is not rotating
					if (animBackwards) deploy_anim.play(deployed, false);
					else deploy_anim.play(!deployed, false);
					waitRotation = false;
				}
				else if (!rotateIsTransform && !rotate_anim.playing())
				{
					if (animBackwards) deploy_anim.play(deployed, false);
					else deploy_anim.play(!deployed, false);
					waitRotation = false;
				}
			}

			// if has any animation playing, consume energy.
			if (deploy_anim.playing() || (rotate_transf.IsRotating() && !rotate_transf.IsStopping()) || rotate_anim.playing())
			{
				// get resource handler
				resource_info ec = ResourceCache.Info(vessel, "ElectricCharge");

				// consume ec
				ec.Consume(ec_rate * Kerbalism.elapsed_s);
			}

			if (rotateIsTransform && rotate_transf != null) rotate_transf.DoSpin();
		}