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. 锁(lock)和闩(latch)

    开发多用户.数据库驱动的应用时,最大的难点之一是:一方面要力争取得最大限度的并发访问,与此同时还要确保每个用户能以一致的方式读取和修改数据.为此就有了锁定(locking)机制,这也是所有数据库都具有 ...

  2. Codeforces 822D My pretty girl Noora - 线性筛 - 动态规划

    In Pavlopolis University where Noora studies it was decided to hold beauty contest "Miss Pavlop ...

  3. 如何获取sdcard的总容量

    activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android& ...

  4. python ---24 正则表达式 re模块

    一.正则表达式 1.字符组 ① [abc] 匹配a或b或c ②  [a-z] 匹配a到z之间的所有字⺟ [0-9]匹配所有阿拉伯数字 2.元字符 3.量词 4.重要搭配 ①  .*? ②  .*?x  ...

  5. Python3 tkinter基础 Frame bind 鼠标移动事件 实时显示鼠标的位置

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

  6. 【做题】CF239E. k-d-sequence——线段树

    首先,容易得到判断一个子串为"good k-d sequence"的方法: 子串中没有重复元素,且所有元素模d相等. 记mx为除以d的最大值,mn为除以d的最小值,则\(mx-mn ...

  7. centos远程访问

    centos远程访问即windows下的mysql和linux下的mysql能连接,即windows下的navicat能连接到(访问)centos下的mysql中的库表 (centos是linux的一 ...

  8. Trim Galore用法及参数考量

    Trim Galore是一个非常流行的用于「去接头序列」的软件,用于处理高通量测序得到的原始数据.通常我们从测序公司拿到数据后,第一步就是评估数据的质量以及对raw data去接头处理.公司拿来的数据 ...

  9. activiti 5.13流程图连线名称不显示bug修复

    使用modeler设计器,流程图连线名称是有显示的,但是运行结果却没显示.找到网上2遍文章,说是activiti框架中的一个bug,要修改 DefaultProcessDiagramGenerator ...

  10. 分布式强化学习基础概念(Distributional RL )

    分布式强化学习基础概念(Distributional RL) from: https://mtomassoli.github.io/2017/12/08/distributional_rl/ 1. Q ...