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. String类的知识点(不断更新)

    知识点1.String类位于java.lang包中,具有丰富的方法计算字符串的长度.比较字符串.连接字符串.提取字符串2.数组的length是属性,字符串的length()是方法3.import ja ...

  2. opencv学习之路(4)、Mat类介绍,基本绘图函数

    一.Mat类创建 Mat img;//创建无初始化矩阵 Mat img1(,,CV_8UC1);//200行,100列(长200,宽100) Mat img2(Size(,),CV_8UC3,Scal ...

  3. 基础_模型迁移_CBIR_augmentation

    在之前我们做过这样的研究:5图分类CBIR问题 各不相同的 5类的图形,每类100张 import numpy as npfrom keras.datasets import mnistimport  ...

  4. 20145326蔡馨熤《网络对抗》——MSF基础应用

    20145326蔡馨熤<网络对抗>——MSF基础应用 实验后回答问题 用自己的话解释什么是exploit,payload,encode. exploit:起运输的作用,将数据传输到对方主机 ...

  5. topcoder srm 480 div1

    problem1 link 直接模拟即可. problem2 link 首先,网关一定是安装在client与server之间的链路上.而不会安装在client与client之间的链路上.对于一条路径c ...

  6. SSM集成activiti6.0错误集锦(一)

    项目环境 Maven构建 数据库:Orcle12c 服务器:Tomcat9 <java.version>1.8</java.version> <activiti.vers ...

  7. Python3 tkinter基础 Listbox for+insert 将list中元素导入listbox中

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. Restful framework【第八篇】频率组件

    基本使用 频率: -限制每个ip地址一分钟访问10次 -写一个类 from rest_framework.throttling import SimpleRateThrottle class Visi ...

  9. gerrit的使用笔记

    1.clone的时候一定要同时选择上clone with commit-msg hook和ssh,这样才能使用change id,同时使用ssh push到remote. 2.如果是使用了clone ...

  10. bzoj4008: [HNOI2015]亚瑟王 dp

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=4008 思路 神仙啊 \(f[i][j]表示第i个点有j次机会(不管成功与否)\) \(f ...