Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Sandbox.ModAPI;
- using Sandbox.Common;
- using Sandbox.Common.ObjectBuilders;
- using Sandbox.Common.Components;
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ConsoleApplication2
- {
- [MyEntityComponentDescriptor(typeof(MyObjectBuilder_MotorStator))]
- public class MyRotorLogic : MyGameLogicComponent
- {
- private bool m_greeted;
- public override void Close()
- {
- }
- public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
- {
- Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
- }
- public override void MarkForClose()
- {
- }
- public override void UpdateAfterSimulation()
- {
- }
- public override void UpdateAfterSimulation10()
- {
- }
- public override void UpdateAfterSimulation100()
- {
- }
- public override void UpdateBeforeSimulation()
- {
- }
- public override void UpdateBeforeSimulation10()
- {
- }
- public override void UpdateBeforeSimulation100()
- {
- if ((MyAPIGateway.Session.Player.PlayerCharacter.Entity.GetPosition() - Entity.GetPosition()).Length() < 10)
- {
- if (!m_greeted)
- {
- MyAPIGateway.Utilities.ShowNotification(String.Format("Rotor Angle: {0}", getRotorCurrentAngle(Entity)), 3000, MyFontEnum.Red);
- m_greeted = true;
- }
- }
- else
- m_greeted = false;
- }
- private static float getRotorCurrentAngle(IMyEntity baseEntity)
- {
- float value = 0f;
- try
- {
- var topEnt = baseEntity.GetTopMostParent();
- var topBuilder = (MyObjectBuilder_CubeGrid)topEnt.GetObjectBuilder(true);
- foreach (MyObjectBuilder_CubeBlock block in topBuilder.CubeBlocks)
- {
- if (block.EntityId == baseEntity.EntityId && block is MyObjectBuilder_MotorStator)
- {
- MyObjectBuilder_MotorStator rotor = (MyObjectBuilder_MotorStator)block;
- value = rotor.CurrentAngle * (float)(180 / Math.PI);
- break;
- }
- }
- }
- catch
- {
- }
- return value;
- }
- public override void UpdateOnceBeforeFrame()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment