121 lines
3.2 KiB
C#
121 lines
3.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DragonLi.Core;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class PlayerModel : MonoBehaviour
|
|
{
|
|
public GameObject[] dress;
|
|
|
|
public GameObject t_Dress;
|
|
|
|
public GameObject shoe1;
|
|
public GameObject shoe2;
|
|
|
|
public int maxOverIndex;
|
|
|
|
public Animator playAir;
|
|
public Animator yiFuAir;
|
|
public GameObject playEx;
|
|
public GameObject winPuzzleEx;
|
|
public GameObject losePuzzleEx;
|
|
|
|
private int _overIndex;
|
|
|
|
public void Init()
|
|
{
|
|
maxOverIndex = 6;
|
|
foreach (var item in dress)
|
|
{
|
|
item.SetActive(false);
|
|
}
|
|
t_Dress.SetActive(true);
|
|
shoe1.SetActive(true);
|
|
shoe2.SetActive(true);
|
|
playEx.gameObject.SetActive(false);
|
|
winPuzzleEx.gameObject.SetActive(false);
|
|
losePuzzleEx.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void TryPuzzle(int id,GameObject dressItem)
|
|
{
|
|
dress[id].SetActive(true);
|
|
dressItem.transform.position=dress[id].transform.position;
|
|
dressItem.transform.eulerAngles = dress[id].transform.eulerAngles;
|
|
dressItem.SetActive(false);
|
|
dressItem.GetComponent<BoxCollider>().enabled = false;
|
|
if(dress[1].activeSelf&&dress[3].activeSelf)
|
|
t_Dress.SetActive(false);
|
|
if (id == 5)
|
|
{
|
|
shoe1.SetActive(false);
|
|
shoe2.SetActive(false);
|
|
}
|
|
if (id <= 5)
|
|
{
|
|
WinPuzzle();
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(LosePuzzle(id,dressItem));
|
|
}
|
|
GameManager.Ins.taskManager.tasks[3].GetComponent<PuzzleTask>().isGetPuzzle = false;
|
|
}
|
|
|
|
public void WinPuzzle()
|
|
{
|
|
//播放正确特效
|
|
winPuzzleEx.SetActive(true);
|
|
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
|
{
|
|
winPuzzleEx.SetActive(false);
|
|
},2f);
|
|
//播放正确音效
|
|
GameManager.Ins.PlaySound2DRPC("1.40");
|
|
//播放正确动作
|
|
_overIndex++;
|
|
if (_overIndex >= maxOverIndex)
|
|
{
|
|
StartCoroutine(OverPuzzle());
|
|
}
|
|
}
|
|
|
|
IEnumerator LosePuzzle(int id,GameObject dressItem)
|
|
{
|
|
//播放错误特效
|
|
losePuzzleEx.SetActive(true);
|
|
//播放错误音效
|
|
GameManager.Ins.PlaySound2DRPC("1.41");
|
|
//播放错误动作
|
|
yield return new WaitForSeconds(2f);
|
|
dress[id].SetActive(false);
|
|
losePuzzleEx.SetActive(false);
|
|
dressItem.SetActive(true);
|
|
dressItem.GetComponent<PuzzleItem>().StartFly();
|
|
}
|
|
|
|
IEnumerator OverPuzzle()
|
|
{
|
|
//模型播放全部完成动画
|
|
playEx.gameObject.SetActive(true);
|
|
playAir.SetBool("over",true);
|
|
yiFuAir.SetBool("over", true);
|
|
yield return new WaitForSeconds(2f);
|
|
GameManager.Ins.taskManager.CompleteTask();
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.tag == "Puzzle")
|
|
{
|
|
if (other.GetComponent<PuzzleItem>())
|
|
{
|
|
var curPuzzleItem = other.GetComponent<PuzzleItem>();
|
|
TryPuzzle(curPuzzleItem.id,other.gameObject);
|
|
}
|
|
}
|
|
}
|
|
}
|