Resources.LoadAssetAtPath 加载所在路径的资源

static function LoadAssetAtPath (assetPath : string, type : Type) : Object

Description描述

Returns a resource at an asset path (Editor Only).

返回所在资源路径上的一个资源(编辑器仅仅)。

This function always return null in the standalone player or web player. This is useful for quickly accessing an asset for use in the editor only.

在独立版或者web播放器中这个函数总是返回null。这个可以用来快速访问一个在编辑器中使用的资源。

Note: ALL asset names & paths in Unity are with forward slashes, if you use backward slashes for paths you will get errors.

注意:所有资源名字和路径在Unity是带有正斜杠,如果在路径中使用反斜杠,将获得错误。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public GameObject prefab;
	void Start() {
		prefab = Resources.LoadAssetAtPath("Assets/Artwork/mymodel.fbx", typeof(GameObject));
	}
}
var prefab : GameObject;

function Start () {
	prefab = Resources.LoadAssetAtPath("Assets/Artwork/mymodel.fbx", GameObject);
}
Page last updated: 2011-3-13