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

AssetDatabase.GetMainAssetTypeFromGUID

建议更改

成功!

感谢你帮助我们改善 Unity 组件质量。虽然我们无法接受所有提交项,但是,我们会阅读我们用户提出的每项建议更改,并在必要时进行更新。

关闭

提交失败

由于某些原因,无法提交你建议的更改。请在几分钟后重试。感谢你花时间帮助我们改善 Unity 组件的质量。

关闭

取消

声明

public static Type GetMainAssetTypeFromGUID(GUID guid);

参数

guid 资产的 guid。

说明

返回具有 guid 的主资产对象的类型。

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

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Print Type Count")] static void GetAllAssetTypeCount() { var typeCount = new Dictionary<string, uint>(); //Put all the types that were found in the typeCount dictionary and increment their count foreach (var guid in AssetDatabase.FindAssets("", new []{"Assets"})) { var typeString = AssetDatabase.GetMainAssetTypeFromGUID(new GUID(guid)).ToString(); if (typeCount.ContainsKey(typeString)) typeCount[typeString]++; else typeCount.Add(typeString, 1); } //Print types and their count into the Unity Console foreach (var element in typeCount) { Debug.Log(element); } } }