using System; using System.Collections; using System.Collections.Generic; using DragonLi.Core; using UnityEngine; using Random = UnityEngine.Random; public class TaskManager : MonoBehaviour { public GameObject[] gemPres; public GameObject boxPre; public GameObject task3Tu; public GameObject bg; public GameObject taskHope; public MeshRenderer hopeBookMesh; public Material[] hopeBookMaterials; public GameObject[] hopeIcons; public List tasks = new List(); public int curTaskId; public int getGemIndex; public bool isGetGem; private void Start() { task3Tu.SetActive(false); taskHope.SetActive(false); bg.SetActive(false); } public void StartTask() { tasks[curTaskId].StartTask(); taskHope.SetActive(true); //taskHope.transform.position = new Vector3(3f, 0, 3f); hopeBookMesh.gameObject.SetActive(false); for (int i = 0; i < hopeIcons.Length; i++) { hopeIcons[i].SetActive(false); } hopeBookMesh.material = hopeBookMaterials[curTaskId]; MonoSingleton.Instance.WaitSecondTodo(() => { for (int i = 0; i < hopeIcons.Length; i++) { hopeIcons[i].SetActive(i==curTaskId); } hopeBookMesh.gameObject.SetActive(true); },2); isGetGem = false; getGemIndex = 0; } public void StartGemEndTask() { GameManager.Ins.playerRightHand.CreateGemKey(); CreateBox(GameLocal.Ins.self.transform.position+new Vector3(0,0,1),Vector3.zero,-1,TaskBoxType.TaskEndBox); } public void CompleteTask() { tasks[curTaskId].CompleteTask(); curTaskId++; taskHope.SetActive(false); } public void OverTask() { hopeBookMesh.gameObject.SetActive(false); for (int i = 0; i < hopeIcons.Length; i++) { hopeIcons[i].SetActive(false); } taskHope.SetActive(false); } public void CreateBox(Vector3 pos,Vector3 eulerAngles,int curId,TaskBoxType boxType) { GameObject box=Instantiate(boxPre,pos,Quaternion.identity); box.transform.eulerAngles = eulerAngles; box.GetComponent().Init(curId,boxType); } public GameObject CreateGem(int id,Vector3 pos,int gemId) { GameObject gem = Instantiate(gemPres[id], pos, Quaternion.identity); switch (curTaskId) { case 0: gem.GetComponent().Init(gemId); break; case 1: gem.GetComponent().Init(gemId); break; case 2: gem.GetComponent().Init(gemId); break; } tasks[curTaskId].curGems.Add(gem); getGemIndex++; return gem; } public void GetGem(GameObject gem) { switch (curTaskId) { case 0: GetSeekGem(gem); break; } } public void GetSeekGem(GameObject gem) { var seekGem = gem.transform.parent.GetComponent(); if(seekGem==null||isGetGem) return; if (tasks[curTaskId].isWin|| getGemIndex==1) { seekGem.GetGem(3); getGemIndex--; return; } int rangeIndex=Random.Range(1,11); seekGem.GetGem(rangeIndex<=7 ? 1:2); getGemIndex--; } public void GetBubblesGem(GameObject gem) { var bubblesGem = gem.transform.GetComponent(); if(bubblesGem==null||isGetGem) return; if (tasks[curTaskId].isWin|| getGemIndex==1) { bubblesGem.GetGem(3); getGemIndex--; return; } int rangeIndex=Random.Range(1,11); bubblesGem.GetGem(rangeIndex<=7 ? 1:2); getGemIndex--; } public void GetCarrotGem(GameObject gem) { var carrotGem = gem.transform.GetComponent(); if(carrotGem==null||isGetGem) return; if (tasks[curTaskId].isWin|| getGemIndex==1) { carrotGem.GetGem(3); getGemIndex--; return; } int rangeIndex=Random.Range(1,11); carrotGem.GetGem(rangeIndex<=7 ? 1:2); getGemIndex--; } public void GetPuzzle(int id) { tasks[3].GetComponent().GetPuzzle(id); } }