1、首先需要先了解两个知识点: Unity内置的文件路径获取方式、windows的Directory.GetFiles文件获取方式:

   1>Unity内置的文件路径获取方式,以下是官方解释:https://docs.unity3d.com/ScriptReference/AssetDatabase.FindAssets.html

  以下是自己对AssetDatabase类中一些方法的简单测试:

 

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor; using UnityEngine;
using UnityEditor; public class TestAssetDatabase : Editor
{
const string TestMatPath = @"Assets/Materials/";
const string TestMatName = "TestMaterial.mat"; static string MatPath = string.Format("{0}{1}", TestMatPath, TestMatName); [MenuItem("Tools/Create Asset")]
static void CreateMaterial()
{
var material = new Material(Shader.Find("Specular"));
AssetDatabase.CreateAsset(material, MatPath); //Materials文件夹 需要手动创建
} [MenuItem("Tools/Delete Asset")]
static void DeleteMaterial()
{
AssetDatabase.DeleteAsset(MatPath);
} [MenuItem("Tools/Copy Asset")]
static void CopyMaterial()
{
AssetDatabase.CopyAsset(MatPath, "Assets/NewMaterials/TestMaterial.mat"); //NewMaterials文件夹 需要手动创建
} [MenuItem("Tools/Load Asset")]
static void LoadMaterial()
{
//加载资源两种不同的写法,需要些资源后缀的
//Material mat = AssetDatabase.LoadAssetAtPath<Material>(MatPath);
Material mat = AssetDatabase.LoadAssetAtPath(MatPath, typeof(Material)) as Material;
Debug.Log(mat.color);
} //Filter可以是:Name、Lable、Type(内置的、自定义) //Type 关键字 t:
static string fliterMat = "t:Material"; //单个
static string filterPrefab = "t:Prefab";
static string fliterMatPre = "t:Material t:Prefab"; //多个
static string filterCustomDefine = "t:CustomDefine"; //自定义的类型,需要是ScriptableObject创建的资源 //Label 关键字 l:
static string filterLabel = "l:lgs"; static string filterMixed = "Cube l:lgs"; //混合过滤---名字中有Cube,Label为 lgs [MenuItem("Tools/Find Asset")]
static void FindAsset()
{
string[] guidArray = AssetDatabase.FindAssets(filterMixed);
foreach (string item in guidArray)
{
Debug.Log(AssetDatabase.GUIDToAssetPath(item)); //转换来的资源路径是带有后缀名字的
}
}
}

   2>windows的Directory.GetFiles文件获取方式,官方解释:https://docs.microsoft.com/zh-cn/dotnet/api/system.io.directory.getfiles?view=netframework-4.7.2#System_IO_Directory_GetFiles_System_String_System_String_System_IO_SearchOption_

  以下是官方代码示例(指定以字母开头的文件数):

 using System;
