Version: 2021.3
言語: 日本語
public static Object LoadMainAssetAtPath (string assetPath);

パラメーター

assetPath 読み込むアセットのファイルシステム上のパス

説明

assetPath のメインアセットオブジェクトを返します。

The "main" Asset is the Asset at the root of a hierarchy (such as a Maya file which may contain multiples meshes and GameObjects).

すべてのパスは、例えば "Assets/MyTextures/hello.png" のような Project フォルダーに対する相対パスです。

See Also: AssetDatabase.LoadAssetAtPath, AssetDatabase.LoadAllAssetsAtPath, AssetDatabase.LoadAllAssetRepresentationsAtPath.

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

public class MyPlayer : MonoBehaviour { [MenuItem("AssetDatabase/Assign Materials To Models")] static void AssignGunMaterialsToModels() { var materials = new List<Material>(); //Get all the materials that have the name gun in them using LoadMainAssetAtPath foreach (var asset in AssetDatabase.FindAssets("t:Material gun")) { var path = AssetDatabase.GUIDToAssetPath(asset); materials.Add((Material)AssetDatabase.LoadMainAssetAtPath(path)); }

var materialID = 0; //Assign gun materials to their corresponding models MeshRenderer foreach (var asset in AssetDatabase.FindAssets("t:Model Gun")) { if (materialID >= materials.Count) materialID = 0; var path = AssetDatabase.GUIDToAssetPath(asset); var material = materials[materialID++]; material.shader = Shader.Find("Standard"); var modelMesh = (MeshRenderer) AssetDatabase.LoadAssetAtPath(path, typeof(MeshRenderer)); modelMesh.sharedMaterial = material; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961