-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(input): add interaction to power generator (#82)
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
plugin/src/input/ui/machine/PowerGeneratorInteractableUi.cs
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,34 @@ | ||
using TechtonicaVR.Util; | ||
using UnityEngine; | ||
|
||
namespace TechtonicaVR.Input.Ui.Machine; | ||
|
||
public class PowerGeneratorInteractableUi : InteractableUi | ||
{ | ||
private static PluginLogger Logger = PluginLogger.GetLogger<PowerGeneratorInteractableUi>(); | ||
|
||
private GeneratorUI generator; | ||
public PowerGeneratorInteractableUi(GameObject gameObject) : base(gameObject) | ||
{ | ||
generator = gameObject.GetComponentInParent<GeneratorUI>(); | ||
|
||
var button = GameObjectFinder.FindChildObjectByName("Controller Activate Crank CG", gameObject); | ||
var rectTransform = button.GetComponent<RectTransform>(); | ||
var rect = rectTransform.rect; | ||
|
||
Logger.LogDebug($"Button rect: {rect} {rectTransform.localPosition}"); | ||
rect.x += rectTransform.localPosition.x; | ||
rect.y = 260; // TODO: Find a way to get this value dynamically | ||
|
||
interactable = [ | ||
new InteractableBuilder(this, rect, button) | ||
.withClick((ui) => onClick()) | ||
.build() | ||
]; | ||
} | ||
|
||
private void onClick() | ||
{ | ||
generator.ActivateCrankOnClick(); | ||
} | ||
} |
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