Example #1
0
    private void HandleCollision()
    {
        int layerMask = 0;

        if (controller.viewCollision)
        {
            layerMask |= 1 << LayerMask.NameToLayer("Collide");
        }
        else
        {
            layerMask |= 1 << LayerMask.NameToLayer("Visual");
        }
        if (controller.viewGraphs)
        {
            layerMask |= 1 << LayerMask.NameToLayer("Graph");
        }
        Ray ray = cam.cam.ScreenPointToRay(Input.mousePosition);

        RaycastHit[] hits = Physics.RaycastAll(ray, Mathf.Infinity, layerMask, QueryTriggerInteraction.Ignore);
        if (hits != null && hits.Length > 0)
        {
            System.Array.Sort(hits, (x, y) => (x.distance.CompareTo(y.distance)));
            if (controller.showPersos)
            {
                for (int i = 0; i < hits.Length; i++)
                {
                    // the object identified by hit.transform was clicked
                    BasePersoBehaviour pb = hits[i].transform.GetComponentInParent <BasePersoBehaviour>();
                    if (pb != null)
                    {
                        highlightedPerso = pb;
                        if (Input.GetMouseButtonDown(0))
                        {
                            IsSelecting = true;
                        }
                        UpdateHighlight();
                        if (IsSelecting)
                        {
                            if (cam.IsPanningWithThreshold())
                            {
                                IsSelecting = false;
                            }
                            else if (Input.GetMouseButtonUp(0))
                            {
                                Select(pb, view: true);
                            }
                        }
                        break;
                    }
                }
            }
            if (controller.viewCollision)
            {
                for (int i = 0; i < hits.Length; i++)
                {
                    CollideComponent cc = hits[i].transform.GetComponent <CollideComponent>();
                    if (cc != null)
                    {
                        highlightedCollision = cc;
                        break;
                    }
                }
            }
            if (controller.viewGraphs)
            {
                for (int i = 0; i < hits.Length; i++)
                {
                    WayPointBehaviour wp = hits[i].transform.GetComponent <WayPointBehaviour>();
                    if (wp != null)
                    {
                        highlightedWayPoint = wp;
                        break;
                    }
                }
            }

            /*SectorComponent sector = hit.transform.GetComponentInParent<SectorComponent>();
             * if (sector != null) {
             *  JumpTo(sector.gameObject);
             *  return;
             * }*/
        }

        /*if (Input.GetMouseButtonDown(0)) { // if left button pressed...
         *  if (Physics.Raycast(ray, out hit)) {
         *      // the object identified by hit.transform was clicked
         *      PersoBehaviour pb = hit.transform.GetComponentInParent<PersoBehaviour>();
         *      if (pb != null) {
         *          JumpTo(pb.gameObject);
         *          return;
         *      }
         *      SectorComponent sector = hit.transform.GetComponentInParent<SectorComponent>();
         *      if (sector != null) {
         *          JumpTo(sector.gameObject);
         *          return;
         *      }
         *  }
         * }*/
    }