第一次作业(图片未上传)
1、简答题
解释 游戏对象(GameObjects) 和 资源(Assets)的区别与联系。
-
游戏对象(GameObjects)
官方文档:Every object in your game is a GameObject, from characters and collectible items to lights, cameras and special effects. However, a GameObject can’t do anything on its own; you need to give it properties before it can become a character, an environment, or a special effect.自我理解:游戏对象(GameObjects)就是Unity 场景中所有实体的基类,游戏中的每个对象都是一个游戏对象,包括可收藏的物品到灯光、相机还有特效等等。文档提到一个游戏对象不能自己做任何事情;你需要给它一些属性,才能使它成为一个角色、一个环境或一个特殊效果。
-
资源(Assets)
官方文档:An Asset is a representation of any item you can use in your game or Project. An Asset may come from a file created outside of Unity, such as a 3D Model, an audio file, an image, or any of the other file types that Unity supports. There are also some Asset types that you can create in Unity, such as a ProBuilder Mesh, an Animator Controlle, an Audio Mixer, or a Render Texture.自我理解:就是一种可以在游戏项目中使用的资源,包括各种3d模型、音视频、图像等,同时我们也可以创建游戏对象(GameObjects)并组合起来,制作为预设(Prefabs),也是供使用的一种资源。总而言之,资源(Assets)就是一系列游戏编程中需要使用到的素材。
-
区别与联系
区别:游戏对象是游戏中一个实体,是在游戏中充当某个角色的;而资源作为素材可供游戏对象使用,或者使用资源组成新的游戏对象。联系: 上面的解释也提到,游戏对象可以组合起来制作成预设以供此场景或其他场景使用的资源;同时游戏对象也需要由各种资源组成,包括脚本、音视频等,相当于赋予一个游戏对象属性。
下载几个游戏案例,分别总结资源、对象组织的结构(指资源的目录组织结构与游戏对象树的层次结构)
我在官网的Assets store下载了一个游戏案例教程Space Shooter,资源与对象组织结构如下。游戏对象的组织是根据游戏中各对象所扮演的角色决定的,如Done_Player是一个完整的飞机,所以它底下还包括组成飞机的各个部件,而相互独立的对象是并列的。一个完整的游戏的资源组织为Audio、Materials、Models、Prefabs、Scripts、Scenes、Textures等,可以看到这个游戏的完整仅包括Materials、Prefabs、Scripts、Scenes。
[外链图片转存失败(img-gbNGnmLl-1568338766497)(img/2.png)]
[外链图片转存失败(img-rP7OznQR-1568338766499)(img/3.png)]
编写一个代码,使用 debug 语句来验证 MonoBehaviour 基本行为或事件触发的条件
- 基本行为包括 Awake() Start() Update() FixedUpdate() LateUpdate()
- 常用事件包括 OnGUI() OnDisable() OnEnable()
代码如下
//TestBeh.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestBeh : MonoBehaviour
{
//First run in project
void Awake()
{
Debug.Log("Init Awake");
}
// Start is called before the first frame update
void Start()
{
Debug.Log("Init Start");
}
// Update is called once per frame
void Update()
{
Debug.Log("Init Update");
}
//FixedUpdate is called every fixed frame-rate frame.
void FixedUpdate()