4
|
1 using UnityEngine;
|
|
2 using UnityEditor;
|
|
3 using System.Collections;
|
|
4 using UnityEngine.SceneManagement;
|
|
5
|
|
6 public class SaveDataTest : MonoBehaviour {
|
|
7
|
|
8 DefaultNodePath root = new DefaultNodePath();
|
|
9 NodePath path;
|
|
10 System.Collections.Generic.List<ParentObject> ParentList = new System.Collections.Generic.List<ParentObject>();
|
|
11 public ConvertObject co;
|
|
12
|
|
13 private void Start () {
|
|
14 path = root.add(0);
|
|
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 = 1;
|
|
25 foreach (var parent in ParentList) {
|
|
26 foreach (var comp in parent.dic) {
|
|
27 Mapping (comp.Key, comp.Value);
|
|
28 }
|
|
29 // SaveData.Instance.GetAttribute (path);
|
|
30 path = path.last ().rights();
|
|
31 path = path.add (i);
|
|
32 i++;
|
|
33 SaveData.Instance.EditorMode ();
|
|
34 }
|
|
35 }
|
|
36 }
|
|
37
|
|
38 private void Mapping(string key, Component value) {
|
|
39 byte[] array = ConvertObject.Convert (value);
|
|
40 SaveData.Instance.PutAttribute (path, key , array);
|
|
41 }
|
|
42
|
|
43 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;
|
|
53 foreach (GameObject obj in UnityEngine.Resources.FindObjectsOfTypeAll(typeof(GameObject))) {
|
|
54 string path = AssetDatabase.GetAssetOrScenePath (obj);
|
|
55 bool isScene = path.Contains (".unity");
|
|
56 if (isScene) { // このシーンの中のオブジェクトかどうか。
|
|
57 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));
|
|
59 i++;
|
|
60 }
|
|
61 }
|
|
62 }
|
|
63 }
|
|
64 }
|