23
|
1 # Jungle-Sharp
|
|
2
|
|
3 using UnityEngine.
|
|
4 tree structure database.
|
|
5
|
|
6 # How to use Jungle-Sharp
|
|
7
|
|
8 namespace is JungleDB, so you write c# script.
|
|
9
|
|
10 using JungleDB;
|
|
11
|
|
12 # How to use Jungle Database.
|
|
13
|
|
14 - need interface.
|
|
15
|
|
16 Jungle
|
|
17 JungleTree
|
|
18 JungleTreeEditor
|
|
19 NodePath
|
|
20
|
|
21 1. Create Instance Jungle from DefaultJungle Class.
|
|
22 2. Create Tree in 1's Jungle Instance.
|
|
23 3. Set 2'Tree to Jungle Tree.
|
|
24 4. Change Tree Mode to Editor Tree Mode, so Set JungleTreeEditor.
|
|
25 5. Create root a Path.
|
|
26 6. Put Key(String) and Value(Byte Array) Attribute from path to TreeEditor.
|
|
27
|
|
28 private void Start () {
|
|
29 Jungle jungle = new DefaultJungle(null, "TestJungle", new DefaultTreeEditor(new DefaultTraverser()));
|
|
30 jungle.createNewTree ("TestTree");
|
|
31 JungleTree tree = jungle.getTreeByName ("TestTree");
|
|
32 JungleTreeEditor editor = tree.getTreeEditor();
|
|
33 NodePath root = new DefaultNodePath ();
|
|
34 // if put root.
|
|
35 Either<Error, JungleTreeEditor> putAttr = editor.putAttribute(root, "Key", "Value"); // <-1>
|
|
36 if(putAttr.isA()) { // put error.
|
|
37 // Expection
|
|
38 }
|
|
39
|
|
40 editor = putAttr.b();
|
|
41
|
|
42 // elif put root children path.
|
|
43 NodePath path = root.add(0);
|
|
44 Either<Error, JungleTreeEditor> createRootChild = editor.addNewChildAt(root, 0); // <-1, 0>
|
|
45 if(createRootChild.isA()) { // child create error.
|
|
46 // Expection
|
|
47 }
|
|
48
|
|
49 editor = createRootChild.b(); // success create root child.
|
|
50
|
|
51 putAttr = editor.putAttribute(path, "Key", "Value");
|
|
52 if(putAttr.isA()) { // put error.
|
|
53 // Expection
|
|
54 }
|
|
55
|
|
56 editor = putAttr.b();
|
|
57
|
|
58 // else put other path child.
|
|
59 path = path.add(0);
|
|
60 Either<Error, JungleTreeEditor> createPathChild = editor.addNewChildAt(path, 0); // <-1, 0, 0>
|
|
61 if(createPathChild.isA()) { // child create error.
|
|
62 // Expection
|
|
63 }
|
|
64
|
|
65 editor = createPathChild.b();
|
|
66
|
|
67 putAttr = editor.putAttribute(path, "Key", "Value");
|
|
68 if(putAttr.isA()) { // put error.
|
|
69 // Expection
|
|
70 }
|
|
71
|
|
72 editor = putAttr.b();
|
|
73
|
|
74 // end put Attribute function.
|
|
75 }
|