ImageVerifierCode 换一换
格式:DOC , 页数:12 ,大小:266.54KB ,
资源ID:3027539      下载积分:8 金币
验证码下载
登录下载
邮箱/手机:
验证码: 获取验证码
温馨提示:
支付成功后,系统会自动生成账号(用户名为邮箱或者手机号,密码是验证码),方便下次登录下载和查询订单;
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/3027539.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  
声明  |  会员权益     获赠5币     写作写作

1、填表:    下载求助     留言反馈    退款申请
2、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
3、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
4、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
5、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前自行私信或留言给上传者【精****】。
6、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
7、本文档遇到问题,请及时私信或留言给本站上传会员【精****】,需本站解决可联系【 微信客服】、【 QQ客服】,若有其他问题请点击或扫码反馈【 服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【 版权申诉】”(推荐),意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:4008-655-100;投诉/维权电话:4009-655-100。

注意事项

本文(unity三D关键技术之导出Unity场景的所有游戏对象信息.doc)为本站上传会员【精****】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4008-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

unity三D关键技术之导出Unity场景的所有游戏对象信息.doc

1、 导出Unity场景所有游戏对象信息,一种是XML一种是JSON。本篇文章咱们把游戏场景中游戏对象、旋转、缩放、平移与Prefab名称导出在XML与JSON中。然后解析刚刚导出XML或JSON通过脚本把导出游戏场景还原。在Unity官网上下载随便下载一种demo Project,如下图所示这是我刚刚在官网上下载一种范例程序。 接着将层次视图中所有游戏对象都封装成Prefab保存在资源途径中,这里注意一下如果你Prefab绑定脚本中有public Object 话 ,需要在代码中改一下。用 Find() FindTag()此类办法在脚本中Awake()办法中来拿,否则Prefab动态加载时候无法

2、赋值,如下图所示,我把封装Prefab对象都放在了Resources/Prefab文献夹下。 OK,当前咱们就需要编写咱们导出工具、在Project视图中创立Editor文献夹,接着创立脚本MyEditor 。如下图所示。 由于编辑游戏场景数量比较多,导出时候咱们需要遍历所有游戏场景,一种一种读取场景信息。然后获得游戏场景中所有游戏对象Prefab 名称 旋转 缩放 平移。关于XML使用请人们看我上一篇文章:Unity3D研究院之使用 C#合成解析XML与JSON(四十一)代码中我只注释重点某些,嘿嘿。MyEditor.csC#123456789101112131415161718192021

3、222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147

4、148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190using UnityEngine;using System.Collections;using UnityEditor;using System.Collections.Generic;using System.Xml;using System.IO;using System.Text;using LitJson;public class

