tyrsisxl

Untitled

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