Exemplo n.º 1
0
    public static Dictionary <string, string[]> FindAllFolderDependent(string path, string dstAssetPath)
    {
        string[] assetPathsFromFolder            = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
        string   assetPath                       = "";
        Dictionary <string, string[]> tempRefDic = new Dictionary <string, string[]>();

        foreach (var tempPath in assetPathsFromFolder)
        {
            if (!tempPath.EndsWith(".meta"))
            {
                assetPath = FindReferences.GetRelativeAssetsPath(tempPath);
                string[]      a          = GetAssetDependencies(assetPath);
                List <string> filterPath = new List <string>();

                /* for (int j = 0; j < a.Length; j++)
                 * {
                 *   //过滤掉本身目录,过滤掉.shader .cs
                 *   if (a[j].Contains(dstAssetPath) || a[j].Contains(".cs") || a[j].Contains(".shader"))
                 *   {
                 *   }
                 *   else
                 *   {
                 *       filterPath.Add(a[j]);
                 *   }
                 * }
                 * if (filterPath.Count != 0)
                 * {
                 *   tempRefDic.Add(assetPath, filterPath.ToArray());
                 * }*/
                tempRefDic.Add(assetPath, a);
            }
        }

        return(tempRefDic);
    }
Exemplo n.º 2
0
    //可视化使用
    public static void FindFolderDependentByArtToolsWindow(string path)
    {
        string dstAssetPath = FindReferences.GetRelativeAssetsPath(path);

        refDic = FindAllFolderDependent(path, dstAssetPath);
        Finddependent window = (Finddependent)EditorWindow.GetWindow(typeof(Finddependent));

        window.Show();
    }
Exemplo n.º 3
0
    public static string[] GetAssetDependencies(string assetPath)
    {
        if (!File.Exists(assetPath))
        {
            return(null);
        }
        string dstAssetPath = FindReferences.GetRelativeAssetsPath(assetPath);

        string[]      dependecies = AssetDatabase.GetDependencies(assetPath);
        List <string> filterPath  = new List <string>();

        for (int j = 0; j < dependecies.Length; j++)
        {
            if (dependecies[j].Contains("Assets/AssetsPackage") && !dependecies[j].Contains(dstAssetPath))
            {
                filterPath.Add(dependecies[j]);
            }
        }

        dependecies = filterPath.ToArray();
        return(dependecies);
    }
Exemplo n.º 4
0
    public static void FindAssetsByRG(string path)
    {
        string[] assetPathsFromFolder = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);

        System.Collections.Generic.List <string> pathList = new System.Collections.Generic.List <string>();
        foreach (var tempPath in assetPathsFromFolder)
        {
            if (!tempPath.EndsWith(".meta"))
            {
                pathList.Add(AssetDatabase.AssetPathToGUID(FindReferences.GetRelativeAssetsPath(tempPath)));
            }
        }

        if (pathList.Count < 1)
        {
            EditorUtility.DisplayDialog("提示", "请选择要查找的资源", "确定");
            return;
        }

        //string appDataPath = Path.Combine(Application.dataPath, AddressableTools.Assets_Package );
        //for(int i=0;i<pathList.Count;i++)
        //{
        //    if(i == (pathList.Count - 1))
        //    {
        //        FindReferencesInProject2.FindByRG(pathList[i],appDataPath,true,false);
        //    }
        //    else if(i == 0)
        //    {
        //        FindReferencesInProject2.FindByRG(pathList[i],appDataPath,false,true);
        //    }
        //    else
        //    {
        //        FindReferencesInProject2.FindByRG(pathList[i],appDataPath,false,false);
        //    }
        //}
    }
