Пример #1
0
    private void MouseManager_ClickEvent(object sender, ClickArgs e)
    {
        var clickedObject = e.clickedObject;

        //if you clicked an object that is not selected already
        if (selectedObject != clickedObject)
        {
            //clear previous selection
            if (DeselectionEvent != null && selectedObject != null)
            {
                DeselectionEvent.Invoke(this, new ClickArgs(selectedObject));
            }
            //select the object
            if (SelectionEvent != null && clickedObject != null)
            {
                SelectionEvent.Invoke(this, new ClickArgs(clickedObject));
            }
        }
        else
        {
            //if you clicked the selected object
            //deselect the object
            if (DeselectionEvent != null)
            {
                DeselectionEvent.Invoke(this, new ClickArgs(clickedObject));
            }
        }
    }
Пример #2
0
 public void RemoveEventFromDeselection(DeselectionEvent action)
 {
     if (eventQueue != null && eventQueue.Contains(action))
     {
         eventQueue.Remove(action);
     }
     onDeselection -= action;
 }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo))
        {
            //Debug.Log("Mouse is over: " + hitInfo.collider.name);

            // The collider we hit may not be the "root" of the object
            // You can grab the most "root-est" gameobject using
            // transform.root, though if your objects are nested within
            // a larger parent GameObject (like "All Units") then this might
            // not work.  An alternative is to move up the transform.parent
            // hierarchy until you find something with a particular component.

            GameObject hitObject = hitInfo.transform.root.gameObject;

            var outlineRefs = hitObject.GetComponent <GetOutlineReferences>();
            if (outlineRefs != null && outlineRefs.IsClickable == true)//TODO: Change that with a way to know if the object is interactible
            {
                HighlightObject(hitObject);

                if (Input.GetMouseButtonDown(0))
                {
                    if (ClickEvent != null)
                    {
                        ClickEvent.Invoke(this, new ClickArgs(hitObject));
                    }
                }
            }
            else
            {
                //if you hit something, but it's not clickable
                ClearHighlight();
                if (Input.GetMouseButtonDown(0) && selectedObject != null)
                {
                    ClickEvent.Invoke(this, new ClickArgs(null));
                }
            }
        }
        else
        {
            //if you did not hit a collider
            ClearHighlight();
            if (Input.GetMouseButtonDown(0) && selectedObject != null)
            {
                DeselectionEvent.Invoke(this, new ClickArgs(selectedObject));
            }
        }
    }
Пример #4
0
 void Awake()
 {
     OnSelect   = new SelectionEvent();
     OnDeselect = new DeselectionEvent();
 }
Пример #5
0
 private void AddEventToDeselectionQueue(DeselectionEvent action)
 {
     eventQueue.Add(action);
 }