4
|
1 using UnityEngine;
|
|
2 using System.Collections;
|
8
|
3 using JungleDB;
|
|
4 using System.Text;
|
|
5 using System;
|
4
|
6 public class Item : MonoBehaviour {
|
|
7
|
8
|
8 public string Type;
|
|
9 public GameObject ItemImage;
|
|
10 public int Broken = 2;
|
|
11 private int nowBroken = 2;
|
|
12 public int indexID = 0;
|
|
13 public int itemID = 1;
|
10
|
14 public string ColorCode = "";
|
8
|
15
|
|
16 private Jungle jungle;
|
|
17
|
10
|
18 public void SetItem (ItemInfo item, int index) {
|
|
19 this.Broken = item.Broken;
|
|
20 nowBroken = Broken;
|
|
21 Type = item.Type;
|
|
22 itemID = item.itemID;
|
|
23 indexID = index;
|
|
24 ColorCode = item.ColorCode;
|
|
25 SetColor (this.ColorCode);
|
|
26 }
|
8
|
27
|
10
|
28 public void SetItem (int broken, string type, string item_id, int index, string code) {
|
8
|
29 this.Broken = broken;
|
|
30 nowBroken = Broken;
|
|
31 Type = type;
|
10
|
32 itemID = Convert.ToInt32(item_id);
|
|
33 indexID = index;
|
|
34 SetColor (code);
|
8
|
35 }
|
4
|
36
|
8
|
37 public void SetPosition (Vector3 pos) {
|
|
38 this.transform.position = pos;
|
|
39 // print ("Set (" + pos.x + ", " + pos.y + ", " + pos.z + ")");
|
|
40 }
|
|
41
|
10
|
42 public void SetColor (string code) {
|
|
43 Color color;
|
|
44 ColorUtility.TryParseHtmlString(code, out color);
|
|
45 this.GetComponent<MeshRenderer> ().material.color = color;
|
|
46 }
|
|
47
|
8
|
48 public void Delete() {
|
|
49 if (nowBroken == 0) {
|
11
|
50 DeleteTreeNode ();
|
8
|
51 Destroy (this.gameObject);
|
|
52 return;
|
|
53 }
|
|
54
|
|
55 nowBroken -= 1;
|
|
56 }
|
|
57
|
11
|
58 public void DeleteTreeNode () {
|
|
59 jungle = SaveDataTest.jungle;
|
|
60 JungleTree tree = jungle.getTreeByName ("SceneTree");
|
|
61 JungleTreeEditor edt = tree.getTreeEditor ();
|
|
62
|
|
63 NodePath root = new DefaultNodePath ();
|
|
64 NodePath stagePath = root.add (1);
|
|
65
|
|
66 Either<Error, JungleTreeEditor> e = edt.deleteChildAt (stagePath, indexID);
|
|
67 if (e.isA ()) {
|
|
68 print ("[Error] Try again!");
|
|
69 SetCreateTreeNode ();
|
|
70 }
|
|
71 edt = e.b ();
|
|
72 edt.commit ();
|
|
73 }
|
|
74
|
|
75
|
8
|
76 public void SetCreateTreeNode () {
|
|
77 jungle = SaveDataTest.jungle;
|
|
78 JungleTree tree = jungle.getTreeByName ("SceneTree");
|
|
79 JungleTreeEditor edt = tree.getTreeEditor ();
|
|
80
|
|
81 NodePath root = new DefaultNodePath ();
|
|
82 NodePath stagePath = root.add (1);
|
|
83 edt = edt.addNewChildAt(stagePath, indexID).b();
|
|
84
|
|
85 Either<Error, JungleTreeEditor> e = edt.putAttribute (stagePath.add (indexID), "Item_ID", Encoding.UTF8.GetBytes(itemID.ToString()));
|
|
86 if (e.isA ()) {
|
|
87 print ("[Error] Try again!");
|
|
88 SetCreateTreeNode ();
|
|
89 }
|
|
90 edt = e.b ();
|
|
91 edt.commit ();
|
4
|
92 }
|
|
93 }
|