#Class name

20 messages · Page 1 of 1 (latest)

sacred prawn
#
// 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;
    }
}

@analog quarry
Picking up from yesterday, what would you call this class?

thorn topazBOT
#

This post has been reserved for your question.

Hey @sacred prawn! 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.

analog quarry
#

ahhhhh now I have to read C++ code

sacred prawn
#

It's C#

analog quarry
#

or that

#

I just looked at the first 4 lines and saw underscores later

sacred prawn
#

Also, the syntax is not important. I want to know whether the name is an accurate description of what the functions do.

analog quarry
#

What is the ar prefix used for?

sacred prawn
#

Argumented Reality

#

This is to distinquish from a physics raycast

analog quarry
#

That class desn't have any public API?

#

seems like a useless class if it cannot be used

sacred prawn
#

It invokes events in another class.

analog quarry
#

yes but what is it invoked by?

sacred prawn
#

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.

analog quarry
#

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?