-
-
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 tech tree (#121)
- Loading branch information
Showing
20 changed files
with
178 additions
and
31 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
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
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
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
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
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,50 @@ | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace TechtonicaVR.Input.Ui; | ||
|
||
public class TechTreeInteractableUi : InteractableUi | ||
{ | ||
private TechTreeUI techTreeUi; | ||
public TechTreeInteractableUi(TechTreeUI ui, GameObject gameObject) : base(gameObject) | ||
{ | ||
techTreeUi = ui; | ||
getInteractables = () => gameObject.GetComponentsInChildren<TechTreeCategoryButton>() | ||
.Select(getCategoryButtonInteractable) | ||
.Concat(gameObject.GetComponentsInChildren<TechTreeNode>() | ||
.Select(getTechTreeNodeInteractable) | ||
.Where(interactable => interactable != null)) | ||
.ToList(); | ||
} | ||
|
||
private Interactable getTechTreeNodeInteractable(TechTreeNode node) | ||
{ | ||
if (node.myUnlock.category != techTreeUi.gridUI.curCategory) | ||
{ | ||
return null; | ||
} | ||
|
||
var rect = node.GetComponent<RectTransform>(); | ||
return new InteractableBuilder(this, getRect(rect), node.gameObject) | ||
.withClick((ui) => node.mouseLeftClickCallback?.Invoke()) | ||
.withMouseDown(() => node.mouseDownCallback?.Invoke()) | ||
.withMouseUp(() => node.mouseUpCallback?.Invoke()) | ||
.withHoverEnter((ui) => node.mouseEnterCallback?.Invoke()) | ||
.withHoverExit((ui) => node.mouseExitCallback?.Invoke()) | ||
.build(); | ||
} | ||
|
||
private Interactable getCategoryButtonInteractable(TechTreeCategoryButton button) | ||
{ | ||
var rect = button.GetComponent<RectTransform>(); | ||
return new InteractableBuilder(this, getRect(rect), button.gameObject) | ||
.withClick((ui) => | ||
{ | ||
button.mouseLeftClickCallback?.Invoke(); | ||
ui.refresh(); | ||
}) | ||
.withHoverEnter((ui) => button.mouseEnterCallback?.Invoke()) | ||
.withHoverExit((ui) => button.mouseExitCallback?.Invoke()) | ||
.build(); | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.