Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2.  
  3. using KSP;
  4.  
  5. namespace AnimatedDocking
  6. {
  7. public class ModuleAnimatedDocking : PartModule
  8. {
  9. [KSPField]
  10. public string animationName = "";
  11.  
  12. private ModuleAnimateGeneric module;
  13.  
  14. public override void OnStart(StartState state)
  15. {
  16. base.OnStart(state);
  17. foreach (ModuleAnimateGeneric m in base.part.FindModulesImplementing<ModuleAnimateGeneric>())
  18. {
  19. if (m.animationName == this.animationName)
  20. {
  21. this.module = m;
  22. break;
  23. }
  24. }
  25. if (this.module == null) return;
  26. GameEvents.onPartCouple.Add(this.onPartCouple);
  27. GameEvents.onPartUndock.Add(this.onPartUndock);
  28. }
  29. private void onPartCouple(GameEvents.FromToAction<Part, Part> action)
  30. {
  31. if (action.to == base.part)
  32. {
  33. module.Toggle();
  34. }
  35. }
  36. private void onPartUndock(Part part)
  37. {
  38. if (part = base.part)
  39. {
  40. this.module.Toggle();
  41. }
  42. }
  43. private void OnDestroy()
  44. {
  45. GameEvents.onPartCouple.Add(this.onPartCouple);
  46. GameEvents.onPartUndock.Remove(this.onPartUndock);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement