123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- using System.Text;
- using System;
- public class OutPointManager : MonoBehaviour
- {
- private static OutPointManager instance;
- void Awake()
- {
- if (instance == null)
- {
- instance = this;
- }
- }
- public static OutPointManager GetInstance()
- {
- return instance;
- }
- [Tooltip("导出文件名字")]
- public string jsonName;
-
-
- public StringBuilder SB = new StringBuilder();
- public void StartWriteFile()
- {
- this.WriteSceneCom();
- //ADD Here
- SB.Append("}");
- var name = "E:/Work/ShootOut3D/Shootout/ShootLaya/bin/res/LevelCfg" + "/" + jsonName + ".json";
- WriterFile(name, SB.ToString());
- }
- //写入场景组件
- private void WriteSceneCom()
- {
- SB.Append("{\"sceneCom\":[");
- var goArr = GameController.GetInstance().sceneEnity;
- for (int i = 0; i < goArr.Length; i++)
- {
- var go = goArr[i];
- SB.Append("{\"name\":\"" + go.name+"\",");
- SB.Append("\"pos\":");
- outVector3(SB, go.transform.position);
- SB.Append(",");
- SB.Append("\"scale\":");
- outVector3ForScale(SB, go.transform.localScale);
- SB.Append(",");
- SB.Append("\"rotation\":");
- outQuaterion(SB, go.transform.rotation);
-
- if (i + 1 == goArr.Length)
- {
- SB.Append("}");
- }
- else
- {
- SB.Append("},");
- }
- }
- SB.Append("]");
- }
- public static void WriterFile(string path, string info)
- {
- if (File.Exists(path))
- {
- File.Delete(path);
- }
- FileStream fs = File.Create(path);
- if (fs != null)
- {
- StreamWriter sw = new StreamWriter(fs);
- if (sw != null)
- {
- sw.Write(info);
- sw.Flush();
- }
- fs.Flush();
- sw.Close();
- fs.Close();
- }
- }
- static void outVector3(StringBuilder SB, Vector3 p)
- {
- SB.Append("[");
- SB.Append(-p.x);
- SB.Append(",");
- SB.Append(p.y);
- SB.Append(",");
- SB.Append(p.z);
- SB.Append("]");
- }
- static void outVector3ForScale(StringBuilder SB, Vector3 p)
- {
- SB.Append("[");
- SB.Append(p.x);
- SB.Append(",");
- SB.Append(p.y);
- SB.Append(",");
- SB.Append(p.z);
- SB.Append("]");
- }
- static void outQuaterion(StringBuilder SB,Quaternion q)
- {
- SB.Append("[");
- SB.Append(-q.x);
- SB.Append(",");
- SB.Append(q.y);
- SB.Append(",");
- SB.Append(q.z);
- SB.Append(",");
- SB.Append(-q.w);
- SB.Append("]");
- }
- }
|