-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add internal module to facilitate animated IVAs
ie, when the sub-model that holds the IVA moves relative to the part. It's just a simple parent-constraint that doesn't (yet?) support offset position or rotation.
- Loading branch information
Showing
2 changed files
with
37 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,36 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
public class ELInternalParentConstraint : InternalModule | ||
{ | ||
[KSPField] | ||
public string parentTransformName; | ||
|
||
Transform parentTransform; | ||
|
||
public override void OnAwake () | ||
{ | ||
if (part == null) { | ||
return; | ||
} | ||
if (!String.IsNullOrEmpty (parentTransformName)) { | ||
parentTransform = part.FindModelTransform (parentTransformName); | ||
} | ||
if (parentTransform == null) { | ||
Debug.Log ($"[ELInternalParentConstraint] could not find {parentTransformName}"); | ||
} | ||
} | ||
|
||
void Update () | ||
{ | ||
if (parentTransform == null) { | ||
return; | ||
} | ||
Vector3 pos = parentTransform.position; | ||
Quaternion rot = parentTransform.rotation; | ||
|
||
var xform = internalModel.transform; | ||
xform.position = InternalSpace.WorldToInternal (pos); | ||
xform.rotation = InternalSpace.WorldToInternal (rot) * Quaternion.Euler(90, 180, 0); | ||
} | ||
} |
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