using UnityEngine; using System.Collections; using System.Collections.Generic; public class Player : MonoBehaviour { // Singleton // -------------------------------------- public static Player Instance; private GameObject eye; private CharacterController cc; private Vector3 Direction; // 今見ているフィールドのアイテム public GameObject LookedObject; // セットする前のアイテム public int HaveObjectNumber; public int GlassItem = 0; public int SandItem = 0; public int WoodItem = 0; public System.Collections.Generic.List HaveItemList = new System.Collections.Generic.List(); public delegate void Callback(int n0, int n1, int n2); public Callback callback; // ------------------------------------- private void Start () { if (Instance == null) { Instance = this; } eye = this.transform.FindChild ("Eye").gameObject; cc = this.GetComponent (); } private void Update () { Gravity (); } public void Move (bool b) { if (b) { Direction += this.transform.forward * Time.deltaTime; } else { Direction.x = 0; Direction.z = 0; } cc.Move (Direction); } public void EyeMove (Vector3 v3) { eye.transform.Rotate (-v3.x, 0, 0); this.transform.Rotate (0, v3.y, 0); } public void Gravity () { Direction.y = -0.1f; } public void SetLookedObject (GameObject obj) { LookedObject = obj; } public void SetHaveObjectNumber (int num) { HaveObjectNumber = num; } public void GetItem () { if (LookedObject != null) { Stage stage = LookedObject.GetComponent (); HaveItemList.Add (stage); CheckList (); stage.Delete (); } } public void SetItem () { if (LookedObject != null) { StageManager.Instance.CreateStage (HaveObjectNumber, new Vector3 (LookedObject.transform.position.x, LookedObject.transform.position.y + 1f, LookedObject.transform.position.z)); CheckList (); } } public void CheckList () { // 増えたときに面倒なので動的に増えてもいいように書き直す必要あり int g = 0; int w = 0; int s = 0; foreach (var item in HaveItemList) { if (Stage.Type.GRASS == item.Attribute) { g++; } else if (Stage.Type.SAND == item.Attribute) { s++; } else if (Stage.Type.WOOD == item.Attribute) { w++; } } SetItemNum (g, w, s); } public void SetCallback (Callback c) { this.callback = c; } public void SetItemNum (int glass, int wood, int sand) { this.GlassItem = glass; this.WoodItem = wood; this.SandItem = sand; this.callback (sand, wood, glass); print (glass + ", " + wood + ", " + sand); } }