You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
443 lines
17 KiB
443 lines
17 KiB
3 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using HTC.UnityPlugin.Vive;
|
||
|
|
||
|
//教程部分的关卡
|
||
|
//玩家一旦进入该场景,会提前弹出窗口,询问是否进行教学
|
||
|
//如果不需要,自动解除像素
|
||
|
public class PixelAppear : MonoBehaviour {
|
||
|
public GameObject box_;
|
||
|
public GameObject pixelImage;
|
||
|
public GameObject[] PannelObj;
|
||
|
private GameObject newPixel;
|
||
|
private Pixel pixelList;
|
||
|
private bool isDisappearing;
|
||
|
public GameObject[] allPixelO;
|
||
|
private List<Pixel> allPixelI;
|
||
|
//是否需要进行教程(不再提示)
|
||
|
private bool isNeedTeach;
|
||
|
//是否需要进行教程(提示)
|
||
|
private bool confirmNeedTeach;
|
||
|
//获取镜头
|
||
|
private GameObject Camera_;
|
||
|
//获取右侧手柄
|
||
|
private GameObject rightHand_;
|
||
|
//获取玩家对象
|
||
|
private GameObject Player_;
|
||
|
//教学步骤
|
||
|
private int teachingStep_;
|
||
|
public GameObject[] ConfirmCamera_;
|
||
|
public GameObject ConfirmCameraAll_;
|
||
|
public GameObject[] ConfirmHand;
|
||
|
public GameObject ConfirmHandAll_;
|
||
|
public GameObject[] ConfirmFeet;
|
||
|
public GameObject ConfirmFeetAll_;
|
||
|
public GameObject TeachingArrow_;
|
||
|
public GameObject TeachingMoving_;
|
||
|
public GameObject TeachingUsing_;
|
||
|
//教学文字
|
||
|
public Text teachingTxt;
|
||
|
|
||
|
|
||
|
// Use this for initialization
|
||
|
void Start () {
|
||
|
pixelAppear();
|
||
|
isDisappearing = false;
|
||
|
Camera_ = GameObject.FindGameObjectWithTag("MainCamera");
|
||
|
rightHand_ = GameObject.FindGameObjectWithTag("rightHand");
|
||
|
Player_ = GameObject.FindGameObjectWithTag("Player");
|
||
|
teachingStep_ = 0;
|
||
|
StartSelect();
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update () {
|
||
|
/*if (Input.GetKeyDown(KeyCode.A)) {
|
||
|
isDisappearing = true;
|
||
|
}*/
|
||
|
if (isDisappearing) {
|
||
|
/*foreach (Pixel pixelI in allPixelI) {
|
||
|
pixelI.disappearPixel();
|
||
|
}*/
|
||
|
pixelDisappear();
|
||
|
}
|
||
|
box_.transform.position = new Vector3(Camera_.transform.position.x, 1.3f, Camera_.transform.position.z-1.5f);
|
||
|
|
||
|
}
|
||
|
|
||
|
//制造像素,并把像素放置在固定的数组里面
|
||
|
void pixelAppear() {
|
||
|
for (int panel_num = 0; panel_num < PannelObj.Length; panel_num++) {
|
||
|
for (int j = 0; j < 15; j++)
|
||
|
{
|
||
|
for (int i = 0; i < 15; i++)
|
||
|
{
|
||
|
newPixel = Instantiate(pixelImage, PannelObj[panel_num].transform);
|
||
|
newPixel.transform.localPosition = new Vector3(i * 4f - 28f, j * 4f - 28f, 0f);
|
||
|
//pixelArray.Add(newPixel);
|
||
|
pixelList = newPixel.GetComponent<Pixel>();
|
||
|
pixelList.x = i;
|
||
|
pixelList.y = j;
|
||
|
//float actionNo = (Mathf.Abs(7 - i) + Mathf.Abs(7 - j));
|
||
|
pixelList.randomTime = Random.Range(0.75f,3.5f);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void pixelDisappear() {
|
||
|
allPixelO = GameObject.FindGameObjectsWithTag("Pixel");
|
||
|
|
||
|
for (int i = 0;i<allPixelO.Length;i++) {
|
||
|
//print(allPixelO[i].GetComponent<Pixel>().x);
|
||
|
allPixelO[i].GetComponent<Pixel>().disappearPixel();
|
||
|
}
|
||
|
//isDisappearing = true;
|
||
|
}
|
||
|
|
||
|
//开始时是否进行教程操作
|
||
|
private void StartSelect() {
|
||
|
StartCoroutine(TeachActionAll());
|
||
|
}
|
||
|
//教程逻辑实现
|
||
|
IEnumerator TeachActionAll() {
|
||
|
print("StartTeaching");
|
||
|
yield return StartCoroutine(TeachAction_0());
|
||
|
print("EndTeaching");
|
||
|
isDisappearing = true;
|
||
|
}
|
||
|
|
||
|
//确认是否跳过教程
|
||
|
IEnumerator TeachAction_0() {
|
||
|
while (teachingStep_ != -1) {
|
||
|
if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.Trigger))
|
||
|
{
|
||
|
teachingStep_ = 1;
|
||
|
yield return StartCoroutine(TeachAction_1());
|
||
|
yield return StartCoroutine(TeachAction_2());
|
||
|
yield return StartCoroutine(TeachAction_3());
|
||
|
yield return StartCoroutine(TeachAction_4());
|
||
|
yield return StartCoroutine(TeachAction_5());
|
||
|
yield return StartCoroutine(TeachAction_6());
|
||
|
yield return StartCoroutine(TeachAction_end());
|
||
|
teachingStep_ = -1;
|
||
|
}
|
||
|
else if (ViveInput.GetPress(HandRole.LeftHand, ControllerButton.Trigger))
|
||
|
{
|
||
|
yield return StartCoroutine(TeachAction_end());
|
||
|
teachingStep_ = -1;
|
||
|
}
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
//教程1
|
||
|
IEnumerator TeachAction_1() {
|
||
|
ConfirmCameraAll_.SetActive(true);
|
||
|
teachingTxt.text = "请上下左右晃动头部,检测头盔精度";
|
||
|
Vector3 startPos = Camera_.transform.localEulerAngles;
|
||
|
int correctCamera = 0;
|
||
|
float radiusX = 0;
|
||
|
float radiusY = 0;
|
||
|
ImageChange_ imageChangeScript1 = ConfirmCamera_[0].GetComponent<ImageChange_>();
|
||
|
ImageChange_ imageChangeScript2 = ConfirmCamera_[1].GetComponent<ImageChange_>();
|
||
|
ImageChange_ imageChangeScript3 = ConfirmCamera_[2].GetComponent<ImageChange_>();
|
||
|
ImageChange_ imageChangeScript4 = ConfirmCamera_[3].GetComponent<ImageChange_>();
|
||
|
while (teachingStep_ != 2) {
|
||
|
radiusX = Camera_.transform.localEulerAngles.x - startPos.x;
|
||
|
radiusY = Camera_.transform.localEulerAngles.y - startPos.y;
|
||
|
if (radiusX < -180f) {
|
||
|
radiusX += 360f;
|
||
|
} else if (radiusX >180f) {
|
||
|
radiusX -= 360f;
|
||
|
}
|
||
|
if (radiusY < -180f)
|
||
|
{
|
||
|
radiusY += 360f;
|
||
|
}else if (radiusY > 180f)
|
||
|
{
|
||
|
radiusY -= 360f;
|
||
|
}
|
||
|
if (!imageChangeScript1.ischange && radiusX < -30f) {
|
||
|
imageChangeScript1.SetChange();
|
||
|
startPos = Camera_.transform.localEulerAngles;
|
||
|
correctCamera++;
|
||
|
}
|
||
|
if (!imageChangeScript2.ischange && radiusX > 30f)
|
||
|
{
|
||
|
imageChangeScript2.SetChange();
|
||
|
startPos = Camera_.transform.localEulerAngles;
|
||
|
correctCamera++;
|
||
|
}
|
||
|
if (!imageChangeScript3.ischange && radiusY < -30f)
|
||
|
{
|
||
|
imageChangeScript3.SetChange();
|
||
|
startPos = Camera_.transform.localEulerAngles;
|
||
|
correctCamera++;
|
||
|
}
|
||
|
if (!imageChangeScript4.ischange && radiusY > 30f)
|
||
|
{
|
||
|
imageChangeScript4.SetChange();
|
||
|
startPos = Camera_.transform.localEulerAngles;
|
||
|
correctCamera++;
|
||
|
}
|
||
|
if (correctCamera == 4)
|
||
|
{
|
||
|
teachingStep_ = 2;
|
||
|
}
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
ConfirmCameraAll_.SetActive(false);
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
//教程2
|
||
|
IEnumerator TeachAction_2()
|
||
|
{
|
||
|
ConfirmHandAll_.SetActive(true);
|
||
|
teachingTxt.text = "请上下左右晃动右手柄,检测手部精度";
|
||
|
Vector3 startPos = rightHand_.transform.position;
|
||
|
int correctHand = 0;
|
||
|
float distanceX = 0;
|
||
|
float distanceY = 0;
|
||
|
float distanceZ = 0;
|
||
|
float distanceXZ = 0;
|
||
|
ImageChange_ imageChangeScript1 = ConfirmHand[0].GetComponent<ImageChange_>();
|
||
|
ImageChange_ imageChangeScript2 = ConfirmHand[1].GetComponent<ImageChange_>();
|
||
|
ImageChange_ imageChangeScript3 = ConfirmHand[2].GetComponent<ImageChange_>();
|
||
|
ImageChange_ imageChangeScript4 = ConfirmHand[3].GetComponent<ImageChange_>();
|
||
|
while (teachingStep_ != 3)
|
||
|
{
|
||
|
distanceX = rightHand_.transform.position.x - startPos.x;
|
||
|
distanceY = rightHand_.transform.position.y - startPos.y;
|
||
|
distanceZ = rightHand_.transform.position.z - startPos.z;
|
||
|
distanceXZ = distanceX + distanceZ;
|
||
|
if (!imageChangeScript1.ischange && distanceY > 0.2f)
|
||
|
{
|
||
|
imageChangeScript1.SetChange();
|
||
|
startPos = rightHand_.transform.position;
|
||
|
correctHand++;
|
||
|
}
|
||
|
if (!imageChangeScript2.ischange && distanceY < -0.2f)
|
||
|
{
|
||
|
imageChangeScript2.SetChange();
|
||
|
startPos = rightHand_.transform.position;
|
||
|
correctHand++;
|
||
|
}
|
||
|
if (!imageChangeScript3.ischange && distanceXZ > 0.2f)
|
||
|
{
|
||
|
imageChangeScript3.SetChange();
|
||
|
startPos = rightHand_.transform.position;
|
||
|
correctHand++;
|
||
|
}
|
||
|
if (!imageChangeScript4.ischange && distanceXZ < -0.2f)
|
||
|
{
|
||
|
imageChangeScript4.SetChange();
|
||
|
startPos = rightHand_.transform.position;
|
||
|
correctHand++;
|
||
|
}
|
||
|
if (correctHand == 4)
|
||
|
{
|
||
|
teachingStep_ = 3;
|
||
|
}
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
ConfirmHandAll_.SetActive(false);
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
//教程3
|
||
|
IEnumerator TeachAction_3()
|
||
|
{
|
||
|
ConfirmFeetAll_.SetActive(true);
|
||
|
teachingTxt.text = "请在房间进行走动(指现实)";
|
||
|
Vector3 startPos = Camera_.transform.position;
|
||
|
int correctFeet = 0;
|
||
|
float distanceX = 0;
|
||
|
float distanceZ = 0;
|
||
|
ImageChange_ imageChangeScript1 = ConfirmFeet[0].GetComponent<ImageChange_>();
|
||
|
ImageChange_ imageChangeScript2 = ConfirmFeet[1].GetComponent<ImageChange_>();
|
||
|
ImageChange_ imageChangeScript3 = ConfirmFeet[2].GetComponent<ImageChange_>();
|
||
|
ImageChange_ imageChangeScript4 = ConfirmFeet[3].GetComponent<ImageChange_>();
|
||
|
while (teachingStep_ != 4)
|
||
|
{
|
||
|
distanceX = Camera_.transform.position.x - startPos.x;
|
||
|
distanceZ = Camera_.transform.position.z - startPos.z;
|
||
|
if (!imageChangeScript1.ischange && distanceX > 0.5f)
|
||
|
{
|
||
|
imageChangeScript1.SetChange();
|
||
|
startPos = Camera_.transform.position;
|
||
|
correctFeet++;
|
||
|
}
|
||
|
if (!imageChangeScript2.ischange && distanceX < -0.5f)
|
||
|
{
|
||
|
imageChangeScript2.SetChange();
|
||
|
startPos = Camera_.transform.position;
|
||
|
correctFeet++;
|
||
|
}
|
||
|
if (!imageChangeScript3.ischange && distanceZ > 0.5f)
|
||
|
{
|
||
|
imageChangeScript3.SetChange();
|
||
|
startPos = Camera_.transform.position;
|
||
|
correctFeet++;
|
||
|
}
|
||
|
if (!imageChangeScript4.ischange && distanceZ < -0.5f)
|
||
|
{
|
||
|
imageChangeScript4.SetChange();
|
||
|
startPos = Camera_.transform.position;
|
||
|
correctFeet++;
|
||
|
}
|
||
|
if (correctFeet == 4)
|
||
|
{
|
||
|
teachingStep_ = 4;
|
||
|
}
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
ConfirmFeetAll_.SetActive(false);
|
||
|
isDisappearing = true;
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
//教程4
|
||
|
IEnumerator TeachAction_4() {
|
||
|
Player_.GetComponent<MovingCtrol>().enabled = true;
|
||
|
teachingTxt.text = "按住右手柄的圆板键前进&后退\n转头进行控制方向";
|
||
|
TeachingArrow_.SetActive(false);
|
||
|
TeachingMoving_.SetActive(true);
|
||
|
yield return new WaitForSeconds(10.0f);
|
||
|
TeachingMoving_.SetActive(false);
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
//教程5
|
||
|
public GameObject highLightClip;
|
||
|
public GameObject highLightSwiftArch;
|
||
|
IEnumerator TeachAction_5() {
|
||
|
Player_.GetComponent<PlayerControl>().enabled = true;
|
||
|
Player_.GetComponent<PlayerControl>().Weapon_.SetActive(true);
|
||
|
teachingTxt.text = "按下左手柄的圆板键切换武器\n十秒后进入下一教学";
|
||
|
TeachingMoving_.SetActive(false);
|
||
|
TeachingUsing_.SetActive(true);
|
||
|
yield return new WaitForSeconds(10.0f);
|
||
|
//换弹药教学
|
||
|
teachingTxt.text = "按下左手柄处的手柄键进行换弹";
|
||
|
Player_.GetComponent<PlayerControl>().lockChange = true;
|
||
|
Player_.GetComponent<PlayerControl>().padUpPublic();
|
||
|
bool createClip = false;
|
||
|
bool releaseClip = false;
|
||
|
bool releaseSwiftArch = false;
|
||
|
AkGun ak_ = GameObject.FindGameObjectWithTag("gun").GetComponent<AkGun>();
|
||
|
while (!createClip) {
|
||
|
if (ViveInput.GetPress(HandRole.LeftHand, ControllerButton.Grip))
|
||
|
{
|
||
|
createClip = true;
|
||
|
}
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
highLightClip.SetActive(true);
|
||
|
while (!releaseClip) {
|
||
|
teachingTxt.text = "将左手中的弹药插进弹药槽上";
|
||
|
if (ak_.getHaveBulletClip()) {
|
||
|
releaseClip = true;
|
||
|
};
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
highLightClip.SetActive(false);
|
||
|
highLightSwiftArch.SetActive(true);
|
||
|
while (!releaseSwiftArch)
|
||
|
{
|
||
|
teachingTxt.text = "拉动枪栓后,就完成弹药的装填工作了";
|
||
|
if (ak_.bulletClip.isUsed) {
|
||
|
releaseSwiftArch = true;
|
||
|
}
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
highLightSwiftArch.SetActive(false);
|
||
|
teachingTxt.text = "恭喜您,已经完成了换弹操作!\n五秒后进入下一教学";
|
||
|
//-------------------------//
|
||
|
yield return new WaitForSeconds(5.0f);
|
||
|
teachingTxt.text = "按下右手柄处的手柄键进行治疗";
|
||
|
bool createNeedle = false;
|
||
|
bool cureHp = false;
|
||
|
Player_.GetComponent<Player>().hp = 70;
|
||
|
while (!createNeedle)
|
||
|
{
|
||
|
if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.Grip))
|
||
|
{
|
||
|
createNeedle = true;
|
||
|
}
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
while (!cureHp)
|
||
|
{
|
||
|
teachingTxt.text = "请对准左手,当针亮起时,按住右扳机进行恢复";
|
||
|
if (Player_.GetComponent<Player>().hp >= 100)
|
||
|
{
|
||
|
cureHp = true;
|
||
|
}
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
teachingTxt.text = "恭喜您,已经完成了治疗操作!\n五秒后进入下一教学";
|
||
|
Player_.GetComponent<PlayerControl>().gripRightPublic();
|
||
|
yield return new WaitForSeconds(5.0f);
|
||
|
|
||
|
TeachingUsing_.SetActive(false);
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
//教程6
|
||
|
public GameObject highLightSlider;
|
||
|
IEnumerator TeachAction_6() {
|
||
|
teachingTxt.text = "请用指针指向其中的一个配件";
|
||
|
Player_.GetComponent<PlayerControl>().leftPointer.SetActive(true);
|
||
|
MenuController_2 menu = GameObject.FindGameObjectWithTag("menu").GetComponent<MenuController_2>();
|
||
|
menu.openMenu(3);
|
||
|
bool selectItem = false;
|
||
|
bool installItem = false;
|
||
|
while (!installItem) {
|
||
|
if (ViveInput.GetPressDown(HandRole.LeftHand, ControllerButton.Trigger) && selectItem)
|
||
|
{
|
||
|
selectItem = false;
|
||
|
highLightSlider.SetActive(false);
|
||
|
teachingTxt.text = "请用指针指向其中的一个配件";
|
||
|
}
|
||
|
if (!selectItem && !Player_.GetComponent<PlayerControl>().leftPointer.activeSelf) {
|
||
|
selectItem = true;
|
||
|
highLightSlider.SetActive(true);
|
||
|
teachingTxt.text = "请将配件放置在枪的滑槽上面";
|
||
|
}
|
||
|
|
||
|
if (selectItem && Player_.GetComponent<PlayerControl>().leftPointer.activeSelf) {
|
||
|
highLightSlider.SetActive(false);
|
||
|
installItem = true;
|
||
|
}
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
}
|
||
|
teachingTxt.text = "可以用左手按住扳机拖动刚安装的配件,调整到合适的位置";
|
||
|
Player_.GetComponent<PlayerControl>().lockChange = false;
|
||
|
yield return new WaitForSeconds(5.0f);
|
||
|
teachingTxt.text = "恭喜您,已经完成了所有教学";
|
||
|
yield return new WaitForSeconds(5.0f);
|
||
|
yield return null;
|
||
|
}
|
||
|
|
||
|
//教程结束
|
||
|
public GameObject teachScreen;
|
||
|
IEnumerator TeachAction_end() {
|
||
|
MenuController_2 menu = GameObject.FindGameObjectWithTag("menu").GetComponent<MenuController_2>();
|
||
|
menu.openMenu(4);
|
||
|
teachingTxt.text = "";
|
||
|
Player_.GetComponent<PlayerControl>().rightPointer.SetActive(true);
|
||
|
Player_.GetComponent<PlayerControl>().leftPointer.SetActive(true);
|
||
|
Player_.GetComponent<PlayerControl>().Weapon_.SetActive(false);
|
||
|
Player_.GetComponent<PlayerControl>().enabled = false;
|
||
|
Player_.GetComponent<MovingCtrol>().enabled = true;
|
||
|
box_.SetActive(false);
|
||
|
teachScreen.SetActive(false);
|
||
|
yield return null;
|
||
|
}
|
||
|
}
|