Created
February 12, 2020 14:38
-
-
Save LambdaSix/5c5a5fff8f990416a46659e0e6c86905 to your computer and use it in GitHub Desktop.
Animated Subpart + Emissives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using Sandbox.Common.ObjectBuilders; | |
| using Sandbox.Game; | |
| using Sandbox.Game.Lights; | |
| using Sandbox.ModAPI; | |
| using VRage.Game; | |
| using VRage.Game.Components; | |
| using VRage.Game.Entity; | |
| using VRage.Game.ModAPI; | |
| using VRage.ModAPI; | |
| using VRage.ObjectBuilders; | |
| using VRageMath; | |
| namespace SurvivalNeeds.AnimationsAndLighting | |
| { | |
| [MyEntityComponentDescriptor(typeof(MyObjectBuilder_Refinery), false, "Hydroponics")] | |
| public class EnclosedHydroAnimation : MyGameLogicComponent | |
| { | |
| private int _rotationTimeWrs = 0; | |
| private int _animationLoopWrs; | |
| private bool _playAnimation = true; | |
| private MyLight _light; | |
| MyObjectBuilder_EntityBase _objectBuilder; | |
| IMyCubeBlock _enclosedHydroponics; | |
| public override void Init(MyObjectBuilder_EntityBase objectBuilder) | |
| { | |
| try | |
| { | |
| base.Init(objectBuilder); | |
| _objectBuilder = objectBuilder; | |
| _enclosedHydroponics = Entity as IMyCubeBlock; | |
| NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME; | |
| } | |
| catch (Exception e) | |
| { | |
| MyVisualScriptLogicProvider.ShowNotificationToAll("Init Error" + e, 10000, "Red"); | |
| } | |
| } | |
| public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false) => _objectBuilder; | |
| public override void UpdateAfterSimulation() | |
| { | |
| try | |
| { | |
| LightTools.UpdateWorkingState(_enclosedHydroponics, _light, null, Color.White, 0.5f, 1.0f, | |
| new Vector4(0.604f, 0.804f, 0.196f, 1.0f), | |
| () => RotateTurbine()); | |
| } | |
| catch (Exception e) | |
| { | |
| MyVisualScriptLogicProvider.ShowNotificationToAll("Update Error" + e, 2500, "Red"); | |
| } | |
| } | |
| public void RotateTurbine() | |
| { | |
| try | |
| { | |
| var subpart = _enclosedHydroponics.GetSubpart("EnclosedHydroponics_Leaves"); | |
| var rotation = 0.003f; | |
| var initialMatrix = subpart.PositionComp.LocalMatrix; | |
| var rotationMatrix = MatrixD.CreateRotationY(rotation); | |
| var matrix = rotationMatrix * initialMatrix; | |
| if (!subpart.Closed) | |
| { | |
| subpart.PositionComp.LocalMatrix = matrix; | |
| _animationLoopWrs++; | |
| } | |
| } | |
| catch (Exception e) | |
| { | |
| MyVisualScriptLogicProvider.ShowNotificationToAll("Animation Error" + e, 2500, "Red"); | |
| } | |
| } | |
| public override void Close() | |
| { | |
| if (_light != null) | |
| { | |
| MyLights.RemoveLight(_light); | |
| _light = null; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment