using System.Collections; using System.Collections.Generic; using UnityEngine; using Cinemachine; using UnityEngine.UI; using System; public class Level1Manager : MonoSingleton { RaycastHit rh; [Header("人物")] public PlayerController player; public GameObject clickPerson; public GameObject person;//施救者 [Header("需要移除的物体")] public GameObject[] needRemoveObjs; [Header("需要转移的物体")] public GameObject[] needTransferObjs; [Header("游戏状态变量")] [NonSerialized] public bool mouseMove = false; [NonSerialized] public bool remove = false; bool safe = false; [NonSerialized] public int safeOperate;//玩家选择的对应操作,0对应转移,1对应清理 [Header("UI")] public ErrorTip errorTip; public GameObject clickTip; public GameObject GameEndTip; [Header("操作历史")] public Transform operateLog; [NonSerialized] public List allOperates = new List(); protected override void Awake() { base.Awake(); DontDestroyOnLoad(gameObject); //safe = Random.Range(0,1f) > 0.5 ? true : false; } private void Start() { Init(); } private void Update() { if (remove) { Ray ray=Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out rh)) { if (rh.collider.tag == "ZAW" && Input.GetMouseButtonDown(0)) { if (rh.collider.GetComponent()) { rh.collider.GetComponent().SetTrigger("Sankai"); } else { rh.collider.gameObject.SetActive(false); clickTip.SetActive(false); } rh.collider.tag = "Untagged"; } } } } void Init() { InitScene(safe); player.WalkAndSquat(); EventManager.Instance.emit("StartTip"); } public void InitScene(bool safe) { clickPerson.GetComponent().SetPosBySafe(safe); if (!safe) { foreach (GameObject obj in needRemoveObjs) { obj.SetActive(true); } clickPerson.tag = "ZAW"; } } #region 安全判断 public void PanDuanSafe(bool safe) { mouseMove = false; EventManager.Instance.emit("PanDuanSafe", this.safe == safe,this.safe); } public void SetSafeOperate(int index) { safeOperate = index; if (index == 0) { EventManager.Instance.emit("SafeOperate", 0); Invoke("TransferObjs", 1); } else if (index == 1) { clickPerson.tag = "ZAW"; remove = true; EventManager.Instance.emit("SafeOperate", 1); } } #endregion #region 转移操作 void TransferObjs() { person.SetActive(true); clickPerson.GetComponent().SetPosBySafe(true); FindObjectOfType().LookAt = needTransferObjs[0].transform; FindObjectOfType().Follow = needTransferObjs[0].transform; FindObjectOfType().m_YAxis.Value = 0.75f; FindObjectOfType().m_XAxis.Value = 56.27f; foreach (GameObject obj in needTransferObjs) { obj.transform.position += new Vector3(2, 0, -35); } Invoke("ZhuanyiEnd",2); } void ZhuanyiEnd() { allOperates[2].Finished(); errorTip.InitThis("恭喜通关", 60); GameEndTip.SetActive(true); GameEndTip.GetComponentInChildren().text = "已成功转移到安全位置"; EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true); } #endregion public void AddOperate(string text) { Operate op = Instantiate(Resources.Load("operate"), operateLog).GetComponent(); allOperates.Add(op); op.str = text; op.color = Level2Const.operateFrontColor; } }