Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by oliver-jones · Nov 30, 2016 at 02:10 PM · clickeventsystempointerexecute

EventSystem - Call 'OnPointerClick' to EventSystem

Hello,

I'm making my own Input for 'OnPointerClick' - which is basically a series of keys pushed in sequence.

If complete, I want to then tell my EventSystem to call 'OnPointerClick'. I've looked at the ExecuteEvents, and the 'pointerClickHandler' but the documentation doesn't really give much information based on that. So I'm not really sure how to set it up.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.EventSystems;
 
 public class PointerClickCustom : MonoBehaviour, IEventSystemHandler {
 
     //tell EventSystem to trigger OnPointerClick within its EventSystem
     void CallOnPointerClickEvent(){
 
         EventSystem _current = EventSystem.current;
         ExecuteEvents.pointerClickHandler();
     }
 }

Any advise would be greatly appreciated. Thanks

--- Update ---

I've created my own InputModule, and I've added to the EventSystem:

 public class GestureInputModule : BaseInputModule
 {
     public GameObject m_TargetObject;
 
     public override void Process(){
         
         if (m_TargetObject == null)return;
         
         ExecuteEvents.Execute (m_TargetObject, new PointerEventData (eventSystem), ExecuteEvents.pointerClickHandler);
     }
 }

The question now is, how do I connect this InputModule to my 'PointerClickCustom'. Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Nov 30, 2016 at 02:34 PM

If you want to provide your own input to the event system you should create your own Input module. Just look at the sample code. For OnPointerClick you want to pass the ExecuteEvents.pointerClickHandler instead of moveHandler. You also might need to pass an instance of PointerEventData instead of BaseEventData.

Don't pay too much attention to the example in the docs. Most examples make no sense.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Nov 30, 2016 at 02:39 PM 0
Share

So I can't just tell the EventSystem to call 'OnPointerClick', but I have to create a whole new Input $$anonymous$$odule? Thanks.

avatar image oliver-jones · Nov 30, 2016 at 02:49 PM 0
Share

Hello, I have updated my OP.

avatar image
0

Answer by Feyyyyy · Nov 30, 2016 at 02:47 PM

There are some different ways of doing this. According to your purpose you need to select one of them.

  1. If your purpose is just do some action on pointer event and position of the click is not important you can do something like this.

      void Update() {
             if (Input.GetMouseButtonDown(0)) {
                 CallOnPointerClickEvent();
             }
         }
    
    
  2. If you have a specific location relative to screen that you want user to click. You can do the following.

Instead of IEventSystemHandler use IPointerClickHandler Also the game object that your script attached have to be attached with a visible component from UnityEngine.UI package (ex: Image), and this gameobject have to be under a canvas

      using UnityEngine;
      using System.Collections;
      using UnityEngine.EventSystems;
      
      
      public class PointerClickCustom : MonoBehaviour, IPointerClickHandler{
     
         public void OnPointerClick(PointerEventData eventData) {
             CallOnPointerClickEvent();
         }
     }
 
 


Hope this helps.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Nov 30, 2016 at 02:49 PM 0
Share

Hello, thanks for your reply - but this doesn't answer my question. I want to be able to 'inject' an OnPointClick event into my current EventSystem. Not to listen for one.

avatar image Feyyyyy · Nov 30, 2016 at 04:12 PM 0
Share

you are right :) sorry.

avatar image oliver-jones Feyyyyy · Nov 30, 2016 at 04:37 PM 0
Share

Thanks anyway :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

58 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fake pointer up on UI gameobject A and pointer down on UI gameobject B 1 Answer

I need the x, y, z position value of the point of gaze input (pointer click in google vr) on a plane centered at (0,0,0) and scaled (2,2,2), 0 Answers

Unity 5 UI buttons don't respond well with clicks when used in windows standalone with different resolutions. 0 Answers

Hi, i want to get "pointer enter" data from the event system 1 Answer

Simulate click OnMouseOver / OnPointerEnter 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges