コード例 #1
0
ファイル: CheckEmptyImage.cs プロジェクト: 526077247/ET
    public void Start()
    {
        List <string> listString = UIAssetUtils.GetAllPrefabs(false);

        for (int i = 0; i < listString.Count; i++)
        {
            string cur = listString[i];

            AssetImporter tmpAssetImporter = AssetImporter.GetAtPath(cur);
            GameObject    prefab           = AssetDatabase.LoadAssetAtPath <GameObject>(tmpAssetImporter.assetPath);

            if (prefab == null)
            {
                Debug.LogError("空的预设 : " + tmpAssetImporter.assetPath);
                continue;
            }

            Image[] images = prefab.GetComponentsInChildren <Image>(true);

            for (int k = 0; k < images.Length; k++)
            {
                SerializedObject   so       = new SerializedObject(images[k]);
                SerializedProperty iterator = so.GetIterator();
                //获取所有属性
                while (iterator.NextVisible(true))
                {
                    if (iterator.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        //引用对象是null 并且 引用ID不是0 说明丢失了引用
                        if (iterator.objectReferenceValue == null && iterator.objectReferenceInstanceIDValue != 0)
                        {
                            AddProblem(cur, images[k].transform);
                        }
                    }
                }
            }

            EditorUtility.DisplayProgressBar("进度", (i + 1) + "/" + listString.Count, (float)(i + 1) / listString.Count);
        }

        EditorUtility.ClearProgressBar();
        isDone = true;
        this.ShowNotification(new GUIContent("查找完成!"));
    }
コード例 #2
0
ファイル: CheckUnuseImage.cs プロジェクト: 526077247/ET
    private void StartCheck()
    {
        EditorSettings.serializationMode = SerializationMode.ForceText;
        AssetDatabase.Refresh();

        List <string> imagePaths = UIAssetUtils.GetAllImages(false);

        imagePaths = imagePaths.Where(s => !Regex.IsMatch(s, "ColorPokerCard")).Where(s => !Regex.IsMatch(s, "PokerCard")).ToList();


        List <string> withoutExtensions = new List <string>()
        {
            ".prefab", ".unity", ".mat", ".cs"
        };

        string[] files = Directory.GetFiles(Path.Combine(Application.dataPath, "AssetsPackage"), "*.*", SearchOption.AllDirectories)
                         .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();

        //预先load内容
        List <string> assetContents = new List <string>();

        foreach (var file in files)
        {
            assetContents.Add(File.ReadAllText(file));
        }
        files = Directory.GetFiles("Codes", "*.*", SearchOption.AllDirectories)
                .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();
        List <string> codeContents = new List <string>();

        foreach (var file in files)
        {
            codeContents.Add(File.ReadAllText(file));
        }

        ThreadPars[] threadParses = new ThreadPars[ThreadCount];
        for (int i = 0; i < ThreadCount; i++)//添加查找的范围内容
        {
            threadParses[i] = new ThreadPars();
            threadParses[i].assetContents = assetContents;
            threadParses[i].codeContents  = codeContents;
        }

        for (int i = 0; i < imagePaths.Count; i++)
        {
            int index = i % ThreadCount;
            threadParses[index].imagePaths.Add(imagePaths[i]);
            threadParses[index].imageGUIDPaths.Add(AssetDatabase.AssetPathToGUID(imagePaths[i]));
        }

        ThreadRun[] tRun          = new ThreadRun[ThreadCount];
        int         finishedState = ThreadCount;

        IAsyncResult[] results = new IAsyncResult[ThreadCount];

        _updateDelegate = delegate
        {
            var finishedCount = 0;
            for (int i = 0; i < ThreadCount; i++)
            {
                if (results[i].IsCompleted)
                {
                    ++finishedCount;
                }
            }

            EditorUtility.DisplayProgressBar("匹配资源中", string.Format("进度:{0}", finishedCount), (float)finishedCount / ThreadCount);

            if (finishedCount >= finishedState)
            {
                for (int i = 0; i < ThreadCount; i++)
                {
                    List <string> temRunThreadData = tRun[i].EndInvoke(results[i]);
                    foreach (var path in temRunThreadData)
                    {
                        Results.Add(path);
                    }
                }

                EditorUtility.ClearProgressBar();
                EditorApplication.update -= _updateDelegate;
                this.ShowNotification(new GUIContent("查找完成!"));
                isDone = true;
                watch.Stop();
                UnityEngine.Debug.Log("累计用时:" + watch.ElapsedMilliseconds);
            }
        };

        for (int i = 0; i < ThreadCount; i++)
        {
            tRun[i]    = ThreadFind;
            results[i] = tRun[i].BeginInvoke(threadParses[i], null, null);
        }

        EditorApplication.update += _updateDelegate;
    }
