unity 删除依赖

2023-11-08

记录- 

Scene中有依赖废弃的资源。

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;

public class FindDependences{
    [MenuItem("Assets/Find Story References", false, 10)]
    static private void Find()
    {
        EditorSettings.serializationMode = SerializationMode.ForceText;
       // string path = AssetDatabase.GetAssetPath(Selection.activeObject);
         List<string> uuids = FindSceneDep();
        if (uuids != null)
        {
            //string guid = AssetDatabase.AssetPathToGUID(path);
           
            string[] files = FindDepsFiles();
            
 
            EditorApplication.update = delegate()
            {


                int startIndex = 0;
                for (int i = 0; i < uuids.Count; i++)
                {
                    
                    bool isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", uuids[i], (float)startIndex / (float)uuids.Count);
                    
                    startIndex++;
                    for (int j = 0; j < files.Length; j++)
                    {
                        if (Regex.IsMatch(File.ReadAllText(files[j]), uuids[i]))
                        {
                            string uuid = GetObjUUID(GetRelativeAssetsPath(files[j]));
                            //Debug.Log(file, AssetDatabase.LoadAssetAtPath<Object>(GetRelativeAssetsPath(file)));
                            ReadFile(SceneManager.GetActiveScene().path, uuid);
                        }
                    }                                  
                }
                
                //if (isCancel || startIndex >= files.Length)
                {
                    EditorUtility.ClearProgressBar();
                    EditorApplication.update = null;
                    startIndex = 0;
                    Debug.Log("匹配结束");
                }
            };
        }
    }
    static string[] FindDepsFiles() {
        List<string> withoutExtensions = new List<string>() { ".prefab", ".unity", ".mat", ".asset", ".playable" };
        string[] files = Directory.GetFiles(Application.dataPath + "/Games/Story/", "*.*", SearchOption.AllDirectories)
            .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();
       
        return files;
    }
    //查找scnes
    static List<string> FindSceneDep()
    {
        List<string> uuids = new List<string>();
        UnityEngine.Object[] selectedAsset = Selection.GetFiltered<UnityEngine.Object>(SelectionMode.DeepAssets);
        for (int i = 0; i < selectedAsset.Length; i++)
        {
            UnityEngine.Object o = selectedAsset[i];     
            string path = AssetDatabase.GetAssetPath(o);
            uuids.Add( AssetDatabase.AssetPathToGUID(path));
        }
        return uuids;
    }
    static void ReadFile(string path,string uuid) {
        try
        {
            Debug.LogError(path);
            
            //FileStream file = new FileStream(path, FileMode.OpenOrCreate);
            //StreamReader sr = new StreamReader(file, Encoding.Default);
            String[] lines = System.IO.File.ReadAllLines(path);
            List<string> listS = new List<string>(lines);
            for (int i = listS.Count - 1; i >= 0; i--)
            {
                if (listS[i].Contains(uuid))
                {
                    Debug.LogError("delet " + uuid);
                    listS.RemoveAt(i + 1);
                    listS.RemoveAt(i);                    
                }
            }
            string[] str = listS.ToArray();
            System.IO.File.WriteAllLines(path, str);
        }
        catch (Exception e) {
            Debug.LogError(e.ToString());
        }
    }
    static string GetObjUUID(string file){
        Debug.Log(AssetDatabase.AssetPathToGUID(file));
        return AssetDatabase.AssetPathToGUID(file);
    }

 
    static private string GetRelativeAssetsPath(string path)
    {
        return "Assets" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/');
    }
}
 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