Exemplo n.º 5
0
    void OnGUI()
    {
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(position.width), GUILayout.Height(position.height));

        showNoUser = EditorGUILayout.Toggle("无引用的资源:", showNoUser);
        if (showNoUser)
        {
            Rect r = EditorGUILayout.BeginVertical("Button");
            foreach (var item in refDic)
            {
                //UnityEngine.Debug.Log(item.Value.Count + "===========" + item.Key);
                if (item.Value.Count == 0)
                {
                    EditorGUILayout.BeginHorizontal();
                    var assetPath = AssetDatabase.GUIDToAssetPath(item.Key);
                    UnityEngine.Object assetObj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
                    GUILayout.Label(assetPath, GUILayout.Width(350));
                    EditorGUILayout.ObjectField("", assetObj, typeof(UnityEngine.Object), true, GUILayout.Width(120));
                    GUILayout.Label("内存占用:" + EditorUtility.FormatBytes(Profiler.GetRuntimeMemorySizeLong(assetObj)), GUILayout.Width(150));

                    if (FindReferences.Rule01(assetPath))
                    {
                        GUIStyle fontStyle = new GUIStyle();
                        fontStyle.normal.textColor = new Color(1, 0, 0);   //设置字体颜色
                        fontStyle.fixedWidth       = 100;
                        GUILayout.Label("bigImage", fontStyle);
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();
        }


        showUser = EditorGUILayout.Toggle("有引用的资源:", showUser);
        if (showUser)
        {
            var index = 0;
            foreach (var item in refDic)
            {
                if (item.Value.Count > 0)
                {
                    if (showList.Count <= index)
                    {
                        showList.Add(true);
                    }

                    //有引用的资源
                    EditorGUILayout.BeginHorizontal();
                    var assetPath = AssetDatabase.GUIDToAssetPath(item.Key);
                    UnityEngine.Object assetObj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
                    GUILayout.Label(assetPath, GUILayout.Width(350));
                    EditorGUILayout.ObjectField("", assetObj, typeof(UnityEngine.Object), true, GUILayout.Width(100));
                    showList[index] = EditorGUILayout.Toggle("", showList[index], GUILayout.Width(20));

                    GUILayout.Label("内存占用:" + EditorUtility.FormatBytes(Profiler.GetRuntimeMemorySizeLong(assetObj)), GUILayout.Width(150));

                    if (FindReferences.Rule01(assetPath))
                    {
                        GUIStyle fontStyle = new GUIStyle();
                        fontStyle.normal.textColor = new Color(1, 0, 0);   //设置字体颜色
                        fontStyle.fixedWidth       = 100;
                        GUILayout.Label("bigImage", fontStyle);
                    }

                    //GUILayout.Label("被下面" + item.Value.Count + "个资源引用:");
                    EditorGUILayout.EndHorizontal();

                    if (showList[index])
                    {
                        foreach (var fileName in item.Value)
                        {
                            assetPath = FindReferences.GetRelativeAssetsPath(fileName);
                            assetObj  = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label(assetPath, GUILayout.Width(350));
                            EditorGUILayout.ObjectField("", assetObj, typeof(UnityEngine.Object), true, GUILayout.Width(120));
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.EndVertical();
                    }
                    index++;
                }
            }
        }

        EditorGUILayout.EndScrollView();
    }
Exemplo n.º 6
0
    public static void SettingPNG()
    {
        /*    string[] fileStrs = Directory.GetFiles(Path.GetFullPath("Assets/AssetsPackage/UI"), "*.*", SearchOption.AllDirectories);
         *  foreach(var file in fileStrs)
         *  {
         *      Debug.Log("file:" + file);
         *      if(file.EndsWith(".meta"))
         *      {
         *          continue;
         *      }
         *      var textureImporter = AssetImporter.GetAtPath( FindReferences.GetRelativeAssetsPath(file) ) as TextureImporter;
         *      if(textureImporter == null)
         *      {
         *          continue;
         *      }
         *      TextureImporterPlatformSettings settingAndroid = textureImporter.GetPlatformTextureSettings("Android");
         *      settingAndroid.overridden = true;
         *      settingAndroid.format = TextureImporterFormat.ETC2_RGBA8;  //设置格式
         *      textureImporter.SetPlatformTextureSettings(settingAndroid);
         *
         *      textureImporter.SaveAndReimport();
         *  }
         */
        string[] paths = Directory.GetFileSystemEntries(Path.GetFullPath("Assets/AssetsPackage"));
        for (int i = 0; i < paths.Length; i++)
        {
            if (Directory.Exists(paths[i]))
            {
                DirectoryInfo di = new DirectoryInfo(paths[i]);

                if (di.Name == "Tmp" || di.Name == "UI" || di.Name == "Fonts" || di.Name == "FmodBanks" || di.Name == "Shaders")
                {
                    continue;
                }


                string[] fileStrs = Directory.GetFiles(Path.GetFullPath("Assets/AssetsPackage/" + di.Name), "*.*", SearchOption.AllDirectories);
                foreach (var file in fileStrs)
                {
                    if (file.EndsWith(".meta"))
                    {
                        continue;
                    }
                    var textureImporter = AssetImporter.GetAtPath(FindReferences.GetRelativeAssetsPath(file)) as TextureImporter;
                    if (textureImporter == null)
                    {
                        continue;
                    }
                    TextureImporterPlatformSettings setting = textureImporter.GetPlatformTextureSettings("Android");
                    setting.overridden     = true;
                    setting.format         = TextureImporterFormat.ASTC_6x6; //设置格式
                    setting.maxTextureSize = 2048;
                    textureImporter.SetPlatformTextureSettings(setting);

                    setting                = textureImporter.GetPlatformTextureSettings("iphone");
                    setting.overridden     = true;
                    setting.format         = TextureImporterFormat.ASTC_6x6; //设置格式
                    setting.maxTextureSize = 2048;
                    textureImporter.SetPlatformTextureSettings(setting);

                    textureImporter.SaveAndReimport();
                }
            }
        }
    }