コード例 #3
0
ファイル: ReplaceImage.cs プロジェクト: 526077247/ET
    private void Start()
    {
        List <string> listString = UIAssetUtils.GetAllPrefabs(false);

        for (int i = 0; i < listString.Count; i++)
        {
            string cur = listString[i];

            AssetImporter tmpAssetImporter = AssetImporter.GetAtPath(cur);
            GameObject    prefab           = AssetDatabase.LoadAssetAtPath <GameObject>(tmpAssetImporter.assetPath);

            if (prefab == null)
            {
                Debug.LogError("空的预设 : " + tmpAssetImporter.assetPath);
                continue;
            }

            bool    isChange = false;
            Image[] Images   = prefab.GetComponentsInChildren <Image>(true);
            for (int k = 0; k < Images.Length; k++)
            {
                if (Images[k].sprite == a)
                {
                    //替換圖片,添加記錄
                    if (b != null)
                    {
                        if (Images[k].type == Image.Type.Filled || Images[k].type == Image.Type.Tiled)
                        {
                            AddProblem(cur, Images[k].transform);
                            continue;
                        }

                        if (b.border.w > 0 || b.border.x > 0 || b.border.y > 0 || b.border.z > 0)
                        {
                            Images[k].type = Image.Type.Sliced;
                        }
                        else
                        {
                            Images[k].type = Image.Type.Simple;
                        }
                        Images[k].sprite = b;
                        isChange         = true;
                        AddRecord(cur, Images[k].transform);
                    }
                }
            }

            Button[] Buttons = prefab.GetComponentsInChildren <Button>(true);
            for (int k = 0; k < Buttons.Length; k++)
            {
                Button btn = Buttons[k];
                if (btn != null)
                {
                    if (btn.transition == Selectable.Transition.SpriteSwap)
                    {
                        int         counter = 0;
                        SpriteState state   = btn.spriteState;
                        if (state.highlightedSprite == a)
                        {
                            counter++;
                            state.highlightedSprite = b;
                        }

                        if (state.pressedSprite == a)
                        {
                            counter++;
                            state.pressedSprite = b;
                        }

                        if (state.selectedSprite == a)
                        {
                            counter++;
                            state.selectedSprite = b;
                        }

                        if (state.disabledSprite == a)
                        {
                            counter++;
                            state.disabledSprite = b;
                        }

                        if (counter > 0)
                        {
                            btn.spriteState = state;
                            isChange        = true;
                            AddRecord(cur, Buttons[k].transform);
                        }
                    }
                }
            }

            if (isChange)
            {
                PrefabUtility.SavePrefabAsset(prefab);
            }
            EditorUtility.DisplayProgressBar("Prefab进度", (i + 1) + "/" + listString.Count, (float)(i + 1) / listString.Count);
        }

        EditorUtility.ClearProgressBar();
        this.ShowNotification(new GUIContent("替换完成!"));
    }
コード例 #4
0
ファイル: ReplaceImage.cs プロジェクト: 526077247/ET
    private void Search()
    {
        List <string> listString = UIAssetUtils.GetAllPrefabs(false);

        for (int i = 0; i < listString.Count; i++)
        {
            string cur = listString[i];

            AssetImporter tmpAssetImporter = AssetImporter.GetAtPath(cur);
            GameObject    prefab           = AssetDatabase.LoadAssetAtPath <GameObject>(tmpAssetImporter.assetPath);

            if (prefab == null)
            {
                Debug.LogError("空的预设 : " + tmpAssetImporter.assetPath);
                continue;
            }

            Image[] Images = prefab.GetComponentsInChildren <Image>(true);
            for (int k = 0; k < Images.Length; k++)
            {
                if (Images[k].sprite == a)
                {
                    AddRecord(cur, Images[k].transform);
                }
            }

            Button[] Buttons = prefab.GetComponentsInChildren <Button>(true);
            for (int k = 0; k < Buttons.Length; k++)
            {
                Button btn = Buttons[k];
                if (btn != null)
                {
                    if (btn.transition == Selectable.Transition.SpriteSwap)
                    {
                        int         counter = 0;
                        SpriteState state   = btn.spriteState;
                        if (state.highlightedSprite == a)
                        {
                            counter++;
                        }

                        if (state.pressedSprite == a)
                        {
                            counter++;
                        }

                        if (state.selectedSprite == a)
                        {
                            counter++;
                        }

                        if (state.disabledSprite == a)
                        {
                            counter++;
                        }

                        if (counter > 0)
                        {
                            AddRecord(cur, Buttons[k].transform);
                        }
                    }
                }
            }

            EditorUtility.DisplayProgressBar("Prefab进度", (i + 1) + "/" + listString.Count, (float)(i + 1) / listString.Count);
        }

        EditorUtility.ClearProgressBar();
        this.ShowNotification(new GUIContent("搜索完成!"));
        isDone = true;
    }