3D 游戏与编程——作业二

1、简答题

1)解释 游戏对象(GameObject)和 资源(Assets)的区别和联系

Assets 是游戏中具体的资源,比如 texture,mesh,material,shader,script 等,它们存在于文件夹中,不一定用到;GameObject 是游戏中实际存在的对象,由 Assets 实例化而来,是对 Assets 的引用和复制的关系。

2)下载几个游戏案例,总结资源、对象组织的结构(指资源的目录组织结构与游戏对象树的层次结构)

以上是某个游戏的资源的结构,包含模型,预制,脚本等游戏资源,分门别类地存放在不同文件夹中,便于整理和使用。


上图是该游戏对象的结构,根据对象的类型(General, Player, Lever, Game-Mode)存放在不同文件夹下,便于修改,组织。

3)编写一个代码,使用debug 语句来验证 MonoBehaviour 基本行为或事件触发的条件。(基本行为包括 Awake() Start() Update() FixedUpdate() LateUpdate();常用事件包括 OnGUI() OnDisable() OnEnable() )

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class FirstBeh : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){Debug.Log("This Start!");}// Update is called once per framevoid Update(){Debug.Log("This Updated");}void OnEnable(){Debug.Log("This Enabled");}void OnDisable(){Debug.Log("This Disabled");}void Awake(){Debug.Log("This Awaked");}void LateUpdated(){Debug.Log("This LateUpdated");}void FixedUpdate(){Debug.Log("This FixedUpdate");}private void OnGUI(){Debug.Log("This is ONGUI");}
}

Awake:当一个游戏对象实例被载入时被调用,或是脚本构造时调用
Start:第一次进入游戏循环时调用
Update:当行为启用时,其 Update 在每一帧被调用
Fixedupdate:当行为启用时,其 Fixedupdate 在每一时间片被物理引擎调用
OnGUI:渲染和处理 GUI 事件时调用
OnEnable:当对象变为可用或激活状态时被调用
OnDisable:当对象变为不可用或非激活状态时被调用
LateUpdate:所有 Update 调用完之后,被游戏循环调用

4)查找脚本手册,了解 GameObject,Transform,Component 对象
分别翻译官方对三个对象的描述(Description)
描述下图中 table 对象(实体)的属性、table的Transform的属性、table的部件
用UML 图描述 三者的关系(请使用UMLet 14.1.1 stand-alone版本出图)、

Description:

  • GameObject:是Unity场景里面所有实体的基类。

  • Transform:物体的位置、旋转和缩放。

  • Component:一切附加到游戏物体的基类。

描述:

  • activeSelf:可以定义对象的名称,动静态等属性
  • Transform:可以定义对象的位置、面向方向、大小
  • Box Collider:可以调整坐标系的位置、大小
  • Component:可以给对象增加行为

5)资源预设(Prefabs)与对象克隆(clone)
预设(Prefabs)有什么好处?
预设与对象克隆(clone or copy or Instantiate of Unity Object)关系?
制作 table 预制,写一段代码将 table 预制资源实例化成游戏对象

资源预设(Prefabs)的好处:

预设就是将设计游戏中所需要的游戏对象进行设计打包,成为一个新的整体,在接下来的设计中作为一个新对象与其他组件发生交互。预设充分发挥了“组合优于继承”的思想和面向对象的思想,让我们在设计过程中更加灵活快捷。

预设与对象克隆的关系:

克隆是将已经存在的游戏对象,或者是资源当中的预设进行复制。预设本身不需要有实例化的游戏对象,而克隆需要复制实例化的游戏对象。而且如果要集中修改通过将预设实例化创建出来的对象,只需要修改预设就能全都修改,方便批量修改。而如果要修改克隆出来的对象只能一个一个修改。

void Start(){print("hello");Debug.Log("start!");Object temp = Resources.Load("new_table");GameObject cube = Instantiate(temp) as GameObject;cube.transform.position = new Vector3(0, 5, 0);}

2、编程实践,小游戏