unity 删除依赖 的相关文章

  • 【Unity2d】带你制作一款类似于金山打字的小游戏

    博主大概08年开始接触电脑游戏 当时玩的是我哥的电脑 那时候家里没网 只可以玩电脑上自带的单机游戏 比如扫雷 蜘蛛纸牌等等 当然还有红色警戒 冰封王座 星际争霸 帝国崛起等等 这些大概是我哥当时在大学下载的 也是那个时候对游戏充满了兴趣 记
  • Unity用Vuforia做AR实现脱卡效果

    有时在识别目标丢失后我们仍希望虚拟物体能够出现在摄像机前 或者到一个特定的位置 我们能对其进行操作 这就是脱卡功能 自带的脱卡功能应该是ExtendedTracking 允许模型在识别图丢失的时候还存在 位置不变 在丢失的时候的位置 这样也
  • using UnityEditor引用注意事项

    本文转载自http blog csdn net czlilove article details 19979725 在运行时脚本中使用UnityEditor命名空间 假如该脚本被挂在场景中的物体上 那么 可以这样做 在Unity编辑器中运行
  • 【UGUI】2D头顶血条制作

    前言 近期因为需要制作玩家和敌人头顶的2D血条 查找了很多博客 发现很多都拘束于Canvas的渲染模式必须要设定为ScreenSpace Overlay 还有应该是版本原因 我的是unity2019 1 11f1 用RecttTransfo
  • UE5学习笔记(一)——界面功能梳理&第一天知识点记录

    学习UE5的第一步 是软件安装 默认是安装好的 由于安装没有太多技术含量 所以就没有专门做记录 这里有个注意点 虚幻引擎是整合在Epic games launcher中的 也就是说开发引擎内嵌在游戏平台上 打个比方 就是如果你要下unity
  • 蒙特卡洛积分、重要性采样、低差异序列

    渲染公式 渲染的目标在于计算周围环境的光线有多少从表面像素点反射到相机视口中 要计算总的反射光 每个入射方向的贡献 必须将他们在半球上相加 为入射光线 与法线 的夹角 为方便计算可以使用法线向量和入射向量 单位化 的乘积表示 对于基于图像的
  • Unity 粒子特效、材质发光 HDR ShaderGraph图文教程[完成lit发光设置]

    效果如图 准备工作 在hdr模式下 关闭Directional Light 相机设置 移动球挂一个点光源作为子节点 设置自行调节 0 创建移动球的材质及shader shader gt 在Project Create Shader Grap
  • Unity Shader入门精要第七章 基础纹理之遮罩纹理

    Unity系列文章目录 文章目录 Unity系列文章目录 前言 一 实践 参考 前言 遮罩纹理 mask texture 是本章要介绍的最后一种纹理 它非常有用 在很多商业游戏中 都可以见到它的身影 那么什么是遮罩呢 简单来讲 遮罩允许我们
  • Unity中UI框架的使用1-添加面板、显示Loading页面

    其中BasePanel和Canvas都是挂在面板的预制物上的 1 导入我们的UI框架 本篇文章中有用的是两个UIPanelType NUIManager和NBasePanel 会放在文章最后供大家使用 2 先将我们做好的Panel设置成预制
  • GooglePlay提审警告(com.google.android.gms:play-services-safetynet:17.0.0)

    1 Goole在今年6月份出的新政策 不在使用safetynet 而使用Play Integrity API 2 项目本身没有使用过safetynet 3 使用了firebase 查阅资料 解决方案如下 implementation pla
  • 【IMGUI】 各种辅助类 EditorGUIUtility、EditorUtility、GUIUtility、GUILayoutUtility

    EditorGUIUtility class in Editor 继承自 GUIUtility EditorGUI 的各种辅助程序 EditorGUIUtility currentViewWidth 我尝试打印了下这个值和position
  • Unity打开工程时卡住的问题

    自从Unity升级了一个版本后 Unity打开工程卡住的问题越来越严重了 具体表现为 选择工程后 Unity窗口消失 但进程还在 有时候等个几分钟能出来 有时候等10分钟都不见得能出来 直观感受上看 似乎是Unity加载工程的时候某一步卡了
  • Unity保存图片到相册

    Unity保存图片到Android相册 Java 纯文本查看 复制代码 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  • unity实现鼠标右键控制视角

    主要实现的功能是相机跟随主角 鼠标右击移动后 相机的视角会旋转 思路 在主角里创建空的子物体 把相机绑在空物体上 通过旋转空物体来实现视角的旋转 要把相机调整到适当位置 代码如下 public float rotateSpeed 100 设
  • unity3d切换场景Application.LoadLevel(1)含义

    Application LoadLevel 1 场景ID
  • unity3d 自定义的图片无法放入source image中

    须将图片的texture type改为 sprite
  • Unity学习笔记

    一 旋转欧拉角 四元数 Vector3 rotate new Vector3 0 30 0 Quaternion quaternion Quaternion identity quaternion Quaternion Euler rota
  • 游戏开发常见操作梳理之NPC任务系统

    多数游戏存在任务系统 接下来介绍通过NPC触发任务的游戏制作代码 using System Collections using System Collections Generic using UnityEngine
  • 游戏开发常见操作梳理系列之——玩家信息的显示系统

    在游戏中 有不少游戏在左上角会出现玩家的头像和等级以及血量 这就是玩家的信息显示系统 那么这些是如何制作的呢 接下来我将讲讲代码的操作 其它操作我会在其它笔记中一一说明 敬请期待 信息的显示相当简单就是控制一些UI 然后在其它系统里面填写相
  • 游戏开发常见操作梳理之小地图的制作

    游戏中一般存在小地图系统 实际上就是设置一个新的摄像机放置在玩家的正上方 然后在小地图上显示新摄像机看见的东西就可以了 在小地图上一般存在放大地图和缩小地图的按钮可以方便放大和缩小地图 这些操作是如何实现的呢 接下来直接上核心代码 usin

随机推荐