Exemplo n.º 1
0
 public void OnBeginDrag(PointerEventData eventData)
 {
     if (!Input.GetKey(KeyCode.LeftControl) && !Input.GetKey(KeyCode.RightControl))
     {
         RTS_Selectable.DeselectAll(new BaseEventData(EventSystem.current));
     }
     selectionBoxImage.gameObject.SetActive(true);
     startPosition = eventData.position;
     selectionRect = new Rect();
 }
Exemplo n.º 2
0
        // bubbles/propagates the pointer click
        public void OnPointerClick(PointerEventData eventData)
        {
            List <RaycastResult> results = new List <RaycastResult> ();

            EventSystem.current.RaycastAll(eventData, results);

            Debug.Log("CLICK");
            Debug.Log(results.Count);

            if (results.Count < 3)
            {
                RTS_Selectable.DeselectAll(eventData);
            }
            else
            {
                float myDistance = 0;

                foreach (RaycastResult result in results)
                {
                    // get the drag selection box distance
                    if (result.gameObject == gameObject)
                    {
                        myDistance = result.distance;
                        break;
                    }
                }

                GameObject nextObject  = null;
                float      maxDistance = Mathf.Infinity;

                foreach (RaycastResult result in results)
                {
                    // if there are any objects further away than the drag selector - this is the nextObject to pass the event to
                    if (result.distance > myDistance && result.distance < maxDistance)
                    {
                        nextObject  = result.gameObject;
                        maxDistance = result.distance;
                    }
                }

                if (nextObject)
                {
                    // grab on click event and bubble it through to the object behind the UI
                    ExecuteEvents.Execute <IPointerClickHandler> (nextObject, eventData, (x, y) => { x.OnPointerClick((PointerEventData)y); });
                }
            }
        }
Exemplo n.º 3
0
 // Use this for initialization
 protected override void Awake()
 {
     base.Awake();              // call -parent awake function
     navMeshAgent = GetComponent <NavMeshAgent> ();
     mySelectable = GetComponent <RTS_Selectable> ();
 }