-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper module ModuleROPayload to support solar panel animations and tracking in ROTanks.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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; | ||
} | ||
} | ||
} |
This file contains 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