unity场景中寻找挂的脚本

在开发中往往会遇到一个问题:不知道整个场景中究竟有哪些物体挂载了某一个脚本。如果挨个查找太麻烦了,下面有一种方法可以快速找到解决这个问题。

在windows找到
在这里插入图片描述

在这里插入图片描述

using UnityEngine;
using UnityEditor;
public class FindMissingScriptsRecursively : EditorWindow
{
    static int go_count = 0, components_count = 0, missing_count = 0;
 
    [MenuItem("Window/FindMissingScriptsRecursively")]
    public static void ShowWindow()
    {
        EditorWindow.GetWindow(typeof(FindMissingScriptsRecursively));
    }
 
    public void OnGUI()
    {
        if (GUILayout.Button("Find Missing Scripts in selected GameObjects"))
        {
            FindInSelected();
        }
    }
    private static void FindInSelected()
    {
        GameObject[] go = Selection.gameObjects;
        go_count = 0;
        components_count = 0;
        missing_count = 0;
        foreach (GameObject g in go)
        {
            FindInGO(g);
        }
        Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
    }
 
    private static void FindInGO(GameObject g)
    {
        go_count++;
        Component[] components = g.GetComponents<Component>();
        for (int i = 0; i < components.Length; i++)
        {
            components_count++;
            if (components[i] == null)
            {
                missing_count++;
                string s = g.name;
                Transform t = g.transform;
                while (t.parent != null)
                {
                    s = t.parent.name + "/" + s;
                    t = t.parent;
                }
                Debug.Log(s + " has an empty script attached in position: " + i, g);
            }
        }
        // Now recurse through each child GO (if there are any):  
        foreach (Transform childT in g.transform)
        {
            //Debug.Log("Searching " + childT.name  + " " );  
            FindInGO(childT.gameObject);
        }
    }
}

还有这个

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
 
/
//查找节点及所有子节点中,是否有指定的脚本组件
/
public class MonoFinder : EditorWindow
{
    Transform root = null;
    MonoScript scriptObj = null;
    int loopCount = 0;
 
    List<Transform> results = new List<Transform>();
 
    [MenuItem("Level4/Finder/MonoFinder")]
    static void Init()
    {
        EditorWindow.GetWindow(typeof(MonoFinder));
    }
 
    void OnGUI()
    {
        GUILayout.Label("节点:");
        root = (Transform)EditorGUILayout.ObjectField(root, typeof(Transform), true);
        GUILayout.Label("脚本类型:");
        scriptObj = (MonoScript)EditorGUILayout.ObjectField(scriptObj, typeof(MonoScript), true);
        if (GUILayout.Button("Find"))
        {
            results.Clear();
            loopCount = 0;
            Debug.Log("开始查找.");
            FindScript(root);
        }
        if (results.Count > 0)
        {
            foreach (Transform t in results)
            {
                EditorGUILayout.ObjectField(t, typeof(Transform), false);
            }
        }
        else
        {
            GUILayout.Label("无数据");
        }
    }
 
    void FindScript(Transform root)
    {
        if (root != null && scriptObj != null)
        {
            loopCount++;
            Debug.Log(".." + loopCount + ":" + root.gameObject.name);
            if (root.GetComponent(scriptObj.GetClass()) != null)
            {
                results.Add(root);
            }
            foreach (Transform t in root)
            {
                FindScript(t);
            }
        }
    }
}


在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Unity 场景下载是指下载其他开发者制作的 Unity 场景,以便在自己的项目使用。在互联网上,有很多网站和社区提供了丰富的 Unity 场景资源供开发者免费或付费下载。 主要的下载方式有以下几种: 1. Unity Asset Store:这是 Unity 官方提供的资源商店,提供了丰富的可以直接在 Unity 编辑器导入的资源,包括场景模型、材质、音频、代码脚本等。 2. 第三方网站:如 CGTrader、TurboSquid、Sketchfab 等,这些网站提供了广泛的 3D 模型,在其寻找合适的场景模型、特效动画、音频背景是不错的选择。 3. Unity 官网社区:它提供了一个交流分享的平台,许多开发者会在其免费分享自己开发的场景,或者提供下载链接。 无论是哪种下载方式,都需要开发者根据自己的需求进行筛选和选择,保证下载的资源符合项目需求和使用规范。同时,确保资源下载的合法性,防止恶意软件的入侵。在使用场景时,还需适当调整和修改,以保证流畅的合理的使用体验。 ### 回答2: Unity场景下载是指从Unity Asset Store或者其他网络资源下载其他开发者创建的Unity场景文件。Unity场景是游戏开发的基本元素之一,它是一种包含了游戏所有元素和物体的三维环境,包括场景内的地图、地形、建筑、道具等等。 通过下载其他开发者创建的Unity场景文件,我们可以快速地获取并使用他们创建的游戏环境,加快我们的开发速度。而且,下载的Unity场景文件也可以作为学习资源,让我们学习其他游戏开发者的制作技巧和经验,从而提高自己的创作能力。 当我们下载Unity场景文件后,通常需要进一步编辑和调整其内容,以适应我们自己的需求。例如,我们可以添加自己的游戏元素或者再次修改地图和道具等等。同时,我们还可以将自己创建的Unity场景文件发布到网络资源,以分享给其他开发者和游戏爱好者。 总之,Unity场景下载是游戏开发常见的操作之一,它可以帮助我们快速地获取资源并学习他人的经验,同时也可以将自己的作品分享给其他人。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值