123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GameController : MonoBehaviour {
- [Tooltip("玩家预设")]
- public GameObject prefabP;
- [Tooltip("怪物预设")]
- public GameObject prefabM;
- public GameObject[] sceneEnity;
- public GameObject[] player;
- public GameObject[] moster;
- private List<Player> playerS;
- private List<Moster> mosterS;
- public Transform Bullet;
- public Transform Moster;
- public Transform Player;
-
-
- public GameObject bulletG;
- public GameObject bulletR;
- private static GameController instance;
- void Awake()
- {
- if (instance==null)
- {
- instance = this;
- }
- playerS = new List<Player>();
- mosterS = new List<Moster>();
- for (int i = 0; i < player.Length; i++)
- {
- var ps= player[i].GetComponent<Player>();
- if (ps)
- {
- playerS.Add(ps);
- }
- }
- for (int i = 0; i < moster.Length; i++)
- {
- var ms = moster[i].GetComponent<Moster>();
- if (ms)
- {
- mosterS.Add(ms);
- }
- }
- }
- public static GameController GetInstance()
- {
- return instance;
- }
- private Vector3 nowPos;
- private Vector3 oldPos;
- private bool isClick = false;
- private float length = 1;
- //private void OnMouseUp()
- //{
- // isClick = false;
- // print(2);
- //}
- //private void OnMouseDown()
- //{
- // isClick = true;
- // print(3);
- //}
- private void Update()
- {
- CloneRole();
- WriteFile();
- if (Input.GetMouseButtonDown(0))
- {
- isClick = true;
- }
- else if(Input.GetMouseButtonUp(0))
- {
- isClick = false;
- }
- nowPos = Input.mousePosition;
- if (isClick == true)
- {
- Vector3 offset = nowPos - oldPos;
- if (Mathf.Abs(offset.x) > Mathf.Abs(offset.y) && Mathf.Abs(offset.x) > length)
- {
- // transform.Rotate(Vector3.up, -offset.x);
- Rotation(-offset.x/10);
- print(111);
- }
- }
- oldPos = Input.mousePosition;
- }
- private void Rotation(float offset)
- {
- for (int i = 0; i < playerS.Count; i++)
- {
- playerS[i].RotationSelf(offset);
- }
- for (int i = 0; i < mosterS.Count; i++)
- {
- mosterS[i].RotationSelf(offset);
- }
- }
- private void CloneRole()
- {
- if (Input.GetKeyDown(KeyCode.P))
- {
- var go = GameObject.Instantiate(prefabP);
- go.transform.SetParent(Player);
- go.name = prefabP.name;
- var gs= go.AddComponent<Player>();
- playerS.Add(gs);
- }
- if (Input.GetKeyDown(KeyCode.M))
- {
- var go = GameObject.Instantiate(prefabM);
- go.transform.SetParent(Moster);
- go.name = prefabM.name;
- var gs = go.AddComponent<Moster>();
- mosterS.Add(gs);
- }
- }
- private void WriteFile()
- {
- if (Input.GetKeyDown(KeyCode.C))
- {
- OutPointManager.GetInstance().StartWriteFile();
- }
-
- }
- public float GetAng(Vector3 dir)
- {
- var xx = Mathf.Abs(dir.x);
- var zz = Mathf.Abs(dir.z);
- var obl = Mathf.Sqrt(Mathf.Pow(dir.x, 2) + Mathf.Pow(dir.z, 2));
- return 180 / Mathf.PI * Mathf.Acos(xx / obl);
- }
- }
|