简单计算器
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Calculator : MonoBehaviour
{public string str_res;public static string str_a;public static string str_b;public static string str_opera;float res;void Start(){Init();}void Init(){str_res = "0";str_a = "";str_b = "";str_opera = "";res = 0;}void OnGUI(){GUI.Box(new Rect(0, 0, 350, 220), "");//对数字进行处理if (GUI.Button(new Rect(0, 0, 50, 30), "1")){str_a += "1";str_res = str_a;}if (GUI.Button(new Rect(60, 0, 50, 30), "2")){str_a += "2";str_res = str_a;}if (GUI.Button(new Rect(120, 0, 50, 30), "3")){str_a += "3";str_res = str_a;}if (GUI.Button(new Rect(180, 0, 50, 30), "4")){str_a += "4";str_res = str_a;}if (GUI.Button(new Rect(0, 40, 50, 30), "5")){str_a += "5";str_res = str_a;}if (GUI.Button(new Rect(60, 40, 50, 30), "6")){str_a += "6";str_res = str_a;}if (GUI.Button(new Rect(120, 40, 50, 30), "7")){str_a += "7";str_res = str_a;}if (GUI.Button(new Rect(180, 40, 50, 30), "8")){str_a += "8";str_res = str_a;}if (GUI.Button(new Rect(0, 80, 50, 30), "9")){str_a += "9";str_res = str_a;}if (GUI.Button(new Rect(60, 80, 50, 30), "0")){str_a += "0";str_res = str_a;}//计算符号if (GUI.Button(new Rect(120, 80, 50, 30), "+")){str_opera = "+";print(str_b);if (str_a != null){str_b = str_a;}str_a = "";str_res = str_b;}if (GUI.Button(new Rect(60, 120, 50, 30), "-")){str_opera = "-";if (str_a != null){str_b = str_a;}str_a = "";str_res = str_b;}if (GUI.Button(new Rect(0, 120, 50, 30), "*")){str_opera = "*";if (str_a != null){str_b = str_a;}str_a = "";str_res = str_b;}if (GUI.Button(new Rect(180, 80, 50, 30), "/")){str_opera = "/";if (str_a != null){str_b = str_a;}str_a = "";str_res = str_b;}if (GUI.Button(new Rect(0, 160, 50, 30), "C")){if (str_a == ""){str_res = "0";return;}else{str_a = str_a.Substring(0, str_a.Length - 1);}str_res = str_a;}if (GUI.Button(new Rect(120, 120, 50, 30), "=")){if (str_opera == "+"){res = float.Parse(str_b) + float.Parse(str_a);}else if (str_opera == "-"){res = float.Parse(str_b) - float.Parse(str_a);}else if (str_opera == "*"){res = float.Parse(str_b) * float.Parse(str_a);}else if (str_opera == "/"){res = float.Parse(str_b) / float.Parse(str_a);}str_b = res.ToString();str_a = "";str_res = res.ToString();}if (GUI.Button(new Rect(180, 120, 50, 30), "CE")){str_a = "";str_a = "";res = 0;str_res = "";}GUI.Label(new Rect(300, 0, 100, 30), str_res);}
}

测试截图:

Unity 3D 游戏与编程相关推荐

  1. Unity 3D游戏代码编程学习教程 Full Guide To Unity 3D C#: Learn To Code Making 3D Games

    Unity 3D游戏代码编程学习教程 Full Guide To Unity 3D & C#: Learn To Code Making 3D Games Full Guide To Unit ...

  2. unity 3d游戏开发_使用Unity 5开发3D游戏

    unity 3d游戏开发 If there's one thing cooler than playing games, it's building games. 如果有比玩游戏更酷的一件事,那就是构 ...

  3. 《Unity 3D 游戏开发技术详解与典型案例》——1.1节Unity 3D基础知识概览

    本节书摘来自异步社区<Unity 3D 游戏开发技术详解与典型案例>一书中的第1章,第1.1节Unity 3D基础知识概览,作者 吴亚峰 , 于复兴,更多章节内容可以访问云栖社区" ...

  4. Unity 3D 环境特效||Unity 3D 游戏场景设计实例

    Unity 3D 环境特效 一般情况下,要在游戏场景中添加雾特效和水特效较为困难,因为需要开发人员懂得着色器语言且能够熟练地使用它进行编程. Unity 3D 游戏开发引擎为了能够简单地还原真实世界中 ...

  5. Unity 3D - 游戏开发中的Lua

    Unity 3D - 游戏开发中的Lua : 本文作者:秦元培, 本文出处:http://blog.csdn.net/qinyuanpei/article/details/39826323 前言 : ...

  6. 《Unity 3D 游戏开发技术详解与典型案例》——1.3节第一个Unity 3D程序

    本节书摘来自异步社区<Unity 3D 游戏开发技术详解与典型案例>一书中的第1章,第1.3节第一个Unity 3D程序,作者 吴亚峰 , 于复兴,更多章节内容可以访问云栖社区" ...

  7. 雨松MOMO《Unity 3D游戏开发》源码公布

    原创文章如需转载请注明:转载自雨松MOMO程序研究院 本文链接地址:雨松MOMO<Unity 3D游戏开发>源码公布 下载源码时,首先大家请登陆图灵社区找到<Unity 3D游戏开发 ...

  8. 【Unity 3D游戏开发】在Unity使用NoSQL数据库方法介绍

    随着游戏体积和功能的不断叠加,游戏中的数据也变得越来越庞杂,这其中既包括玩家产生的游戏存档等数据,例如关卡数.金币等,也包括游戏配置数据,例如每一关的配置情况.尽管Unity提供了PlayerPref ...

  9. Unity 3D游戏发布到Android平台

    Android 是目前最流行的一个词,Android 的游戏.软件等几乎是人们每天都要用到的.要将 apk 文件发布到 Android 平台,必须先安装两个工具:Java(JDK)和 Android ...

最新文章

  1. 三维点云的深度学习研究综述
  2. 【跃迁之路】【658天】程序员高效学习方法论探索系列(实验阶段415-2018.12.02)...
  3. vs2015配置opencv3.3
  4. RequestMapping介绍
  5. 欧冠淘汰赛第二回合!我厂生死战!!
  6. Spring陷阱:代理
  7. 单片机如何用普通电池供电?
  8. 基于JAVA+Servlet+JSP+MYSQL的汽车维修保养管理系统
  9. 关于.Net Application Server对象访问方式的设计(2.上)
  10. Web性能测试工具:http_load安装使用简介
  11. Perl语言入门(05 文件)
  12. wps交叉表_WPS Office
  13. C语言中的万能头文件
  14. java垃圾回收的方法_java垃圾回收的方法都有哪些
  15. word文档中英文行间距不一样怎么解决
  16. 使用SVG构建icon
  17. java二元一次方程求极值_二元一次方程的最值怎么求,最大值和最 二元一次方程...
  18. 手机编程软件推荐(C/C++、JAVA篇)
  19. 水溶性CdSe/ZnS量子点(520nm)
  20. 华为ENSP模拟器开启SSH服务

热门文章

  1. “Word文件设置了多级列表,却还是不能创建目录”的解决办法
  2. 贵州小县城出身的“网约车品牌”,如何拓县出省、走向全国?
  3. 数据库SQL实战 --42.将id=5以及emp_no=10001的行数据替换成id=5以及emp_no=10005
  4. 《十周成为数据分析师》笔记——业务线 第五节 用户画像体系
  5. 【计算机视觉】关于用opencv 设置摄像头读分辨率问题的若干说明
  6. oracle11g memory_target,oracle11g要求在操作系统层设定共享内存/dev/shm,且大于MEMORY_TARGET...
  7. 几种颜色单位设置(颜色设置)
  8. chromedriver与chrome各版本对应及下载地址
  9. 【求助】winfrom怎么获取视频当前播放时间
  10. 浅谈汽车软件Boot的五种自刷新方式