Class name

// The purpose of this class is to check what object was tapped on the screen, UI element or brick.
// This is to reduce the conditional logic required for the listeners to check whether the event is relevant to them.
public class InputCategorizer : MonoBehaviour {
[SerializeField] private GameObject xrOrigin;

private ARRaycastManager _arRaycastManager;
private static List<ARRaycastHit> _arHits;
private void Start() {
_arHits = new List<ARRaycastHit>();
_arRaycastManager = xrOrigin.GetComponent<ARRaycastManager>();
InputManager.instance.Tapped += HandleTapped;
}

private void HandleTapped(Vector2 touchPosition, int touchID) {
if (IsUIElementTapped(touchID)) {
EventManager.instance.OnUIElementTapped(touchPosition);
}
else {
if (IsBrickTapped(touchPosition, out RaycastHit physicsHit)) {
EventManager.instance.OnBrickTapped(touchPosition, physicsHit);
}

else if (IsARPlaneTapped(touchPosition, _arHits)) {
EventManager.instance.OnARPlaneTapped(touchPosition, _arHits[0]);
}
}
}

private bool IsBrickTapped(Vector2 touchPosition, out RaycastHit hit) {
Ray ray = Camera.main.ScreenPointToRay(touchPosition);
Physics.Raycast(ray, out hit);

return hit.collider.gameObject.TryGetComponent<Brick>(out _);
}

private bool IsUIElementTapped(int touchId) {
return EventSystem.current.IsPointerOverGameObject(touchId);
}

private bool IsARPlaneTapped(Vector2 touchPosition, List<ARRaycastHit> arHits) {
_arRaycastManager.Raycast(touchPosition, arHits, TrackableType.Planes);

return arHits.Count > 0;
}
}
// The purpose of this class is to check what object was tapped on the screen, UI element or brick.
// This is to reduce the conditional logic required for the listeners to check whether the event is relevant to them.
public class InputCategorizer : MonoBehaviour {
[SerializeField] private GameObject xrOrigin;

private ARRaycastManager _arRaycastManager;
private static List<ARRaycastHit> _arHits;
private void Start() {
_arHits = new List<ARRaycastHit>();
_arRaycastManager = xrOrigin.GetComponent<ARRaycastManager>();
InputManager.instance.Tapped += HandleTapped;
}

private void HandleTapped(Vector2 touchPosition, int touchID) {
if (IsUIElementTapped(touchID)) {
EventManager.instance.OnUIElementTapped(touchPosition);
}
else {
if (IsBrickTapped(touchPosition, out RaycastHit physicsHit)) {
EventManager.instance.OnBrickTapped(touchPosition, physicsHit);
}

else if (IsARPlaneTapped(touchPosition, _arHits)) {
EventManager.instance.OnARPlaneTapped(touchPosition, _arHits[0]);
}
}
}

private bool IsBrickTapped(Vector2 touchPosition, out RaycastHit hit) {
Ray ray = Camera.main.ScreenPointToRay(touchPosition);
Physics.Raycast(ray, out hit);

return hit.collider.gameObject.TryGetComponent<Brick>(out _);
}

private bool IsUIElementTapped(int touchId) {
return EventSystem.current.IsPointerOverGameObject(touchId);
}

private bool IsARPlaneTapped(Vector2 touchPosition, List<ARRaycastHit> arHits) {
_arRaycastManager.Raycast(touchPosition, arHits, TrackableType.Planes);

return arHits.Count > 0;
}
}
@dan1st Picking up from yesterday, what would you call this class?
13 Replies
JavaBot
JavaBot3w ago
This post has been reserved for your question.
Hey @Danish Pirate! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st3w ago
ahhhhh now I have to read C++ code
Danish Pirate
Danish PirateOP3w ago
It's C#
dan1st
dan1st3w ago
or that I just looked at the first 4 lines and saw underscores later
Danish Pirate
Danish PirateOP3w ago
Also, the syntax is not important. I want to know whether the name is an accurate description of what the functions do.
dan1st
dan1st3w ago
What is the ar prefix used for?
Danish Pirate
Danish PirateOP3w ago
Argumented Reality This is to distinquish from a physics raycast
dan1st
dan1st3w ago
That class desn't have any public API? seems like a useless class if it cannot be used
Danish Pirate
Danish PirateOP3w ago
It invokes events in another class.
dan1st
dan1st3w ago
yes but what is it invoked by?
Danish Pirate
Danish PirateOP3w ago
The class listens for events from another class that handles input I wanted the class that handles input to be decoupled from the rest of the program so it only knows about itself.
dan1st
dan1st3w ago
idk what kind of input it is but it seems that the name should reflect that the class is processing/listening to that input I can't tell you much more without knowing how it is called as I don't see anything non-private/overrides Ask yourself the following: What about that class is visible (as API or how it affects other things) to the outside world?
JavaBot
JavaBot3w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?