162 lines
4.2 KiB
C#
162 lines
4.2 KiB
C#
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<Task> tasks = new List<Task>();
|
|
|
|
public int curTaskId;
|
|
|
|
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<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
|
{
|
|
for (int i = 0; i < hopeIcons.Length; i++)
|
|
{
|
|
hopeIcons[i].SetActive(i==curTaskId);
|
|
}
|
|
hopeBookMesh.gameObject.SetActive(true);
|
|
},2);
|
|
isGetGem = false;
|
|
}
|
|
|
|
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<TaskBox>().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<SeekGem>().Init(gemId);
|
|
break;
|
|
case 1:
|
|
gem.GetComponent<BubblesGem>().Init(gemId);
|
|
break;
|
|
case 2:
|
|
gem.GetComponent<CarrotGem>().Init(gemId);
|
|
break;
|
|
}
|
|
tasks[curTaskId].curGems.Add(gem);
|
|
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<SeekGem>();
|
|
if(seekGem==null||isGetGem)
|
|
return;
|
|
if (tasks[curTaskId].isWin)
|
|
{
|
|
seekGem.GetGem(3);
|
|
return;
|
|
}
|
|
int rangeIndex=Random.Range(1,11);
|
|
seekGem.GetGem(rangeIndex<=7 ? 1:2);
|
|
|
|
}
|
|
|
|
public void GetBubblesGem(GameObject gem)
|
|
{
|
|
var bubblesGem = gem.transform.GetComponent<BubblesGem>();
|
|
if(bubblesGem==null||isGetGem)
|
|
return;
|
|
if (tasks[curTaskId].isWin)
|
|
{
|
|
bubblesGem.GetGem(3);
|
|
return;
|
|
}
|
|
int rangeIndex=Random.Range(1,11);
|
|
bubblesGem.GetGem(rangeIndex<=7 ? 1:2);
|
|
}
|
|
|
|
public void GetCarrotGem(GameObject gem)
|
|
{
|
|
var carrotGem = gem.transform.GetComponent<CarrotGem>();
|
|
if(carrotGem==null||isGetGem)
|
|
return;
|
|
if (tasks[curTaskId].isWin)
|
|
{
|
|
carrotGem.GetGem(3);
|
|
return;
|
|
}
|
|
int rangeIndex=Random.Range(1,11);
|
|
carrotGem.GetGem(rangeIndex<=7 ? 1:2);
|
|
}
|
|
|
|
public void GetPuzzle(int id)
|
|
{
|
|
tasks[3].GetComponent<PuzzleTask>().GetPuzzle(id);
|
|
}
|
|
}
|