Hi there!

It looks like you have some terrific selection options, but I am having trouble because there are so many touch variations. Could you please add some more examples of how selection can be added to objects via script? These would be very useful in the demo scenes as well.

My situation: I have objects that I am instantiating at runtime that I want to make selectable and to execute additional functions when they are selected (specifically, passing the information the object contains to the UI). From what I understand, I want to be adding them to the list of selectables on the TouchCameraInputs object by script. Are these events that I should be adding or objects?

Could you please demonstrate how to make an object selectable (by finger and mouse) via script?

Here is how I am currently trying to do it when I instantiate map markers:

marker.AddComponent<TouchSelectable>();
mainCamera.GetComponent<SelectByFinger>().Selectables.Add(marker.GetComponent<TouchSelectable>());

Many thanks!

    BettyWhite Hi!

    You just need to add a "SelectableByFinger" component to your instantiated object, then you can listen to the OnSelected event in it.

    SelectableByFinger s = marker.AddComponent<SelectableByFinger>();
    s.OnSelected.AddListerner(...

    You can also create a child class of TouchSelectableBehaviour, add it your object, and override "OnSelected"

    protected override void OnSelected(TouchSelect select)
    {

    }

    Have a look at the script FocusOnClick to see an example.
    Thanks!

      Anthony

      Thanks for your response, I now have it partially working!

      I have added the SelectableByFinger component to my marker and added my DisplayUI function to the OnSelected list in the Inspector. I also modified by Marker script to inherit from TouchSelectableBehaviour and I added:

      // when selected
      protected override void OnSelected(TouchSelect select)
      {
           // tell object to display UI
           this.gameObject.GetComponent<MapMarker>().DisplayPreview();
      }

      I also added a listener based on FocusOnClick so that it focuses on the marker. Looks great!
      CameraEvents.OnRequestObjectFocus?.Invoke(gameObject, true);

      Now it will focus on the marker 80% of the time the first time I select it, and then if I don't move the camera I can still select other markers and have my DisplayUI function execute anywhere between 1 and 3 times before it stops completely. And if I move the camera then I stop being able to select any markers at all (or execute the DisplayUI function).

      I also found that the function associated with the touch (DisplayPreview) executed twice, so I added a co-routine delay so that it only executes once.

      Could you explain what else I'm missing here and why it's stopping? And please let me know if you need any more information.

      Thanks for your time!

        BettyWhite it's hard to tell, do you experience the same issue with by cubes in the demo scenes?
        Can you share a video, or a basic scene in a .unitypackage and sent it to contact at exoa.fr ? I will have a look

        Thanks

          BettyWhite just to keep the conversation tracked here:

          Thank you. It’s still hard to tell, can you try to put a simple shape collider on the markers like box or sphere collider, make sure it’sa bit larger than the marker and remove the child meshcollider?

          Something else to try: using the default OnMouseDown event in your script ?

          Anthony

            Write a Reply...