0
|
1 using UnityEngine;
|
|
2 using System.Collections;
|
3
|
3 using System.Collections.Generic;
|
0
|
4
|
|
5 public class Player : MonoBehaviour { // Singleton
|
|
6 // --------------------------------------
|
|
7 public static Player Instance;
|
|
8 private GameObject eye;
|
|
9 private CharacterController cc;
|
|
10 private Vector3 Direction;
|
3
|
11 // 今見ているフィールドのアイテム
|
|
12 public GameObject LookedObject;
|
|
13 // セットする前のアイテム
|
|
14 public int HaveObjectNumber;
|
|
15
|
|
16 public int GlassItem = 0;
|
|
17 public int SandItem = 0;
|
|
18 public int WoodItem = 0;
|
|
19
|
|
20 public System.Collections.Generic.List<Stage> HaveItemList = new System.Collections.Generic.List<Stage>();
|
|
21
|
|
22 public delegate void Callback(int n0, int n1, int n2);
|
|
23 public Callback callback;
|
|
24
|
0
|
25 // -------------------------------------
|
|
26 private void Start () {
|
|
27 if (Instance == null) {
|
|
28 Instance = this;
|
|
29 }
|
3
|
30 eye = this.transform.FindChild ("Eye").gameObject;
|
0
|
31 cc = this.GetComponent<CharacterController> ();
|
|
32 }
|
|
33
|
|
34 private void Update () {
|
|
35 Gravity ();
|
|
36 }
|
|
37
|
|
38 public void Move (bool b) {
|
|
39 if (b) {
|
3
|
40 Direction += this.transform.forward * Time.deltaTime;
|
0
|
41 } else {
|
|
42 Direction.x = 0;
|
|
43 Direction.z = 0;
|
|
44 }
|
|
45 cc.Move (Direction);
|
|
46 }
|
|
47
|
|
48 public void EyeMove (Vector3 v3) {
|
|
49 eye.transform.Rotate (-v3.x, 0, 0);
|
|
50 this.transform.Rotate (0, v3.y, 0);
|
|
51 }
|
|
52
|
|
53 public void Gravity () {
|
|
54 Direction.y = -0.1f;
|
|
55 }
|
3
|
56
|
|
57 public void SetLookedObject (GameObject obj) {
|
|
58 LookedObject = obj;
|
|
59 }
|
|
60
|
|
61 public void SetHaveObjectNumber (int num) {
|
|
62 HaveObjectNumber = num;
|
|
63 }
|
|
64
|
|
65 public void GetItem () {
|
|
66 if (LookedObject != null) {
|
|
67 Stage stage = LookedObject.GetComponent<Stage> ();
|
|
68 HaveItemList.Add (stage);
|
|
69 CheckList ();
|
|
70 stage.Delete ();
|
|
71 }
|
|
72 }
|
|
73
|
|
74 public void SetItem () {
|
|
75 if (LookedObject != null) {
|
|
76 StageManager.Instance.CreateStage (HaveObjectNumber, new Vector3 (LookedObject.transform.position.x, LookedObject.transform.position.y + 1f, LookedObject.transform.position.z));
|
|
77 CheckList ();
|
|
78 }
|
|
79 }
|
|
80
|
|
81 public void CheckList () { // 増えたときに面倒なので動的に増えてもいいように書き直す必要あり
|
|
82 int g = 0;
|
|
83 int w = 0;
|
|
84 int s = 0;
|
|
85 foreach (var item in HaveItemList) {
|
|
86 if (Stage.Type.GRASS == item.Attribute) {
|
|
87 g++;
|
|
88 } else if (Stage.Type.SAND == item.Attribute) {
|
|
89 s++;
|
|
90 } else if (Stage.Type.WOOD == item.Attribute) {
|
|
91 w++;
|
|
92 }
|
|
93 }
|
|
94 SetItemNum (g, w, s);
|
|
95 }
|
|
96
|
|
97 public void SetCallback (Callback c) {
|
|
98 this.callback = c;
|
|
99 }
|
|
100
|
|
101 public void SetItemNum (int glass, int wood, int sand) {
|
|
102 this.GlassItem = glass;
|
|
103 this.WoodItem = wood;
|
|
104 this.SandItem = sand;
|
|
105 this.callback (sand, wood, glass);
|
|
106 print (glass + ", " + wood + ", " + sand);
|
|
107 }
|
0
|
108 }
|