unity实验报告Word文档下载推荐.docx
《unity实验报告Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《unity实验报告Word文档下载推荐.docx(15页珍藏版)》请在冰点文库上搜索。
二、实验方法
本次实验是以windows操作系统为平台,通过unity3d软件进行本次实验的项目实现,unity3d是一个十分优秀的全面整合的专业游戏引擎。
通过unity3d软件和编程工具的结合可以轻松创建各种3D模型,模拟模型动态以及插入互动内容。
三、实验内容、步骤及结果
1.实验内容
本次实验是通过unity3d软件完成一个综合的应用系统。
并且本次实验所设计的系统要实现的功能如下:
(1)漫游浏览(三维);
(2)连接数据库(SQLServer2008);
(3)音视频播放;
(4)绘制简单图形;
(5)基本GUI元素显示;
2.实验步骤及结果
步骤:
(1)场景设计以及构思;
(2)项目实施及代码编写;
(3)场景代码相结合;
(4)进行调试。
结果:
1)基本GUI元素显示:
代码如下:
#pragmastrict
varstr:
String;
varmm:
functionStart(){
}
functionUpdate(){
functionOnGUI(){
GUI.BeginGroup(Rect(Screen.width/2-150,Screen.height/2-100,400,300));
GUI.Label(Rect(20,20,80,30),"
菜单:
"
);
if(GUI.Button(Rect(100,40,60,20),"
自动漫游"
)){
Application.LoadLevel("
}
if(GUI.Button(Rect(100,10,60,20),"
音频播放"
if(GUI.Button(Rect(100,70,60,20),"
画线"
if(GUI.Button(Rect(100,100,60,20),"
视频播放"
GUI.EndGroup();
2)绘制简单图形:
publicclassNewBehaviourScript:
MonoBehaviour{
ArrayListpX=newArrayList();
ArrayListpY=newArrayList();
publicMaterialmat;
//Point3dpts3d=newPoint3d();
Vector3mousePos=newVector3();
enumDrawMode
{
Null,Lines,Triangle,Rectangle
};
DrawModedm;
boolTriClose=false;
//Usethisforinitialization
voidStart()
dm=DrawMode.Null;
//Updateiscalledonceperframe
voidUpdate()
mousePos=Input.mousePosition;
if(Input.GetMouseButton(0))
pX.Add(Input.mousePosition.x);
pY.Add(Input.mousePosition.y);
voidOnGUI()
//此处略。
3)音视频播放:
音频:
usingUnityEngine;
usingSystem.Collections;
publicclassmusic:
voidStart(){
voidUpdate(){
voidOnGUI(){
if(GUI.Button(newRect(Screen.width/2-100,Screen.height-30,50,20),"
Start"
gameObject.audio.Play();
}
if(GUI.Button(newRect(Screen.width/2-40,Screen.height-30,50,20),"
Pause"
gameObject.audio.Pause();
if(GUI.Button(newRect(Screen.width/2+20,Screen.height-30,50,20),"
Stop"
gameObject.audio.Stop();
if(GUI.Button(newRect(Screen.width/2+80,Screen.height-30,50,20),"
Return"
Application.LoadLevel("
loading"
视频:
publicclassvidio:
publicMovieTexturemovietexture;
publicboolON=false;
renderer.material.mainTexture=null;
movietexture.loop=true;
gameObject.audio.Stop();
if(GUI.Button(newRect(Screen.width/2-40,Screen.height-40,40,40),"
开关"
if(!
ON){
movietexture.Play();
renderer.material.mainTexture=movietexture;
gameObject.audio.Play();
ON=true;
}else{
movietexture.Stop();
gameObject.audio.Stop();
ON=false;
renderer.material.mainTexture=null;
}
if(GUI.Button(newRect(Screen.width/2,Screen.height-40,40,40),"
停止"
movietexture.Stop();
if(GUI.Button(newRect(Screen.width/2+40,Screen.height-40,40,40),"
暂停"
movietexture.Pause();
if(GUI.Button(newRect(Screen.width/2+80,Screen.height-40,40,40),"
返回"
4)漫游浏览(三维):
publicclassworking:
MonoBehaviour
{
floathSliderValue=1f;
publicGameObject[]path;
//定义一个数组用来存储路径方块
publicstaticinti=0;
//定义一个整型变量用来存储当前路径点序号
voidStart()
voidUpdate()
gameObject.transform.LookAt(path[i%path.Length].transform);
gameObject.transform.Translate(Vector3.forward*Time.deltaTime*hSliderValue);
if(Input.GetMouseButtonDown(0))
Rayray=Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHithit=newRaycastHit();
if(Physics.Raycast(ray,outhit))
print(hit.collider.gameObject.name);
GUI.skin.label.fontSize=10;
GUI.color=Color.cyan;
//GUI.Button(newRect(10,10,80,30),"
djfkj"
hSliderValue=GUI.HorizontalSlider(newRect(Screen.width-200,40,100,30),hSliderValue,0.0f,100.0f);
//GUI.contentColor=Color.black;
GUI.Label(newRect(Screen.width-200,15,200,30),"
漫游速度:
+hSliderValue.ToString()+"
m/s"
//空间坐标
//GUI.Label(newRect(10,Screen.height-20,100,30),"
X坐标:
+transform.position.x+"
m"
//GUI.Label(newRect(120,Screen.height-20,100,30),"
Y坐标:
+transform.position.y+"
//GUI.Label(newRect(230,Screen.height-20,100,30),"
Z坐标:
+transform.position.z+"
if(GUILayout.Button("
四、实验结果以及心得体会
从普通用户的角度来说,3D
Unity功能齐全,容易使用,3D模型导入比较容易,做3D项目比较容易。
从开发人员的角度来说,使用3D
Unity已有的功能,是很方便,但是一旦涉及到某些地方要定制化就很难做。
由于它不能直接调用操作系统底层功能,因此,定制化模块的性能会比较差。
3Dunity适合做房产演示、产品演示、小型网络游戏。
但是不适合做大型网络游戏,和用户定制化要求比较高的项目。