using Invector.vCharacterController; using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; public class GameManager : MonoBehaviour { public static GameManager Instance; #region Components private GameObject PlayerPrefab; //player预制体 public Transform PlayerPool; //player父物体 //public Transform InitPosition; //初始位置 public Transform MySelf; //自己 public Camera MainCamera; //主相机 public Camera EnvirCamera; //环境相机 public Joystick Joystick; //虚拟轴 //public FakeMountain FakeMountain; //环境山 public CameraController CamController; //相机控制脚本 //public JiugongGridSegmentation JiugongGridSegmentation; //地形格子 public GridMange JiugongGridSegmentation; //地形格子 public vThirdPersonInput PlayerInput; //角色控制输入 public Tips Tip; //提示面板 public Font _font; //系统字体 #endregion public List playerPool = new List(); #region Variables public static bool GodMode = false; //上帝模式 public static bool AutoWalk = false; //自动行走 public int TagetFrameRate = 60; //设置锁帧 [Header("Target Platform Quality Settings")] public int PcQuality = 4; public int MobileQuality = 2; #endregion void Awake() { Instance = this; //AutoWalk = true; //MainCamera.enabled = false; Screen.sleepTimeout = SleepTimeout.NeverSleep; Debug.unityLogger.logEnabled = Application.isEditor; QualitySettings.SetQualityLevel(Application.isMobilePlatform ? MobileQuality : PcQuality); } // Use this for initialization void Start() { Application.ExternalCall("OnSceneLoaded"); new FrameRate().UpdateFrame(); _font = Resources.Load("Fonts/fzzyjw"); PlayerPrefab = Resources.Load("Prefabs/Role/Human"); if (WebSocketDemo.instance) WebSocketDemo.instance.ConnectMain(); //连接 else MySelf = this.transform; Application.targetFrameRate = TagetFrameRate; } // Update is called once per frame void Update() { //#if UNITY_EDITOR //Application.targetFrameRate = TagetFrameRate; //#endif } /// /// 更新分辨率 /// public void UpdateResolution(string msssage) { if (string.IsNullOrEmpty(msssage)) { Debug.Log("请输入参数,格式:#width#height#"); return; } string[] msgs = msssage.Split(msssage[0]); if (msgs.Length < 4) { Debug.Log(string.Format("格式不正确,请按照该格式:#width#height#")); return; } int width = Screen.width; int.TryParse(msgs[1], out width); int height = Screen.height; int.TryParse(msgs[2], out height); bool fullScreen = false; if (msgs.Length >= 5) bool.TryParse(msgs[3], out fullScreen); int freshRate = 60; if (msgs.Length >= 6) int.TryParse(msgs[4], out freshRate); Screen.SetResolution(width, height, fullScreen, freshRate); Debug.Log(string.Format("w:{0} h:{1} f:{2} r:{3}", width, height, fullScreen, freshRate)); } /// /// 生成Player /// /// /// public GameObject GeneratePlayers(bool isme = false, byte[] coordinate = null) { GameObject go = null; if (playerPool.Count > 0) { go = playerPool[0]; playerPool.RemoveAt(0); go.gameObject.SetActive(true); InitPlayer(go, isme, coordinate); } else { if (PlayerPrefab != null) { go = Instantiate(PlayerPrefab); InitPlayer(go, isme, coordinate); } } return go; } /// /// 回收 /// /// public void RecoveryPlayers(MyPlayer player) { GameObject go = player.gameObject; go.SetActive(false); if (go.transform.Find("MyPos") != null) go.transform.Find("MyPos").gameObject.SetActive(false); Destroy(go.GetComponent()); playerPool.Add(go); } /// /// 角色初始化 /// /// /// private void InitPlayer(GameObject go, bool isme, byte[] coordinate) { if (isme) { go.name = "AJ_Me"; MySelf = go.transform; go.GetComponent().Joystick = Joystick; go.GetComponent().Init(); go.AddComponent(); InitSelf(); } else { go.GetComponent().applyRootMotion = false; Destroy(go.GetComponent()); Destroy(go.GetComponent()); Destroy(go.GetComponent()); Destroy(go.GetComponent()); } if (go.transform.Find("MyPos") != null) go.transform.Find("MyPos").gameObject.SetActive(isme); //Vector3 temp = new Vector3(coordinate[0] * 10 + 5, 0, coordinate[1] * 10 + 5); //temp.y = JiugongGridSegmentation.GetTerrainHeight(temp) + 0.05f; Vector3 temp = JiugongGridSegmentation.GetGridInitPos(coordinate); go.transform.position = temp; go.transform.SetParent(PlayerPool); } /// /// 自身初始化 /// private void InitSelf() { //if(FakeMountain)FakeMountain.Target = MySelf; JiugongGridSegmentation.PlayerTrans = MySelf; CamController.Target = MySelf.Find("CameraTarget"); PlayerInput = MySelf.GetComponent(); } /// /// 切换上帝模式 /// public void God() { if (MySelf == null) return; GodMode = !GodMode; if (GodMode) { AutoWalk = false; //禁用 GUIManager.Instance.B_自动行走.m_Text.text = "手动行走"; } CamController.God = PlayerInput.God = GodMode; if (GodMode) { var tmps = MyPlayer.players.Keys.ToList(); tmps.ForEach(a => { if (MyPlayer.players.ContainsKey(a)) { MyPlayer.players[a].gameObject.SetActive(true); } }); } //HidePlayers.ForEach(player => player.gameObject.SetActive(GodMode)); //if(FakeMountain)FakeMountain.God(GodMode); //关掉假山 MainCamera.farClipPlane = GodMode ? 800 : 150; } /// /// 显示隐藏其他角色 /// /// /// public void DisplayPlayer(MyPlayer player, bool isnear) { if (player.gameObject.activeInHierarchy != isnear) { if (isnear) { player.SyncImmediately(); } player.gameObject.SetActive(isnear); } } }