Пример #1
0
    protected virtual List <GameObject> SortObjectsInView(bool cycling = false)
    {
        List <GameObject> Sorted_List   = m_CandidateTargets.OrderBy(go => GetSortWeight(go, cycling)).ToList();
        List <GameObject> objectsInView = new List <GameObject>();

        for (var i = 0; i < Sorted_List.Count(); ++i)
        {
            IDamageableEntity damageable = Sorted_List[i].GetComponent <IDamageableEntity>();
            BaseGameEntity    agent      = Sorted_List[i].GetComponentInParent <BaseGameEntity>();
            if ((agent == null && damageable == null) || (bool)(damageable != null && damageable.IsHideOrDead()))
            {
                continue;
            }
            Vector2 screenPosition = Camera.main.WorldToScreenPoint(Sorted_List[i].transform.position);
            // Entity is within the screen (no targeting offscreen)
            if (screenPosition.x > 0 && screenPosition.x < Screen.width && screenPosition.y > 0 && screenPosition.y < Screen.height && Sorted_List[i].activeInHierarchy)
            {
                // MAKE SURE ALL NON-COLLIDING ENTITIES ARE OFF OF THE DEFAULT LAYER PLEASE
                // If this does not work, change the layer for playercharactercontroller to Player or something
                LayerMask mask   = 1 << LayerMask.NameToLayer("Default") | 1 << LayerMask.NameToLayer("Building");
                bool      didHit = Physics.Linecast(Controller.CacheGameplayCamera.transform.position, GetCenter(Sorted_List[i]), mask);
                if (!didHit)
                {
                    objectsInView.Add(Sorted_List[i]);
                }
            }
        }
        Debug.Log(objectsInView.Count);
        return(objectsInView);
    }