tyrsisxl

Untitled

Sep 16th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. using Sandbox.ModAPI;
  2. using Sandbox.Common;
  3. using Sandbox.Common.ObjectBuilders;
  4. using Sandbox.Common.Components;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. using System.Collections;
  9. using System.Linq;
  10.  
  11. namespace TestRotorLogic
  12. {
  13. [MyEntityComponentDescriptor(typeof(MyObjectBuilder_MotorStator))]
  14. public class MyRotorLogic : MyGameLogicComponent
  15. {
  16. private bool m_greeted;
  17.  
  18. public override void Close()
  19. {
  20. }
  21.  
  22. public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
  23. {
  24. Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
  25. }
  26.  
  27. public override void MarkForClose()
  28. {
  29. }
  30.  
  31. public override void UpdateAfterSimulation()
  32. {
  33. }
  34.  
  35. public override void UpdateAfterSimulation10()
  36. {
  37. }
  38.  
  39. public override void UpdateAfterSimulation100()
  40. {
  41. }
  42.  
  43. public override void UpdateBeforeSimulation()
  44. {
  45. }
  46.  
  47. public override void UpdateBeforeSimulation10()
  48. {
  49. }
  50.  
  51. public override void UpdateBeforeSimulation100()
  52. {
  53. if ((MyAPIGateway.Session.Player.PlayerCharacter.Entity.GetPosition() - Entity.GetPosition()).Length() < 10)
  54. {
  55. if (!m_greeted)
  56. {
  57. MyAPIGateway.Utilities.ShowNotification(String.Format("Rotor Angle: {0:F2}º", getRotorCurrentAngle(Entity)), 3000, MyFontEnum.Red);
  58. m_greeted = true;
  59. }
  60. }
  61. else
  62. m_greeted = false;
  63. }
  64.  
  65. private static float getRotorCurrentAngle(IMyEntity baseEntity)
  66. {
  67. float value = 0f;
  68.  
  69. try
  70. {
  71. IMyEntity topEnt = baseEntity.GetTopMostParent();
  72. MyObjectBuilder_CubeGrid topBuilder = (MyObjectBuilder_CubeGrid)topEnt.GetObjectBuilder(true);
  73.  
  74. MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)topBuilder.CubeBlocks.FirstOrDefault(c => c.EntityId == baseEntity.EntityId);
  75. if (block == null)
  76. return value;
  77.  
  78. if (block.EntityId == baseEntity.EntityId && block is MyObjectBuilder_MotorStator)
  79. {
  80. MyObjectBuilder_MotorStator rotor = (MyObjectBuilder_MotorStator)block;
  81. value = rotor.CurrentAngle * (float)(180 / Math.PI);
  82. }
  83. }
  84. catch
  85. {
  86. }
  87.  
  88. return value;
  89. }
  90.  
  91. public override void UpdateOnceBeforeFrame()
  92. {
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment