Example #1
0
    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("查找完成!"));
    }
Example #2
0
    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("替换完成!"));
    }
Example #3
0
    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;
    }