美文网首页
遍历被隐藏的物体

遍历被隐藏的物体

作者: ValiaLee | 来源:发表于2018-10-27 19:24 被阅读0次

    https://blog.csdn.net/qq_34199256/article/details/82425866

    private static List<GameObject> GetAllSceneObjectsWithInactive()

        {

            var allTransforms = Resources.FindObjectsOfTypeAll(typeof(Transform));

            var previousSelection = Selection.objects;

            Selection.objects = allTransforms.Cast<Transform>()

      .Where(x => x != null)

            .Select(x => x.gameObject)

            //如果你只想获取所有在Hierarchy中被禁用的物体,反注释下面代码

            //.Where(x => x != null && !x.activeInHierarchy)

            .Cast<UnityEngine.Object>().ToArray();

            var selectedTransforms = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab);

            Selection.objects = previousSelection;

            return selectedTransforms.Select(tr => tr.gameObject).ToList();

        }

    相关文章

      网友评论

          本文标题:遍历被隐藏的物体

          本文链接:https://www.haomeiwen.com/subject/vtadtqtx.html