0
|
1 using UnityEngine;
|
|
2 using System.Collections;
|
3
|
3 using System.Collections.Generic;
|
8
|
4 using UnityEngine.UI;
|
|
5 using JungleDB;
|
|
6 using System.Text;
|
0
|
7
|
|
8 public class Player : MonoBehaviour { // Singleton
|
|
9 // --------------------------------------
|
8
|
10
|
|
11 private readonly int BASEHP = 10;
|
|
12
|
0
|
13 public static Player Instance;
|
|
14 private GameObject eye;
|
|
15 private CharacterController cc;
|
|
16 private Vector3 Direction;
|
3
|
17 // 今見ているフィールドのアイテム
|
|
18 public GameObject LookedObject;
|
|
19 // セットする前のアイテム
|
8
|
20 public string haveItemType;
|
3
|
21
|
8
|
22 public DeathZone deathZone;
|
3
|
23
|
|
24 public delegate void Callback(int n0, int n1, int n2);
|
|
25 public Callback callback;
|
|
26
|
8
|
27 /* paramator */
|
|
28 public int HP = 10;
|
|
29
|
|
30 private Jungle jungle;
|
0
|
31 // -------------------------------------
|
8
|
32
|
|
33 private void Awake () {
|
0
|
34 if (Instance == null) {
|
|
35 Instance = this;
|
|
36 }
|
8
|
37 }
|
|
38
|
|
39 private void Start () {
|
|
40 eye = this.transform.FindChild ("Eye").gameObject;
|
|
41 cc = this.GetComponent<CharacterController> ();
|
|
42 deathZone.SetHitCallback (Damege);
|
0
|
43 }
|
|
44
|
|
45 private void Update () {
|
|
46 Gravity ();
|
8
|
47 if (Input.GetMouseButtonUp (1)) {
|
|
48 SetItem ();
|
|
49 }
|
|
50 ChangeGage ();
|
0
|
51 }
|
|
52
|
|
53 public void Move (bool b) {
|
|
54 if (b) {
|
4
|
55 Direction += this.transform.forward * Time.deltaTime / 10f;
|
0
|
56 } else {
|
|
57 Direction.x = 0;
|
|
58 Direction.z = 0;
|
|
59 }
|
|
60 cc.Move (Direction);
|
|
61 }
|
|
62
|
|
63 public void EyeMove (Vector3 v3) {
|
|
64 eye.transform.Rotate (-v3.x, 0, 0);
|
|
65 this.transform.Rotate (0, v3.y, 0);
|
|
66 }
|
|
67
|
|
68 public void Gravity () {
|
|
69 Direction.y = -0.1f;
|
|
70 }
|
3
|
71
|
|
72 public void SetLookedObject (GameObject obj) {
|
|
73 LookedObject = obj;
|
|
74 }
|
|
75
|
8
|
76 public void SetHaveObjectNumber (string type) {
|
|
77 haveItemType = type;
|
3
|
78 }
|
|
79
|
|
80 public void GetItem () {
|
|
81 if (LookedObject != null) {
|
8
|
82 Item stage = LookedObject.GetComponent<Item> ();
|
3
|
83 stage.Delete ();
|
|
84 }
|
|
85 }
|
|
86
|
|
87 public void SetItem () {
|
|
88 if (LookedObject != null) {
|
8
|
89 StageManager.Instance.CreateItem (LookedObject.transform.position + Vector3.up, 1);
|
3
|
90 }
|
|
91 }
|
|
92
|
|
93 public void SetCallback (Callback c) {
|
|
94 this.callback = c;
|
|
95 }
|
|
96
|
8
|
97 public void ChangeGage () {
|
|
98 // print (HP / BASEHP);
|
|
99 GameObject.Find ("MoveHP").GetComponent<Image> ().fillAmount = (float)HP / (float)BASEHP;
|
|
100 }
|
|
101
|
|
102 public void SetPlayerNode () {
|
|
103 jungle = SaveDataTest.jungle;
|
|
104 JungleTree tree = jungle.getTreeByName ("SceneTree");
|
|
105 JungleTreeEditor edt = tree.getTreeEditor ();
|
|
106
|
|
107 NodePath playerpath = new DefaultNodePath ().add (0);
|
|
108 edt = edt.putAttribute (playerpath, "HP", Encoding.UTF8.GetBytes (HP.ToString())).b();
|
|
109 edt = edt.commit ().b();
|
|
110 }
|
|
111
|
|
112 private void OnControllerColliderHit (ControllerColliderHit hit) {
|
|
113 SetPlayerNode ();
|
3
|
114 }
|
8
|
115
|
|
116 private void Damege (int d) {
|
|
117 this.HP -= d;
|
|
118 UpdatePlayerNode ();
|
|
119 }
|
|
120
|
|
121 private void UpdatePlayerNode () {
|
|
122 jungle = SaveDataTest.jungle;
|
|
123 JungleTree tree = jungle.getTreeByName ("SceneTree");
|
|
124 JungleTreeEditor edt = tree.getTreeEditor ();
|
|
125
|
|
126 NodePath playerpath = new DefaultNodePath ().add (0);
|
11
|
127 Either<Error, JungleTreeEditor> e = edt.putAttribute (playerpath, this);
|
|
128 // e.fmap (edt.commit ());
|
|
129
|
|
130
|
8
|
131 }
|
|
132
|
0
|
133 }
|