1.预设体对象--GameObject 2.音效文件--AudioClip 3.文本文件--TextAsset 4.图片文件--Texture 5.其他的需要什么类型用什么类型就好 注意:预设体对象加载需要实例化 关于Resources的方法: FindObjectOfTypeAll:返回某一种类型的所有资源 Load:通过路径加载资源 LoadAll:加载该Resources下
在一个工程当中 Resources文件夹 可以有多个 通过API加载时 会去这些同名的Resources文件夹中去找资源 打包时Resources文件夹里的内容 都会打包在一起 2 加载对象 2.1 预设体对象——GameObject 预设体对象加载需要实例化 加载预设体的资源文件(本质上 就是加载 配置数据 在内存中) Object obj = Resources.Load("Cu...
public class PanelOne : MonoBehaviour { private GameObject levelPreb; private Text levename; private Image startnum; private Text Moneynumtxt; private int Moneynum; void Awake() { Moneynum = 500; //把资源加载到内存中 levelPreb = Resources.Load<GameObject>("Prefabs/guan"); Moneynumtxt = t...
stringfilePath ="img/abc"; vartexture = Resources.Load<Texture2D>(filePath); GameObject obj =newGameObject("newname",typeof(SpriteRenderer)); SpriteRenderer render = obj.GetComponent<SpriteRenderer>();varsprite = Sprite.Create(texture,newRect(0, 0, texture.width, texture.height),newVector2(0...
上面是第一种使用Resources.Load()的方式动态加载游戏对象的,然而在项目中更长用的却是第二种使用AssetBundle的方式动态加载游戏对象。 二、AssetBundle 使用AssetBundle打包预设或者场景可以将与其相关的所有资源打包,这样很好地解决资源的依赖问题,使得我们可以方便的加载GameObject。
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CreateBoxScript : MonoBehaviour { GameObject boxPrefab; Texture tex; // Start is called before the first frame update void Start() { /// boxPrefab = Resources.Load<GameObject>("Prefabs/box"); tex = Res...
public class ResourcesTest : MonoBehaviour { void Start () { //加载材质 Material material = Resources.Load<Material>("New Material"); //加载cube GameObject cube = Resources.Load("Cube") as GameObject; Instantiate(cube); //使用另一种方法加载 ...
1.确保资源文件位于"Resources"文件夹内。在Unity项目的Assets目录下创建一个子目录"Resources",并将要读取的资源文件放入该文件夹中。 2.调用Load方法来加载资源。该方法有多个重载形式,可以根据需要选择合适的形式。以下是其中一种常用的形式: GameObjectobj=Load<GameObject>("Prefabs/CubePrefab"); 上述代码示例...
GameObject instance = Instantiate(Resources.Load("enemy", typeof(GameObject))) as GameObject; } } public static T Load (string path); パラメーター path ターゲットとなるフォルダーのパス名。空文字を指定した場合は、Resources フォルダーにあるすべてのアセットを読み込みます。 説明 ...
1、在UNITY Assets目录下建立Resources目录并把资源放在里面; 2、在挂在的脚本中先加载资源 GameObject obj =Resources.Load<GameObject>("ttt"); 如果放在Resources目录下建的目录下,如在Resources/RRR 则为GameObject obj =Resources.Load<GameObject>("RRR/ttt"); ...