123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System.Collections.Generic;
- using System.IO;
- using Fort23.UTool;
- using UnityEngine;
- using UnityEngine.U2D;
- using UnityEngine.UI;
- using UnityEngine.UI.PackgTool;
- namespace UnityEditor.UI
- {
- public class UGUIGameObjectTool
- {
- private static List<SpriteAtlas> allSpriteAtlasList;
- public static void ReviewUI(List<SpriteAtlas> allSpriteAtlasList, SpriteAtlas spriteAtlas, PackInfo packInfo)
- {
- UGUIGameObjectTool.allSpriteAtlasList = allSpriteAtlasList;
- string[] allFinle =
- System.IO.Directory.GetFiles(Application.dataPath + "/Res/UI/", "*", SearchOption.AllDirectories);
- // string[] uiallObj = AssetDatabase.FindAssets("", new string[] {"Assets/Res/UI"});
- for (int i = 0; i < allFinle.Length; i++)
- {
-
- string path = allFinle[i].Replace(Application.dataPath, "Assets");
- if (path.Contains(".mate"))
- {
- continue;
- }
- GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(path);
- if (go != null)
- {
- bool isAlter = ReviewGameObject(go, spriteAtlas, packInfo);
- if (isAlter)
- {
- PrefabUtility.SavePrefabAsset(go);
- }
- }
- }
- AssetDatabase.SaveAssets();
- }
- private static SpriteAtlas GetSpriteNamePack(string spriteName)
- {
- if (allSpriteAtlasList == null || allSpriteAtlasList.Count <= 0)
- {
- return null;
- }
- for (int i = 0; i < allSpriteAtlasList.Count; i++)
- {
- if (allSpriteAtlasList[i].GetSprite(spriteName) != null)
- {
- return allSpriteAtlasList[i];
- }
- }
- return null;
- }
- private static bool ReviewGameObject(GameObject gameObject, SpriteAtlas spriteAtlas, PackInfo packInfo)
- {
- bool isAlter = false;
- MyImage[] allImage = gameObject.transform.GetComponentsInChildren<MyImage>(true);
- if (allImage == null)
- {
- return false;
- }
- for (int i = 0; i < allImage.Length; i++)
- {
- MyImage image = allImage[i];
- bool isoK = false;
- if (image.packInfo != null && image.CurrSpriteAtlas != null)
- {
- isoK = image.CurrSpriteAtlas.GetSprite(image.icon_name) != null;
- if (!isoK) //没在在图集里面找到图片了,需要去其他地方查找(删除图集)
- {
- SpriteAtlas newAtlas = GetSpriteNamePack(image.icon_name);
- if (newAtlas != null)
- {
- image.packInfo = UGUICacheInfo.uguiPackDB.GetPackgInfo(newAtlas.name);
- image.CurrSpriteAtlas = newAtlas;
- image.icon_name = image.icon_name;
- image.ReashUI();
- isAlter = true;
- }
- }
- else
- {
- continue;
- }
- }
- if (image.CurrSpriteAtlas == null &&
- image.sprite != null|| !string.IsNullOrEmpty( image.icon_name)) //没有图集 但是由功能管理器添加的UI (添加图集)
- {
- string name = image.sprite!=null? image.sprite!.name: image.icon_name;
- SpriteAtlas newAtlas = GetSpriteNamePack(name);
- // Sprite sprite = spriteAtlas.GetSprite(name);
- if (newAtlas != null)
- {
- image.packInfo = UGUICacheInfo.uguiPackDB.GetPackgInfo(newAtlas.name);
- image.CurrSpriteAtlas = newAtlas;
- image.icon_name = image.icon_name;
- image.ReashUI();
- isAlter = true;
- }
- }
- }
- return isAlter;
- }
- }
- }
|