0
|
1 using UnityEngine;
|
|
2 using System.Collections;
|
|
3
|
|
4 public class SaveData : MonoBehaviour {
|
|
5
|
|
6 public static SaveData Instance;
|
|
7
|
4
|
8 private Jungle mainScene ;
|
|
9 private JungleTree mainTree;
|
|
10 private JungleTreeEditor TreeEditor;
|
|
11 private TreeNode node;
|
0
|
12 // Use this for initialization
|
|
13 void Awake () {
|
|
14 if (Instance == null) {
|
|
15 Instance = this;
|
|
16 }
|
|
17 }
|
4
|
18
|
|
19 private void Start () {
|
|
20 JungleStart ();
|
|
21 }
|
|
22
|
|
23 private void JungleStart () {
|
|
24 Debug.Log ("[Jungle] Start ...");
|
|
25 mainScene = new DefaultJungle(null, "Main", new DefaultTreeEditor(new DefaultTraverser()));
|
|
26 }
|
|
27
|
|
28 public void CreateTree (string name) {
|
|
29 mainTree = mainScene.createNewTree (name);
|
|
30 Debug.Log ("[Jungle] Create " + name + " Tree");
|
|
31 EditorMode ();
|
|
32 }
|
|
33
|
|
34 public void EditorMode () {
|
|
35 TreeEditor = mainTree.getTreeEditor ();
|
|
36 Debug.Log ("[Jungle] Editor Mode" + TreeEditor.ToString());
|
|
37 }
|
|
38
|
|
39 public void PutAttribute (NodePath path, string key, byte[] value) {
|
|
40 Either<Error, JungleTreeEditor> either = TreeEditor.putAttribute (path, key, value);
|
|
41 if (either.isA ()) {
|
|
42 Debug.LogError ("[Error]" + either.a());
|
|
43 } else {
|
|
44 Debug.Log ("[Success]");
|
|
45 either.b ();
|
|
46 }
|
|
47 }
|
|
48
|
|
49 public void GetAttribute (NodePath path, string key) {
|
|
50 node = mainTree.getNodeOfPath (path).b ();
|
|
51 byte[] target = node.getAttributes ().get (key);
|
|
52 var obj = ConvertObject.UnConvert (target);
|
|
53 print (obj);
|
|
54 }
|
|
55
|
|
56 public void Push() {
|
|
57 Either<Error, JungleTreeEditor> r = TreeEditor.success();
|
|
58 if (!r.isA ()) {
|
|
59 Debug.LogError ("[Error]");
|
|
60 } else {
|
|
61 Debug.Log ("[Success]");
|
|
62 TreeEditor = r.b ();
|
|
63 }
|
|
64 }
|
0
|
65 }
|