comparison Assets/Application/Scripts/Test/SaveDataTest.cs @ 6:9be20fcffaac

SaveDataTest Fix
author Kazuma Takeda <kazuma-arashi@hotmail.co.jp>
date Mon, 05 Dec 2016 05:24:05 +0900
parents 12f4f937da7f
children ad4729c5eec4
comparison
equal deleted inserted replaced
5:12f4f937da7f 6:9be20fcffaac
2 using UnityEditor; 2 using UnityEditor;
3 using System.Collections; 3 using System.Collections;
4 using UnityEngine.SceneManagement; 4 using UnityEngine.SceneManagement;
5 5
6 public class SaveDataTest : MonoBehaviour { 6 public class SaveDataTest : MonoBehaviour {
7 7
8 DefaultNodePath root = new DefaultNodePath(); 8 private SceneNode root;
9 NodePath path;
10 System.Collections.Generic.List<ParentObject> ParentList = new System.Collections.Generic.List<ParentObject>();
11 public ConvertObject co;
12 9
13 private void Start () { 10 private void Start () {
14 path = root.add(0); 11 root = new SceneNode(this.gameObject, null);
15 Check ();
16 }
17
18 private void Update () {
19 if (Input.GetKeyDown (KeyCode.A)) {
20 SaveData.Instance.CreateTree (SceneManager.GetActiveScene().name);
21 }
22
23 if (Input.GetKeyDown (KeyCode.S)) {
24 int i = 0;
25 foreach (var parent in ParentList) {
26 foreach (var comp in parent.dic) {
27 Mapping (i, root, comp.Key, comp.Value);
28 }
29 i++;
30 }
31 }
32
33 if (Input.GetKeyDown (KeyCode.D)) {
34 SaveData.Instance.Push ();
35 }
36 }
37
38 private void Mapping(int pos, NodePath path, string key, Component value) {
39 byte[] array = ConvertObject.Convert (value.ToString());
40 SaveData.Instance.createTree (pos, path, key , array);
41 } 12 }
42 13
43 private void Check () { 14 private void Check () {
44 // やりたいこと
45 // まず親のみ取得
46 // その後親から辿っていってComponentをすべてとる
47 // http://answers.unity3d.com/questions/275714/how-to-find-all-components-of-a-game-object.html
48 // こことかいいかも
49
50 // TreeMap<Gameobject, ChildObject> Left : Parent, Right : ChildTreeMap
51 // 一番浅い親のTreeMapをListに入れる
52 int i = 0; 15 int i = 0;
53 foreach (GameObject obj in UnityEngine.Resources.FindObjectsOfTypeAll(typeof(GameObject))) { 16 foreach (GameObject obj in UnityEngine.Resources.FindObjectsOfTypeAll(typeof(GameObject))) {
54 string path = AssetDatabase.GetAssetOrScenePath (obj); 17 string path = AssetDatabase.GetAssetOrScenePath (obj);
55 bool isScene = path.Contains (".unity"); 18 bool isScene = path.Contains (".unity");
56 if (isScene) { // このシーンの中のオブジェクトかどうか。 19 if (isScene) { // このシーンの中のオブジェクトかどうか。
57 if (obj.transform.childCount == 0 && obj.transform.parent == null || obj.transform.childCount > 0 && obj.transform.parent == null) { // 親を取得 20 if (obj.transform.childCount == 0 && obj.transform.parent == null || obj.transform.childCount > 0 && obj.transform.parent == null) { // 親を取得
58 ParentObject parent = new ParentObject (obj, root.add (i)); 21
59 ParentList.Add (parent);
60 i++; 22 i++;
61 } 23 }
62 } 24 }
63 } 25 }
64 } 26 }