Mercurial > hg > Members > kazuma > JungleforUnity
view Assets/Application/Scripts/Test/SaveDataTest.cs @ 5:12f4f937da7f
Add BenchMark
author | Kazuma |
---|---|
date | Thu, 10 Nov 2016 04:21:19 +0900 |
parents | 2878be4487ec |
children | 9be20fcffaac |
line wrap: on
line source
using UnityEngine; using UnityEditor; using System.Collections; using UnityEngine.SceneManagement; public class SaveDataTest : MonoBehaviour { DefaultNodePath root = new DefaultNodePath(); NodePath path; System.Collections.Generic.List<ParentObject> ParentList = new System.Collections.Generic.List<ParentObject>(); public ConvertObject co; private void Start () { path = root.add(0); Check (); } private void Update () { if (Input.GetKeyDown (KeyCode.A)) { SaveData.Instance.CreateTree (SceneManager.GetActiveScene().name); } if (Input.GetKeyDown (KeyCode.S)) { int i = 0; foreach (var parent in ParentList) { foreach (var comp in parent.dic) { Mapping (i, root, comp.Key, comp.Value); } i++; } } if (Input.GetKeyDown (KeyCode.D)) { SaveData.Instance.Push (); } } private void Mapping(int pos, NodePath path, string key, Component value) { byte[] array = ConvertObject.Convert (value.ToString()); SaveData.Instance.createTree (pos, path, key , array); } private void Check () { // やりたいこと // まず親のみ取得 // その後親から辿っていってComponentをすべてとる // http://answers.unity3d.com/questions/275714/how-to-find-all-components-of-a-game-object.html // こことかいいかも // TreeMap<Gameobject, ChildObject> Left : Parent, Right : ChildTreeMap // 一番浅い親のTreeMapをListに入れる int i = 0; foreach (GameObject obj in UnityEngine.Resources.FindObjectsOfTypeAll(typeof(GameObject))) { string path = AssetDatabase.GetAssetOrScenePath (obj); bool isScene = path.Contains (".unity"); if (isScene) { // このシーンの中のオブジェクトかどうか。 if (obj.transform.childCount == 0 && obj.transform.parent == null || obj.transform.childCount > 0 && obj.transform.parent == null) { // 親を取得 ParentObject parent = new ParentObject (obj, root.add (i)); ParentList.Add (parent); i++; } } } } }