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 允许模型在识别图丢失的时候还存在 位置不变 在丢失的时候的位置 这样也
  • unity game界面按下play会不断闪烁,按下暂停键(pause)或者中止/下一步(step),game界面的画面会接连变化

    没找到答案 改了两个下午的程序 改完还是这样 后来发现是FixedUpdate Update与OnDrawGizmos的问题 OnDrawGizmos是每帧都会绘制 用FixedUpdate理所当然就那啥了 分析的时候 就突然想到是不是这俩
  • 游戏开发unity编辑器扩展知识系列:修改纹理资源的TextureType

    需要用TextureImporter导入资源 调用如下代码 TextureImporter importer TextureImporter TextureImporter GetAtPath path importer textureTy
  • Unity 资源加载卸载过程

    什么时候才是UnusedAssets 看一个例子 Object obj Resources Load MyPrefab GameObject instance Instantiate obj as GameObject Destroy in
  • using UnityEditor引用注意事项

    本文转载自http blog csdn net czlilove article details 19979725 在运行时脚本中使用UnityEditor命名空间 假如该脚本被挂在场景中的物体上 那么 可以这样做 在Unity编辑器中运行
  • Unity单元测试流程

    文章目录 环境 流程 1 创建一个存放 单元测试程序集 的目录 2 打开 Test Runner 窗口 3 选择单元测试模式 4 创建单元测试程序集 5 创建测试脚本 6 运行测试 环境 Unity 2020 3 3f1 流程 1 创建一个
  • 【UGUI】2D头顶血条制作

    前言 近期因为需要制作玩家和敌人头顶的2D血条 查找了很多博客 发现很多都拘束于Canvas的渲染模式必须要设定为ScreenSpace Overlay 还有应该是版本原因 我的是unity2019 1 11f1 用RecttTransfo
  • 【Unity&C#&随机数】随机数

    一个简单的随机数获得 0或1 使用了这样的代码 想要获得0或者1 if Input anyKeyDown float i 1 if i 1 i Random Range 0 Rang i i lt 0 5 0 1 Debug Log Cou
  • Unity 安卓打包

    Unity打包的方式有很多种 自动打包和手动打包 今天小弟就鼓捣鼓捣unity手动打包 如果想动态打包的话 可以去看其他大佬的帖帖哈 unity打包先配置环境 下载unity的时候可以顺道把unity的安卓包下载下来 如果忘了也没事 可以从
  • c#获取cpu序列号

  • Unity-AR 简介

    Unity AR 简介 现有Unity AR Sdk ARKit 苹果推出的AR开发平台 ARCore Google 推出的增强现实 SDK ARFoundation ARFoundation是ARKit XR插件和ARCore XR插件
  • Unity Shader入门精要第七章 基础纹理之遮罩纹理

    Unity系列文章目录 文章目录 Unity系列文章目录 前言 一 实践 参考 前言 遮罩纹理 mask texture 是本章要介绍的最后一种纹理 它非常有用 在很多商业游戏中 都可以见到它的身影 那么什么是遮罩呢 简单来讲 遮罩允许我们
  • Unity中按钮检测鼠标状态

    改方法主要是用于按钮检测鼠标的进入 滑出 点击 抬起 长按 长按停止 1 先将下面这个脚本挂载到需要检测鼠标状态的按钮上 using System Collections using System Collections Generic u
  • Unity中实现倒计时的几种方式

    1 Time time using UnityEngine public class TimeTest MonoBehaviour public float secound 10 void Update Timing private flo
  • Unity与Android的Back键冲突解决

    Unity与Android的Back键冲突解决 上一篇的最后留下了两个问题 Unity视图下横屏闪退 Unity视图下Android无法响应back返回上一activity 对于第一个问题 应该是Unity横屏下视图的某些设置跟Androi
  • Unity学习笔记(一)—— 基础知识

    一 基础知识 1 开发团队组成 2 unity特点 图形界面 所见即所得 入门简单 支持C 比OC C 更友好 js 国内外资源丰富 因为使用的人多 跨平台性好 PC端 移动端等 对VR AR的支持最完善 3 成功案例 游戏 炉石传说 神庙
  • unity实现鼠标右键控制视角

    主要实现的功能是相机跟随主角 鼠标右击移动后 相机的视角会旋转 思路 在主角里创建空的子物体 把相机绑在空物体上 通过旋转空物体来实现视角的旋转 要把相机调整到适当位置 代码如下 public float rotateSpeed 100 设
  • unity dots jobSystem 记录

    Looking for a way to get started writing safe multithreaded code Learn the principles behind our Job System and how it w
  • Unity中URP下的指数雾

    文章目录 前言 一 指数雾 雾效因子 1 FOG EXP 2 FOG EXP2 二 MixFog 1 ComputeFogIntensity 雾效强度计算 2 lerp fogColor fragColor fogIntensity 雾效颜

随机推荐