5、 MyEditor :Editor/将所有游戏场景导出为XML格式MenuItem (GameObject/ExportXML)static void ExportXML ()string filepath = Application.dataPath + /StreamingAssets/my.xml;if(!File.Exists (filepath)File.Delete(filepath);XmlDocument xmlDoc = new XmlDocument();XmlElement root = xmlDoc.CreateElement(gameObjects);/遍历所有游戏场

6、景foreach (UnityEditor.EditorBuildSettingsScene S in UnityEditor.EditorBuildSettings.scenes) /当关卡启用if (S.enabled) /得到关卡名称string name = S.path;/打开这个关卡EditorApplication.OpenScene(name);XmlElement scenes = xmlDoc.CreateElement(scenes);scenes.SetAttribute(name,name);foreach (GameObject obj in Object.Find

7、ObjectsOfType(typeof(GameObject) if (obj.transform.parent = null) XmlElement gameObject = xmlDoc.CreateElement(gameObjects);gameObject.SetAttribute(name,obj.name);gameObject.SetAttribute(asset,obj.name + .prefab);XmlElement transform = xmlDoc.CreateElement(transform);XmlElement position = xmlDoc.Cre

8、ateElement(position);XmlElement position_x = xmlDoc.CreateElement(x);position_x.InnerText = obj.transform.position.x+; XmlElement position_y = xmlDoc.CreateElement(y);position_y.InnerText = obj.transform.position.y+;XmlElement position_z = xmlDoc.CreateElement(z);position_z.InnerText = obj.transform

9、.position.z+;position.AppendChild(position_x);position.AppendChild(position_y);position.AppendChild(position_z);XmlElement rotation = xmlDoc.CreateElement(rotation);XmlElement rotation_x = xmlDoc.CreateElement(x);rotation_x.InnerText = obj.transform.rotation.eulerAngles.x+; XmlElement rotation_y = x

10、mlDoc.CreateElement(y);rotation_y.InnerText = obj.transform.rotation.eulerAngles.y+;XmlElement rotation_z = xmlDoc.CreateElement(z);rotation_z.InnerText = obj.transform.rotation.eulerAngles.z+;rotation.AppendChild(rotation_x);rotation.AppendChild(rotation_y);rotation.AppendChild(rotation_z);XmlEleme

11、nt scale = xmlDoc.CreateElement(scale);XmlElement scale_x = xmlDoc.CreateElement(x);scale_x.InnerText = obj.transform.localScale.x+; XmlElement scale_y = xmlDoc.CreateElement(y);scale_y.InnerText = obj.transform.localScale.y+;XmlElement scale_z = xmlDoc.CreateElement(z);scale_z.InnerText = obj.trans

12、form.localScale.z+;scale.AppendChild(scale_x);scale.AppendChild(scale_y);scale.AppendChild(scale_z);transform.AppendChild(position);transform.AppendChild(rotation);transform.AppendChild(scale);gameObject.AppendChild(transform); scenes.AppendChild(gameObject);root.AppendChild(scenes); xmlDoc.AppendCh

13、ild(root); xmlDoc.Save(filepath); /刷新Project视图, 否则需要手动刷新哦AssetDatabase.Refresh();/将所有游戏场景导出为JSON格式MenuItem (GameObject/ExportJSON)static void ExportJSON ()string filepath = Application.dataPath + /StreamingAssets/json.txt; FileInfo t = new FileInfo(filepath);if(!File.Exists (filepath)File.Delete(fil

14、epath);StreamWriter sw = t.CreateText();StringBuilder sb = new StringBuilder ();JsonWriter writer = new JsonWriter (sb);writer.WriteObjectStart ();writer.WritePropertyName (GameObjects);writer.WriteArrayStart ();foreach (UnityEditor.EditorBuildSettingsScene S in UnityEditor.EditorBuildSettings.scene

15、s)if (S.enabled)string name = S.path;EditorApplication.OpenScene(name);writer.WriteObjectStart();writer.WritePropertyName(scenes);writer.WriteArrayStart ();writer.WriteObjectStart();writer.WritePropertyName(name);writer.Write(name);writer.WritePropertyName(gameObject);writer.WriteArrayStart ();forea

16、ch (GameObject obj in Object.FindObjectsOfType(typeof(GameObject) if (obj.transform.parent = null) writer.WriteObjectStart();writer.WritePropertyName(name);writer.Write(obj.name);writer.WritePropertyName(position);writer.WriteArrayStart ();writer.WriteObjectStart();writer.WritePropertyName(x);writer

17、.Write(obj.transform.position.x.ToString(F5);writer.WritePropertyName(y);writer.Write(obj.transform.position.y.ToString(F5);writer.WritePropertyName(z);writer.Write(obj.transform.position.z.ToString(F5);writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WritePropertyName(rotation);writer.WriteArr

18、ayStart ();writer.WriteObjectStart();writer.WritePropertyName(x);writer.Write(obj.transform.rotation.eulerAngles.x.ToString(F5);writer.WritePropertyName(y);writer.Write(obj.transform.rotation.eulerAngles.y.ToString(F5);writer.WritePropertyName(z);writer.Write(obj.transform.rotation.eulerAngles.z.ToS

19、tring(F5);writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WritePropertyName(scale);writer.WriteArrayStart ();writer.WriteObjectStart();writer.WritePropertyName(x);writer.Write(obj.transform.localScale.x.ToString(F5);writer.WritePropertyName(y);writer.Write(obj.transform.localScale.y.ToString(F

20、5);writer.WritePropertyName(z);writer.Write(obj.transform.localScale.z.ToString(F5);writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WriteObjectEnd();writer.WriteArrayEnd();writer.WriteObjectEnd ();sw.

21、WriteLine(sb.ToString();sw.Close();sw.Dispose();AssetDatabase.Refresh(); 此时咱们就可以导出游戏场景信息拉,注意游戏场景需要当前Project Setting 中注册。点击 GameObject Export XML 和 GameObject ExportJson 菜单项即可开始生成。 如下图所示,场景导出完毕后,会将xml 与Json 文献保存在StreamingAssets途径下,放在这里因素是以便移动平台移植,由于它们属于二进制文献,移动平台在读取二进制文献途径是不同样。一定要放在这里喔。接着,我继续创立两个游戏场景

22、,一种用来解析XML场景,一种用来解析JSON场景。XML场景中,创立一种空游戏对象,把XML.cs挂上去。C#1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171

23、18119120121122using UnityEngine;using System.Collections;using System.Xml;using System.IO;public class XML :MonoBehaviour / Use this for initializationvoid Start ()/电脑和iphong上途径是不同样,这里用标签判断一下。#if UNITY_EDITORstring filepath = Application.dataPath +/StreamingAssets+/my.xml;#elif UNITY_IPHONEstring fi

24、lepath = Application.dataPath +/Raw+/my.xml;#endif/如果文献存在话开始解析。if(File.Exists (filepath)XmlDocument xmlDoc = new XmlDocument();xmlDoc.Load(filepath);XmlNodeList nodeList=xmlDoc.SelectSingleNode(gameObjects).ChildNodes;foreach(XmlElement scenein nodeList)/由于我XML是把所有游戏对象所有导出, 因此这里判断一下只解析需要场景中游戏对象/JSON

25、和它原理类似if(!scene.GetAttribute(name).Equals(Assets/StarTrooper.unity)continue;foreach(XmlElement gameObjects in scene.ChildNodes)string asset = Prefab/ + gameObjects.GetAttribute(name);Vector3 pos = Vector3.zero;Vector3 rot = Vector3.zero;Vector3 sca = Vector3.zero;foreach(XmlElement transform in game

26、Objects.ChildNodes)foreach(XmlElement prs in transform.ChildNodes)if(prs.Name = position)foreach(XmlElement position in prs.ChildNodes)switch(position.Name)case x:pos.x = float.Parse(position.InnerText);break;case y:pos.y = float.Parse(position.InnerText);break;case z:pos.z = float.Parse(position.In

27、nerText);break;else if(prs.Name = rotation)foreach(XmlElement rotation in prs.ChildNodes)switch(rotation.Name)case x:rot.x = float.Parse(rotation.InnerText);break;case y:rot.y = float.Parse(rotation.InnerText);break;case z:rot.z = float.Parse(rotation.InnerText);break;else if(prs.Name = scale)foreac

28、h(XmlElement scale in prs.ChildNodes)switch(scale.Name)case x:sca.x = float.Parse(scale.InnerText);break;case y:sca.y = float.Parse(scale.InnerText);break;case z:sca.z = float.Parse(scale.InnerText);break;/拿到 旋转 缩放 平移 后来克隆新游戏对象GameObject ob = (GameObject)Instantiate(Resources.Load(asset),pos,Quatern

29、ion.Euler(rot);ob.transform.localScale = sca;/ Update is called once per framevoid Update ()void OnGUI()if(GUI.Button(new Rect(0,0,200,200),XML WORLD)Application.LoadLevel(JSONScene);接着JSON场景中,创立一种空游戏对象,把JSON.cs挂上去。C#12345678910111213141516171819202122232425262728293031323334353637383940414243444546

30、474849505152535455565758596061626364656667686970717273747576777879808182using UnityEngine;using System.Collections;using System.IO;using LitJson;public class JSON :MonoBehaviour / Use this for initializationvoid Start ()#if UNITY_EDITORstring filepath = Application.dataPath +/StreamingAssets+/json.t

31、xt;#elif UNITY_IPHONEstring filepath = Application.dataPath +/Raw+/json.txt;#endif StreamReader sr= File.OpenText(filepath);stringstrLine = sr.ReadToEnd(); JsonData jd = JsonMapper.ToObject(strLine); JsonData gameObjectArray = jdGameObjects;int i,j,k;for (i = 0;i gameObjectArray.Count;i+) JsonData s

32、enseArray = gameObjectArrayiscenes; for (j = 0;j senseArray.Count;j+) string sceneName = (string)senseArrayjname;if(!sceneName.Equals(Assets/StarTrooper.unity)continue;JsonData gameObjects = senseArrayjgameObject;for (k = 0;k gameObjects.Count;k+)string objectName = (string)gameObjectskname;string a

33、sset = Prefab/ + objectName;Vector3 pos = Vector3.zero;Vector3 rot = Vector3.zero;Vector3 sca = Vector3.zero;JsonData position = gameObjectskposition;JsonData rotation = gameObjectskrotation;JsonData scale = gameObjectskscale;pos.x = float.Parse(string)position0x);pos.y = float.Parse(string)position

34、0y);pos.z = float.Parse(string)position0z);rot.x = float.Parse(string)rotation0x);rot.y = float.Parse(string)rotation0y);rot.z = float.Parse(string)rotation0z);sca.x = float.Parse(string)scale0x);sca.y = float.Parse(string)scale0y);sca.z = float.Parse(string)scale0z);GameObject ob = (GameObject)Instantiate(Resources.Load(asset),pos,Quaternion.Euler(rot);ob.transform.localScale = sca; / Update is called once per framevoid Update () void OnGUI()if(GUI.Button(new Rect(0,0,200,200),JSON WORLD)Application.LoadLevel(XMLScene);

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服