Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否有办法在GUILayout.Button内的EditorWindow中使用EditorGUILayout.LabelField? 使用UnityEngine; 使用System.Collections.Generic; 使用Object=UnityEngine.Object; 运用系统反思; 使用UnityEditor; 使用System.Linq; 公共类可搜索窗口:EditorWindow { 字符串searchString=“”; 静态列表gameobjecttest=新列表(); 向量2; [菜单项(“工具/搜索”)] 私有静态void createReplaceWithPrefact() { const int width=340; const int height=420; var x=(Screen.currentResolution.width-width)/2; 变量y=(Screen.currentResolution.height-height)/2; GetWindow().position=新矩形(x、y、宽度、高度); } 私有void OnGUI() { EditorGUILayout.BeginOrizontal(EditorStyles.toolbar); GUILayout.FlexibleSpace(); searchString=EditorGUILayout.TextField(searchString,EditorStyles.toolbarTextField); EditorGUILayout.EndHorizontal(); if(GUILayout.按钮(“搜索”)) { var items=Selection.gameObjects; //在这里进行比较。例如 所选变量=GetChildrenRecursive(项目); gameobjecttest.AddRange(选中); } EditorGUILayout.BeginHorizontal(); scrollPos=EditorGUILayout.BeginScrollView(scrollPos,GUILayout.Width(300),GUILayout.Height(400)); foreach(游戏对象进入游戏对象测试) { EditorGUILayout.LabelField(go.name); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndHorizontal(); } 私有void OnSelectionChange() { 重新油漆(); } 私有静态IEnumerable GetChildrenRecursive(游戏对象根) { var输出=新列表(); //添加根对象本身 output.Add(root); //迭代直接子对象 foreach(在root.Transform中转换子级) { //加上孩子们自己 output.Add(child.gameObject); var childsOfchild=GetChildrenRecursive(child.gameObject); output.AddRange(childsOfchild); } 返回输出; } 私有静态IEnumerable GetChildrenRecursive(IEnumerable rootObjects) { var输出=新列表(); foreach(rootObjects中的var root) { AddRange(GetChildrenRecursive(root)); } //删除所有重复项,例如,如果选择父项及其子项,则会出现重复项 返回output.Distinct(); } }_C#_Unity3d - Fatal编程技术网

C# 是否有办法在GUILayout.Button内的EditorWindow中使用EditorGUILayout.LabelField? 使用UnityEngine; 使用System.Collections.Generic; 使用Object=UnityEngine.Object; 运用系统反思; 使用UnityEditor; 使用System.Linq; 公共类可搜索窗口:EditorWindow { 字符串searchString=“”; 静态列表gameobjecttest=新列表(); 向量2; [菜单项(“工具/搜索”)] 私有静态void createReplaceWithPrefact() { const int width=340; const int height=420; var x=(Screen.currentResolution.width-width)/2; 变量y=(Screen.currentResolution.height-height)/2; GetWindow().position=新矩形(x、y、宽度、高度); } 私有void OnGUI() { EditorGUILayout.BeginOrizontal(EditorStyles.toolbar); GUILayout.FlexibleSpace(); searchString=EditorGUILayout.TextField(searchString,EditorStyles.toolbarTextField); EditorGUILayout.EndHorizontal(); if(GUILayout.按钮(“搜索”)) { var items=Selection.gameObjects; //在这里进行比较。例如 所选变量=GetChildrenRecursive(项目); gameobjecttest.AddRange(选中); } EditorGUILayout.BeginHorizontal(); scrollPos=EditorGUILayout.BeginScrollView(scrollPos,GUILayout.Width(300),GUILayout.Height(400)); foreach(游戏对象进入游戏对象测试) { EditorGUILayout.LabelField(go.name); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndHorizontal(); } 私有void OnSelectionChange() { 重新油漆(); } 私有静态IEnumerable GetChildrenRecursive(游戏对象根) { var输出=新列表(); //添加根对象本身 output.Add(root); //迭代直接子对象 foreach(在root.Transform中转换子级) { //加上孩子们自己 output.Add(child.gameObject); var childsOfchild=GetChildrenRecursive(child.gameObject); output.AddRange(childsOfchild); } 返回输出; } 私有静态IEnumerable GetChildrenRecursive(IEnumerable rootObjects) { var输出=新列表(); foreach(rootObjects中的var root) { AddRange(GetChildrenRecursive(root)); } //删除所有重复项,例如,如果选择父项及其子项,则会出现重复项 返回output.Distinct(); } }

C# 是否有办法在GUILayout.Button内的EditorWindow中使用EditorGUILayout.LabelField? 使用UnityEngine; 使用System.Collections.Generic; 使用Object=UnityEngine.Object; 运用系统反思; 使用UnityEditor; 使用System.Linq; 公共类可搜索窗口:EditorWindow { 字符串searchString=“”; 静态列表gameobjecttest=新列表(); 向量2; [菜单项(“工具/搜索”)] 私有静态void createReplaceWithPrefact() { const int width=340; const int height=420; var x=(Screen.currentResolution.width-width)/2; 变量y=(Screen.currentResolution.height-height)/2; GetWindow().position=新矩形(x、y、宽度、高度); } 私有void OnGUI() { EditorGUILayout.BeginOrizontal(EditorStyles.toolbar); GUILayout.FlexibleSpace(); searchString=EditorGUILayout.TextField(searchString,EditorStyles.toolbarTextField); EditorGUILayout.EndHorizontal(); if(GUILayout.按钮(“搜索”)) { var items=Selection.gameObjects; //在这里进行比较。例如 所选变量=GetChildrenRecursive(项目); gameobjecttest.AddRange(选中); } EditorGUILayout.BeginHorizontal(); scrollPos=EditorGUILayout.BeginScrollView(scrollPos,GUILayout.Width(300),GUILayout.Height(400)); foreach(游戏对象进入游戏对象测试) { EditorGUILayout.LabelField(go.name); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndHorizontal(); } 私有void OnSelectionChange() { 重新油漆(); } 私有静态IEnumerable GetChildrenRecursive(游戏对象根) { var输出=新列表(); //添加根对象本身 output.Add(root); //迭代直接子对象 foreach(在root.Transform中转换子级) { //加上孩子们自己 output.Add(child.gameObject); var childsOfchild=GetChildrenRecursive(child.gameObject); output.AddRange(childsOfchild); } 返回输出; } 私有静态IEnumerable GetChildrenRecursive(IEnumerable rootObjects) { var输出=新列表(); foreach(rootObjects中的var root) { AddRange(GetChildrenRecursive(root)); } //删除所有重复项,例如,如果选择父项及其子项,则会出现重复项 返回output.Distinct(); } },c#,unity3d,C#,Unity3d,我想在单击按钮时进行搜索,并将项目添加到EditorGUILayout.LabelField中,但EditorGUILayout.LabelField不需要位于OnGUI中,如果它位于if(GUILayout.button(“搜索”),则不会将项目添加到EditorGUILayout.LabelField中 现在它不停地向EditorGUILayout.LabelField添加内容。您的问题有点不清楚 如果您的问题只是是否可能: 不(至少不是你所期望的那样) 此区块内的任何内容: using U

我想在单击按钮时进行搜索,并将项目添加到EditorGUILayout.LabelField中,但EditorGUILayout.LabelField不需要位于OnGUI中,如果它位于if
(GUILayout.button(“搜索”)
,则不会将项目添加到EditorGUILayout.LabelField中


现在它不停地向EditorGUILayout.LabelField添加内容。

您的问题有点不清楚

如果您的问题只是是否可能:

(至少不是你所期望的那样)

此区块内的任何内容:

using UnityEngine;
using System.Collections.Generic;
using Object = UnityEngine.Object;
using System.Reflection;
using UnityEditor;
using System.Linq;

public class SearchableWindow : EditorWindow
{
    string searchString = "";
    static List<GameObject> gameobjecttest = new List<GameObject>();
    Vector2 scrollPos;

    [MenuItem("Tools/Searching")]
    private static void CreateReplaceWithPrefab()
    {
        const int width = 340;
        const int height = 420;

        var x = (Screen.currentResolution.width - width) / 2;
        var y = (Screen.currentResolution.height - height) / 2;

        GetWindow<SearchableWindow>().position = new Rect(x, y, width, height);
    }

    private void OnGUI()
    {
        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
        GUILayout.FlexibleSpace();
        searchString = EditorGUILayout.TextField(searchString, EditorStyles.toolbarTextField);
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Search"))
        {
            var items = Selection.gameObjects;
            // Do comparison here. For example
            var selected = GetChildrenRecursive(items);
            gameobjecttest.AddRange(selected);
        }

        EditorGUILayout.BeginHorizontal();
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(300), GUILayout.Height(400));
        foreach (GameObject go in gameobjecttest)
        {
            EditorGUILayout.LabelField(go.name);
        }
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndHorizontal();
    }

    private void OnSelectionChange()
    {
        Repaint();
    }

    private static IEnumerable<GameObject> GetChildrenRecursive(GameObject root)
    {
        var output = new List<GameObject>();

        //add the root object itself
        output.Add(root);

        // iterate over direct children
        foreach (Transform child in root.transform)
        {
            // add the children themselves
            output.Add(child.gameObject);

            var childsOfchild = GetChildrenRecursive(child.gameObject);
            output.AddRange(childsOfchild);
        }

        return output;
    }

    private static IEnumerable<GameObject> GetChildrenRecursive(IEnumerable<GameObject> rootObjects)
    {
        var output = new List<GameObject>();

        foreach (var root in rootObjects)
        {
            output.AddRange(GetChildrenRecursive(root));
        }

        // remove any duplicates that would e.g. appear if you select a parent and its child
        return output.Distinct();
    }
}
只在按钮实际按下时执行

所以你必须按照你已经做过的方式去做。如果列表不为空,可能会添加额外的检查,以仅显示这些字段:

if (GUILayout.Button("Search"))
{
     ...
}
(我通常添加那些
{
}
来稍微清理代码)

或者保留按钮,但禁用它

// only show the button while the list is empty
if(gameobjecttest.Count == 0)
{
    if (GUILayout.Button("Search"))
    {
         ...
    }

    // skip the rest
    return;
}

// otherwise show the list
EditorGUILayout.BeginHorizontal();
{
    scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(300), GUILayout.Height(400));
    {
        foreach (GameObject go in gameobjecttest)
        {
            EditorGUILayout.LabelField(go.name);
        }
    }
    EditorGUILayout.EndScrollView();
}
EditorGUILayout.EndHorizontal();

就像我的另一个问题一样,这里也有同样的问题。因为当你拖动窗口或上下滚动时,foreach(GameObject进入gameobjecttest)在OnGUI中,它移动得非常慢,而且不停地进行foreach循环,所以会抖动/结巴。我想知道他们是如何在等级制度中做到这一点的,它的运作如此顺利。但是我想没有解决办法。如果它不在
OnGUI
中,你就不会看到任何东西。。。那些是抽签电话,必须在那里。当然,这取决于你在同一时间展示了多少对象,但可能慢/结巴不是来自LabelFields本身,而是其他东西?慢/结巴是因为在我的层次结构中有5000多个游戏对象和孩子。如果游戏对象中只有一些游戏对象,如5或10,它将运行平稳,但如果有很多游戏对象,它将缓慢地移动。例如,请看此图像屏幕截图:您可以看到有13个游戏对象都具有相同的名称,但并非所有游戏对象都具有相同的子对象。在我的场景中,我有5000多个对象,搜索每个对象都需要时间。我想知道为什么当我过滤它们的时候,它没有像没有过滤一样显示它们和它们的孩子。我想筛选并查看孩子的原因是检查他们是否都有相同的孩子。但在过滤它们之后,它只显示父对象。最后,我创建了一个脚本,也在编辑器模式下执行,通过inspector中的搜索按钮为我提供有关游戏对象的信息:这是按钮的脚本:这是我想在EditorWindow中做的,也是我想在过滤对象。在inspector中太糟糕了,你不能像在editorwindow中那样进行滚动。
EditorGUI.BeginDisabledGroup(gameobjecttest.Count != 0);
{
    if (GUILayout.Button("Search"))
    {
         ...
    }
}
EditorGUI.EndDisabledGroup();