unity3D克隆50个游戏对象并输出Json格式的文本
http://wenku.baidu.com/link?url=tl8q_aj1n-U267XkKtSZISaw6jKJ1woh4CJkDUr1AwEzllSAv7P0r7cawXXSyDVXNf6mjKZaXr15XiX3tKL8xCrMcxtGKpE2P3fSDnvFEdG
using UnityEngine;
using System.Collections;
using LitJson;
using System.Text;
using System.IO; public class Prefabs : MonoBehaviour
{
public GameObject cube;
public GameObject[] CubePrefabs;
public int i;
public int j = ;
// Use this for initialization
void Start()
{
//CubePrefabs = new GameObject[50];
GameCopy();
} // Update is called once per frame void Update()
{ }
void GameCopy()
{
CubePrefabs = new GameObject[];
string filepath = Application.dataPath + @"/StreamingAssets/json.txt";
FileInfo t = new FileInfo(filepath);
if (!File.Exists(filepath))
{
File.Delete(filepath);
}
StreamWriter sw = t.CreateText();
for (i = ; i < ; i++)
{ CubePrefabs[j] = Instantiate(cube, new Vector3(i * 1.5f, , ), Quaternion.identity) as GameObject;
//Debug.Log("Position" + CubePrefabs[j].transform.position);
//Debug.Log("Rotation" +CubePrefabs[j].transform.rotation);
//Debug.Log("Scale" + CubePrefabs[j].transform.localScale);
j++;
} foreach (GameObject obj in CubePrefabs)
{
StringBuilder sb = new StringBuilder();
JsonWriter writer = new JsonWriter(sb);
writer.WriteObjectStart(); writer.WritePropertyName("name");
writer.Write(obj.name); writer.WritePropertyName("Position");
writer.WriteArrayStart();
writer.WriteObjectStart();
writer.WritePropertyName("X");
writer.Write(obj.transform.position.x);
writer.WritePropertyName("Y");
writer.Write(obj.transform.position.y);
writer.WritePropertyName("Z");
writer.Write(obj.transform.position.z);
writer.WriteObjectEnd();
writer.WriteArrayEnd(); writer.WritePropertyName("Rotation");
writer.WriteArrayStart();
writer.WriteObjectStart();
writer.WritePropertyName("X");
writer.Write(obj.transform.rotation.x);
writer.WritePropertyName("Y");
writer.Write(obj.transform.rotation.y);
writer.WritePropertyName("Z");
writer.Write(obj.transform.rotation.z);
writer.WriteObjectEnd();
writer.WriteArrayEnd(); writer.WritePropertyName("Scale");
writer.WriteArrayStart();
writer.WriteObjectStart();
writer.WritePropertyName("X");
writer.Write(obj.transform.localScale.x);
writer.WritePropertyName("Y");
writer.Write(obj.transform.localScale.y);
writer.WritePropertyName("Z");
writer.Write(obj.transform.localScale.z);
writer.WriteObjectEnd();
writer.WriteArrayEnd(); writer.WriteObjectEnd();
Debug.Log(sb);
sw.WriteLine(sb.ToString()); } sw.Close();
sw.Dispose();
}
unity3D克隆50个游戏对象并输出Json格式的文本的更多相关文章
- 在JSP页面中输出JSON格式数据
JSON-taglib是一套使在JSP页面中输出JSON格式数据的标签库. JSON-taglib主页: http://json-taglib.sourceforge.net/index.html J ...
- php直接输出json格式
php直接输出json格式,很多新手有一个误区,以为用echo json_encode($data);这样就是输出json数据了,没错这样输出文本是json格式文本而不是json数据,正确的写法是应该 ...
- PHP、Java输出json格式数据
PHP 输出json. $result = mysql_query($sql); //查询结果 $users=array(); $i=0; while($row=mysql_fetch_array ...
- python json.dumps()函数输出json格式,使用indent参数对json数据格式化输出
在python中,要输出json格式,需要对json数据进行编码,要用到函数:json.dumps json.dumps() :是对数据进行编码 #coding=gbkimport json dict ...
- WCF兼容WebAPI输出Json格式数据,从此WCF一举两得
问题起源: 很多时候为了业务层调用(后台代码),一些公共服务就独立成了WCF,使用起来非常方便,添加服务引用,然后简单配置就可以调用了. 如果这个时候Web站点页面需要调用怎么办呢? 复杂的XML , ...
- $.each遍历json对象(java将对象转化为json格式以及将json解析为普通对象)
查看一个简单的jQuery的例子来遍历一个JavaScript数组对象. var json = [ {"id":"1","tagName": ...
- shell 输出json格式的内容
对于shell脚本的输出,如果要输出json格式的内容,我们可以借助python -m json.tool命令 比如 echo '{"name":"zhangsan&qu ...
- Unity3D入门基础之游戏对象 (GameObject) 和组件 (Component) 的关系
原文出处:http://edu.china.unity3d.com/learning_document/getData?file=/Manual/TheGameObject-ComponentRela ...
- 把普通对象转换成json格式的对象
1.什么叫做JSON?JSON只是一种数据格式(它不是一种新的数据类型) var obj = {name: "中国", age: 5000};//->普通格式的对象 var ...
随机推荐
- js一段小代码(浏览器用alert,否则用console)
(function(){ var root=this, isBrowserSide=false; if(typeof window !=="undefined" && ...
- 使用 gulp 压缩 CSS
请务必理解如下章节后阅读此章节: 安装 Node 和 gulp 使用 gulp 压缩 JS 压缩 css 代码可降低 css 文件大小,提高页面打开速度. 我们接着将规律转换为 gulp 代码 规律 ...
- [libGDX游戏开发教程]使用libGDX进行游戏开发(12)-Action动画
前文章节列表: 使用libGDX进行游戏开发(11)-高级编程技巧 使用libGDX进行游戏开发(10)-音乐音效不求人,程序员也可以DIY 使用libGDX进行游戏开发(9)-场景过渡 ...
- Macaca 自动化录制工具uirecorder使用入门
Q&A PC端执行用例前,一定要运行selenium-standalone start,否则会出现这个问题:https://github.com/alibaba/uirecorder/issu ...
- onethink 插件模板定位
<?php // +---------------------------------------------------------------------- // | OneThink [ ...
- MongoError: topology was destroyed解决方法
MongoError: topology was destroyed 分析得出,出现这个问题是因为,当mongodb尝试写入某个数据的时候,连接被中断了! 解决方法:检查代码中是否存在操作数据的过程中 ...
- centos7下自定义服务启动和自动执行脚本
systemctl list-units --type=service #查看所有已启动的服务 systemctl enable httpd.service #加入开机自启动服务 systemctl ...
- JVM加载Class文件的机制
1.Java中的所有类,必须被装载到jvm中才能运行,这个装载工作是由jvm中的类装载器完成的, 类装载器所做的工作实质是把类文件从硬盘读取到内存中 2.java中的类大致分为三种: 1.系统 ...
- Largest Divisible Subset -- LeetCode
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...
- UOJ Rounds
UOJ Test Round #1 T1:数字比大小的本质是按(长度,字典序)比大小. T2:首先发现单调性,二分答案,用堆模拟,$O(n\log^2 n)$. 第二个log已经没有什么可优化的了,但 ...