Ejemplo n.º 1
0
        /// <summary>
        /// GetSelectableEntity - return top most parent which can be selectable (in case of weapons slection return ship!)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static MyEntity GetSelectableEntity(MyEntity entity)
        {
            if (entity == null)
                return null;

            if (entity.Parent == null)
            {
                if (entity.IsSelectable())
                    return entity;
                else
                    return null;
            }

            MyEntity currEntity = entity;
            MyEntity topMostSelectable = (currEntity.IsSelectable()) ? currEntity : null; //store
            while (currEntity.Parent != null)
            {
                if (currEntity.IsSelectableAsChild() && currEntity.IsSelectable())
                    return currEntity;

                currEntity = currEntity.Parent;
                if (currEntity.IsSelectable())
                    topMostSelectable = currEntity;
            }

            return topMostSelectable;
        }