版本:Unity 6 (6000.0)
语言英语
  • C#

AssetDatabase.GetCachedIcon

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们会阅读用户建议的每项更改,并在适用时进行更新。

关闭

提交失败

由于某种原因,无法提交您建议的更改。请在几分钟后<a>重试</a>。感谢您花时间帮助我们提高 Unity 文档的质量。

关闭

取消

声明

public static Texture GetCachedIcon(string path);

描述

检索给定资产路径处资产的图标。

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Get Cached Icon Example")] public static void GetCachedIconExample() { var textureList = new List<Texture>(); //Get asset icons and put them in a list foreach (var guid in AssetDatabase.FindAssets("", new []{"Assets"})) { var path = AssetDatabase.GUIDToAssetPath(guid); textureList.Add(AssetDatabase.GetCachedIcon(path)); }

//Set Material textures to the asset icons var textureNo = 0; for (var i = 0; i < 10; i++) { var path = $"Assets/Materials/GroundMaterial{i}.mat"; var asset = (Material)AssetDatabase.LoadMainAssetAtPath(path); if (textureNo >= textureList.Count) textureNo = 0; asset.mainTexture = textureList[textureNo++]; } } }