public static void FilterByLabel()
        {
            if (!FilterByLabelValid())
            {
                throw new InvalidOperationException("No asset label is set.");
            }

            var _labels = EditrixUtility.GetAllAssetLabels(GetSelected(typeof(Object)));

            _options = _labels.ToDictionary((label) => label, (label) => GetSelected(typeof(Object), label));

            CreateInstance <SelectionFilter>().ShowPopup();
        }
示例#2
0
        /// <summary>
        /// Filter the top level transforms, excluding prefabs, ordered by sibling index.
        /// </summary>
        /// <returns>The tops.</returns>
        /// <param name="transforms">Transforms.</param>
        public static Transform[] FilterTops(params Transform[] transforms)
        {
            if (null == transforms)
            {
                throw new ArgumentNullException("transforms");
            }

            var _all = transforms.Distinct().Where((obj) => null != obj && !AssetDatabase.Contains(obj)).ToArray();

            var _tops = _all.Where((praent) => !_all.Any((child) => child != praent && child.IsChildOf(praent)));

            return(_tops.OrderBy((top) => EditrixUtility.GetObjectOrder(top)).ToArray());
        }
        /// <summary>
        /// Show the label popup menu.
        /// </summary>
        /// <param name="rect">Rect.</param>
        private void ShowLabelMenu(Rect rect)
        {
            var _menu = new GenericMenu();

            _menu.AddItem("[ None ]", UpdateLabel, "", string.IsNullOrEmpty(_label));

            var _labels = EditrixUtility.GetAllAssetLabels(_filtered);

            if (0 < _labels.Length)
            {
                _menu.AddSeparator("");
            }

            foreach (var _new in _labels)
            {
                _menu.AddItem(_new, UpdateLabel, _new, _new == _label);
            }

            _menu.DropDown(rect);
        }
        /// <summary>
        /// Get filtered objects from current selection by specified type, label, and selection mode.
        /// </summary>
        ///
        /// <remarks>
        /// Filter from all assets if nothing selected.
        /// Return <c>UnityEngine.GameObject</c> instead if the type is <c>UnityEngine.Component</c>.
        /// </remarks>
        ///
        /// <returns>The filtered selection.</returns>
        /// <param name="type">Type to filter.</param>
        /// <param name="label">Asset label to filter.</param>
        /// <param name="mode">Selection mode to filter.</param>

        /*
         * Use type of GameObject to filter deep in asset folder doesn't work.
         * We have to filter Object first then check type to get prefabs.
         */
        public static Object[] GetSelected(Type type, string label = "", SelectionMode mode = SelectionMode.DeepAssets)
        {
            var _objects = Selection.objects;

            if (0 == _objects.Length)
            {
                Selection.objects = EditrixUtility.GetAllAssets();
            }

            var _object    = typeof(GameObject).IsAssignableFrom(type);
            var _component = typeof(Component).IsAssignableFrom(type);

            IEnumerable <Object> _all;

            if (!_object && !_component)
            {
                _all = Selection.GetFiltered(type, mode);
            }
            else if (SelectionMode.DeepAssets != mode)
            {
                _all = Selection.GetFiltered(typeof(GameObject), mode);
            }
            else
            {
                _all = Selection.GetFiltered(typeof(Object), mode).OfType <GameObject>().Cast <Object>();
            }

            if (_component)
            {
                _all = _all.Where((obj) => null != (obj as GameObject).GetComponent(type));
            }
            if (!string.IsNullOrEmpty(label))
            {
                _all = _all.Where((obj) => AssetDatabase.GetLabels(obj).Contains(label));
            }

            Selection.objects = _objects;
            return(_all.OrderBy((obj) => EditrixUtility.GetObjectOrder(obj)).ToArray());
        }
 private static bool FilterByLabelValid()
 {
     return(EditrixUtility.GetAllAssetLabels(GetSelected(typeof(Object))).Any());
 }