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;
- using System.Collections;
- using System.Linq;
- namespace TestRotorLogic
- {
- [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:F2}º", getRotorCurrentAngle(Entity)), 3000, MyFontEnum.Red);
- m_greeted = true;
- }
- }
- else
- m_greeted = false;
- }
- private static float getRotorCurrentAngle(IMyEntity baseEntity)
- {
- float value = 0f;
- try
- {
- IMyEntity topEnt = baseEntity.GetTopMostParent();
- MyObjectBuilder_CubeGrid topBuilder = (MyObjectBuilder_CubeGrid)topEnt.GetObjectBuilder(true);
- MyObjectBuilder_CubeBlock block = topBuilder.CubeBlocks.FirstOrDefault(c => c.EntityId == baseEntity.EntityId);
- if (block == null)
- return value;
- if (block.EntityId == baseEntity.EntityId && block is MyObjectBuilder_MotorStator)
- {
- MyObjectBuilder_MotorStator rotor = (MyObjectBuilder_MotorStator)block;
- value = rotor.CurrentAngle * (float)(180 / Math.PI);
- }
- }
- catch
- {
- }
- return value;
- }
- public override void UpdateOnceBeforeFrame()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment