Skip to content

Commit

Permalink
New Class ModuleROPayload (#24)
Browse files Browse the repository at this point in the history
Add helper module ModuleROPayload to support solar panel animations and tracking in ROTanks.
  • Loading branch information
ryanc55 authored Sep 24, 2023
1 parent d808e61 commit 4449159
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Source/ROLib/Modules/ModuelROPayload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace ROLib
{
public class ModuleROPayload : ModuleDeployableSolarPanel
{
protected PartModule pmROTank;

public override void OnStart(StartState state)
{
base.OnStart(state);
pmROTank = part.Modules.GetModule<ModuleROTank>();
if (state == StartState.Editor && pmROTank is ModuleROTank moduleROTank)
{
if (moduleROTank?.Fields["currentCore"] is BaseField cCbf)
{
cCbf.uiControlEditor.onFieldChanged += OnCoreChanged;
}
moduleROTank.enableVScale = false;
moduleROTank.Fields[nameof(moduleROTank.currentVScale)].guiActiveEditor = false;
}
}

internal void OnCoreChanged(BaseField bf, object obj)
{
UpdateAnimationAndTracking(bf);
startFSM();
}

private void UpdateAnimationAndTracking(BaseField bf)
{
FindAnimations();
panelRotationTransform = part.FindModelTransform(pivotName);
hasPivot = panelRotationTransform is Transform;
originalRotation = currentRotation = panelRotationTransform?.localRotation ?? Quaternion.identity;
}

private void FindAnimations()
{
anim = null;
if (!string.IsNullOrEmpty(animationName))
{
Animation[] animations = part.transform.ROLFindRecursive("model").GetComponentsInChildren<Animation>();
anim = animations.FirstOrDefault(x => x.GetClip(animationName) is AnimationClip);
anim ??= animations.FirstOrDefault();
}
useAnimation = anim != null;
}
}
}
1 change: 1 addition & 0 deletions Source/ROLib/ROLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="DebugTools\DebugDrawer.cs" />
<Compile Include="DebugTools\DrawTools.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Modules\ModuelROPayload.cs" />
<Compile Include="Modules\ModuleROSolar.cs" />
<Compile Include="Modules\ModuleROTank_KorolevCross.cs" />
<Compile Include="Modules\ROLAnimateEngineHeat.cs" />
Expand Down

0 comments on commit 4449159

Please sign in to comment.