Unity---资源管理中不同资源的路径获取方式
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---资源管理中不同资源的路径获取方式的更多相关文章
- IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404
IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404 .embody{ padding:10px 10px 10px; margin:0 -20px; borde ...
- Java中的资源文件加载方式
文件加载方式有两种: 使用文件系统自带的路径机制,一个应用程序只能有一个当前目录,但可以有Path变量来访问多个目录 使用ClassPath路径机制,类路径跟Path全局变量一样也是有多个值 在Jav ...
- Spring Boot 中初始化资源的几种方式(转)
假设有这么一个需求,要求在项目启动过程中,完成线程池的初始化,加密证书加载等功能,你会怎么做?如果没想好答案,请接着往下看.今天介绍几种在Spring Boot中进行资源初始化的方式,帮助大家解决和回 ...
- Spring Boot 中初始化资源的几种方式
假设有这么一个需求,要求在项目启动过程中,完成线程池的初始化,加密证书加载等功能,你会怎么做?如果没想好答案,请接着往下看.今天介绍几种在Spring Boot中进行资源初始化的方式,帮助大家解决和回 ...
- Laravel从模型中图片的相对路径获取绝对路径
在模型product.php中增加以下方法.数据库图片字段为image.存储的图片相对路径 public function getImageUrlAttribute() { // 如果 image 字 ...
- Spring Boot中初始化资源的几种方式
CommandLineRunner 定义初始化类 MyCommandLineRunner 实现 CommandLineRunner接口,并实现它的 run()方法,在该方法中编写初始化逻辑 注册成Be ...
- springMVC中响应的返回值获取方式
package com.hope.controller;import com.hope.domain.User;import org.springframework.stereotype.Contro ...
- 细谈unity资源管理的设计
一.概要 本文主要说说Unity是如何管理的,基于何种方式,基于这种管理方式,又该如何规划资源管理,以及构建bundle,是后面需要详细讨论的. 二.Unity的资源管理方式 2.1 资源分类 uni ...
- 直接在apk中添加资源的研究
原文 http://blog.votzone.com/2018/05/12/apk-merge.html 之前接手过一个sdk的开发工作,在开发过程中有一个很重要的点就是尽量使用代码来创建控件,资源文 ...
随机推荐
- Python学习基础(三)——装饰器,列表生成器,斐波那契数列
装饰器——闭包 # 装饰器 闭包 ''' 如果一个内部函数对外部(非全局)的变量进行了引用,那么内部函数被认为是闭包 闭包 = 函数块 + 定义时的函数环境 ''' def f(): x = 100 ...
- Huffman Implementation with Python
Huffman Implementation with Python 码表 Token Frequency a 10 e 15 i 12 s 3 t 4 space 13 n 1 生成 Huffman ...
- 06: 字典、顺序表、列表、hash树 实现原理
算法其他篇 目录: 1.1 python中字典对象实现原理 1.2 顺序表 1.3 python 列表(list) 1.1 python中字典对象实现原理返回顶部 注:字典类型是Python中最常 ...
- 从输入URL到页面显示发生了什么
阅读目录 1.输入地址 2.浏览器查找域名的 IP 地址 3.浏览器向 web 服务器发送一个 HTTP 请求 4.服务器的永久重定向响应 5.浏览器跟踪重定向地址 6.服务器处理请求 7.服务器返回 ...
- 5.sql2008分组与嵌套
1.Group by基本介绍;2.Having的使用;3.分组综合应用;4.子查询基本介绍;5.In/Exists/Any/Some/All;6.子查询综合应用; 1.Group by基本介绍:依据B ...
- 洛谷1968美元汇率 dp
P1968 美元汇率 dp 题目描述 在以后的若干天里戴维将学习美元与德国马克的汇率.编写程序帮助戴维何时应买或卖马克或美元,使他从100美元开始,最后能获得最高可能的价值. 输入输出格式 输入格式: ...
- 0-1背包dp|波动数列|2014年蓝桥杯A组10-fishers
标题:波动数列 观察这个数列: 1 3 0 2 -1 1 -2 ... 这个数列中后一项总是比前一项增加2或者减少3. 栋栋对这种数列很好奇,他想知道长度为 n 和为 s 而且后一项总是比前一项增加a ...
- FAQ Flyway
https://flywaydb.org/documentation/faq What is the best strategy for dealing with hot fixes? You hav ...
- python 安装wheel .whl文件
首先得有pip没有的话安装一个. 然后:pip install wheel 然后:pip install 路径\文件名.whl ===================== pip --versionp ...
- HDU 6061 RXD and functions(NTT)
题意 给定一个\(n\) 次的 \(f\) 函数,向右移动 \(m\) 次得到 \(g\) 函数,第 \(i\) 次移动长度是 \(a_i\) ,求 \(g\) 函数解析式的各项系数,对 ...