using System.IO; class Test
{
public static void Main()
{
try
{
// Only get files that begin with the letter "c."
string[] dirs = Directory.GetFiles(@"c:\", "c*");
Console.WriteLine("The number of files starting with c is {0}.", dirs.Length);
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}

在获取不同资源的时候,只需要对不同类型的资源加以不同的过滤标签,
例如:
过滤器,若以t:开头,表示用unity的方式过滤;若以f:开头,表示用windows的SearchPattern方式过滤;若以r:开头,表示用正则表达式的方式过滤
再根据过滤标签,获取不同的资源路径即可

Unity---资源管理中不同资源的路径获取方式的更多相关文章

  1. IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404

    IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404 .embody{ padding:10px 10px 10px; margin:0 -20px; borde ...

  2. Java中的资源文件加载方式

    文件加载方式有两种: 使用文件系统自带的路径机制,一个应用程序只能有一个当前目录,但可以有Path变量来访问多个目录 使用ClassPath路径机制,类路径跟Path全局变量一样也是有多个值 在Jav ...

  3. Spring Boot 中初始化资源的几种方式(转)

    假设有这么一个需求,要求在项目启动过程中,完成线程池的初始化,加密证书加载等功能,你会怎么做?如果没想好答案,请接着往下看.今天介绍几种在Spring Boot中进行资源初始化的方式,帮助大家解决和回 ...

  4. Spring Boot 中初始化资源的几种方式

    假设有这么一个需求,要求在项目启动过程中,完成线程池的初始化,加密证书加载等功能,你会怎么做?如果没想好答案,请接着往下看.今天介绍几种在Spring Boot中进行资源初始化的方式,帮助大家解决和回 ...

  5. Laravel从模型中图片的相对路径获取绝对路径

    在模型product.php中增加以下方法.数据库图片字段为image.存储的图片相对路径 public function getImageUrlAttribute() { // 如果 image 字 ...

  6. Spring Boot中初始化资源的几种方式

    CommandLineRunner 定义初始化类 MyCommandLineRunner 实现 CommandLineRunner接口,并实现它的 run()方法,在该方法中编写初始化逻辑 注册成Be ...

  7. springMVC中响应的返回值获取方式

    package com.hope.controller;import com.hope.domain.User;import org.springframework.stereotype.Contro ...

  8. 细谈unity资源管理的设计

    一.概要 本文主要说说Unity是如何管理的,基于何种方式,基于这种管理方式,又该如何规划资源管理,以及构建bundle,是后面需要详细讨论的. 二.Unity的资源管理方式 2.1 资源分类 uni ...

  9. 直接在apk中添加资源的研究

    原文 http://blog.votzone.com/2018/05/12/apk-merge.html 之前接手过一个sdk的开发工作,在开发过程中有一个很重要的点就是尽量使用代码来创建控件,资源文 ...

随机推荐

  1. rhel 6 version `GLIBC_2.14' not found (required by /usr/lib64/libstdc++.so.6)以及libstdc++.so.6: version GLIBCXX_3.4.18 not found解决办法

    最近在oracle linux 7.3下开发了个应用,发布到rhel 6.5运行的时候,报version `GLIBC_2.14' not found (required by /usr/lib64/ ...

  2. 批处理no.bat

    在公司每次我启动电脑, 网络连接需要一段时间, 而我想在这段小时间里面, 一旦网络连接成功就帮我启动微信和qq, 如果还没有连接成功就继续监测直到有网络了才会成功才会打开两个程序, 当打开程序后脚本自 ...

  3. 识别简单的答题卡(Bubble sheet multiple choice scanner and test grader using OMR, Python and OpenCV——jsxyhelu重新整编)

    该博客转自www.pyimagesearch.com,进行了相关修改补充. Over the past few months I've gotten quite the number of reque ...

  4. outlook使用笔记

    使用电子邮件客户端(pc端)软件, 确实是不得已. 出于某些考试/了解的目的? 现在使用 在线/网页端电子邮件 确实要好得多, 方便得多了. outlook和其他软件都是 设置的 "帐户 a ...

  5. [HDU 1976] Software Version

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1976 #include<iostream> #include<cstdio> ...

  6. [ajaxupload] - 上传文件同时附件参数值

    $.ajax({ url: '/excel/importExcel?instance='+"品种1", type: 'POST', data: formData, 上面前端通过?拼 ...

  7. String、StringBuffer 的使用 ,两个面试问题

    1>统计不同类型字符个数 public static void main(String[] args) { //案例:统计不同类型字符个数 String password = "abZ ...

  8. 3、lvs调度方法详解

    3.lvs类型和调度方法详解    http://www.178linux.com/13570 集群:将多台主机组织起来满足某一特定需求: 集群类型: LB:Load Balancing, 负载均衡集 ...

  9. Android CPU耗电量测试

    Android CPU耗电量测试 在测试Android app时,不仅仅要关注app的功能,也好关注app的性能指标,cpu.内存.流量.电量等.简单介绍下电量测试中的cpu耗电. 影响耗电的因素 C ...

  10. Using keytool to import keystore

    open command line and locate to the location of  keytool.exe. import cert to keystore command: keyto ...