zoukankan      html  css  js  c++  java
  • Unity3d 查找所选的是否引用过某资源

    一、使用方式:

    1、选择要被查找的资源,右键->Find Reference

    2、把资源拽入Res,点Find

    3、输出结果见Console

    //代码

    using UnityEngine;
    using System;
    using System.Collections;
    using UnityEditor;
    using System.Collections.Generic;
    
    
    public class FindReference : ScriptableWizard
    {
        public UnityEngine.Object Res;
    
        // Use this for initialization
        void Start()
        {
    
        }
    
    	[MenuItem("Assets/Find Reference")]
        public static void OpenDialog()
        {
    		DisplayWizard<FindReference>("Find Reference Object In Current Select", "Find", "Cancel");
        }
    
        void OnWizardCreate()
        {
            Find();
        }
        void OnWizardOtherButton()
        {
            Close();
        }
    
    
        public void Find()
        {
    		EditorUtility.DisplayProgressBar("Find Reference", "Finding...", 0);
    
    		var instanceId = Res.GetInstanceID();
    
    		var gos = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
    
    	    string log = "";
    
    
    	    int i = 0;
    	    try
    	    {
    			foreach (var go in gos)
    			{
    				var assetPath = AssetDatabase.GetAssetPath(go.GetInstanceID());
    				var paths = AssetDatabase.GetDependencies(new[] { assetPath });
    				foreach (var path in paths)
    				{
    					var res = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
    					if (res.GetInstanceID() == instanceId)
    					{
    						log+= assetPath;
    						log += "
    ";
    					}
    				}
    				EditorUtility.DisplayProgressBar("Find Reference", assetPath, i / gos.Length);
    				i++;
    			}
    	    }
    	    catch (Exception e)
    	    {
    			Debug.Log(e.Message);
    	    }
    	    finally
    	    {
    			EditorUtility.ClearProgressBar();
    	    }
    		
    
    		Debug.Log(log);
        }
    
        
    
    }
    

      

  • 相关阅读:
    正则表达式获取远程网页
    Devexpress 常见问题
    CSS 带显示隐藏左部页面按钮
    CSS 技巧积累
    SQL 常用操作
    重置 自增字段 起始值 和 步长
    Devexpress TreeList
    Devexpress GridControl
    JS常用
    ajax跨域请求
  • 原文地址:https://www.cnblogs.com/mrblue/p/5405704.html
Copyright © 2011-2022 走看看