|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using UnityEngine.UI;
|
|
|
using UnityEngine.EventSystems;
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
namespace Level12
|
|
|
{
|
|
|
public class Level12 : MonoBehaviour
|
|
|
{
|
|
|
public int AllQuesition = 4;
|
|
|
public GameObject GuanModel1, GuanModel2;
|
|
|
public Text title,one,two,three,four;
|
|
|
public Button okbtn, backbtn,tipsOk,tipsQuxiao,shangfamenBtn,xiafamenBtn,endTipsOkBtn,upBtn,downBtn;
|
|
|
public GameObject model,model2, modelImg,model2Img, shangfamenObj,xiafamenObj,romModel;
|
|
|
public ToggleGroup togGroup;
|
|
|
public GameObject tipUI,endTipsUI;
|
|
|
List<Subject> subjectsList = new List<Subject>();
|
|
|
int PassIndex = 12, QuestionIndex = 0;
|
|
|
public float RotSpeed = 10f;
|
|
|
public float ScaleMax = 4;
|
|
|
public float ScaleMin = 1;
|
|
|
float upMax = 2.2f;
|
|
|
double scaleX=1.0d;
|
|
|
int[] answer= { 0, 0, 0, 0};
|
|
|
bool[] answerbool = { false, false };
|
|
|
Vector3 shangfamenPosV3 = new Vector3(-2.86f, 2.94f, 0.7f);
|
|
|
Vector3 shangfamenEul = new Vector3(-2.31f, 13.5f, -89.7f);
|
|
|
Vector3 xiafamenPosV3 = new Vector3(-0.12f, 0.13f, 0.01f);
|
|
|
Vector3 xiafamenEul = new Vector3(0, 0, -91.96f);
|
|
|
bool shangfamenBool = false,xiafamenBool=false;
|
|
|
bool isClickFaMen = false;
|
|
|
void Start()
|
|
|
{
|
|
|
InitData();
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
{
|
|
|
Toggle t = togGroup.transform.Find(((i+1).ToString())).GetComponent<Toggle>();
|
|
|
togGroup.RegisterToggle(t);
|
|
|
t.onValueChanged.AddListener(on => {
|
|
|
if (on) answer[QuestionIndex] = (int.Parse(t.name));
|
|
|
else answer[QuestionIndex] = 0;
|
|
|
});
|
|
|
}
|
|
|
okbtn.onClick.AddListener(delegate () {
|
|
|
if (QuestionIndex == 4) return;
|
|
|
QuestionIndex += 1;
|
|
|
if (QuestionIndex == 1)
|
|
|
{
|
|
|
GuanModel1.SetActive(false);
|
|
|
GuanModel2.SetActive(true);
|
|
|
}
|
|
|
if (QuestionIndex >= 3 && isClickFaMen == false)
|
|
|
{
|
|
|
tipUI.SetActive(true);
|
|
|
return;
|
|
|
}else if (answer[QuestionIndex-1] == 0&&QuestionIndex<=2)
|
|
|
{
|
|
|
tipUI.SetActive(true);
|
|
|
return;
|
|
|
}
|
|
|
if (QuestionIndex >= 3)
|
|
|
{
|
|
|
GameRoot.SubmitOprerationAnswer(PassIndex, QuestionIndex, answerbool);
|
|
|
Debug.Log("提交第" + QuestionIndex);
|
|
|
if (QuestionIndex == subjectsList.Count)
|
|
|
{
|
|
|
endTipsUI.SetActive(true);
|
|
|
return;
|
|
|
}
|
|
|
SetUIData(QuestionIndex);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SubmitChoiceAnswer();
|
|
|
SetUIData(QuestionIndex);
|
|
|
}
|
|
|
});
|
|
|
backbtn.onClick.AddListener(delegate ()
|
|
|
{
|
|
|
GameRoot.ReturnMenu();
|
|
|
});
|
|
|
tipsOk.onClick.AddListener(delegate ()
|
|
|
{
|
|
|
if (QuestionIndex >= 3)
|
|
|
{
|
|
|
GameRoot.SubmitOprerationAnswer(PassIndex, QuestionIndex, answerbool);
|
|
|
Debug.Log("提交第" + QuestionIndex);
|
|
|
SetUIData(QuestionIndex);
|
|
|
if (QuestionIndex==subjectsList.Count)
|
|
|
endTipsUI.SetActive(true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SubmitChoiceAnswer();
|
|
|
SetUIData(QuestionIndex);
|
|
|
}
|
|
|
tipUI.SetActive(false);
|
|
|
});
|
|
|
tipsQuxiao.onClick.AddListener(delegate ()
|
|
|
{
|
|
|
QuestionIndex -= 1;
|
|
|
tipUI.SetActive(false);
|
|
|
});
|
|
|
shangfamenBtn.onClick.AddListener(delegate ()
|
|
|
{
|
|
|
if (isClickFaMen == false) isClickFaMen = true;
|
|
|
shangfamenBool = !shangfamenBool;
|
|
|
Vector3 tPos = Vector3.zero;
|
|
|
Vector3 tEul = Vector3.zero;
|
|
|
if (QuestionIndex == 2)
|
|
|
{
|
|
|
tPos = shangfamenBool ? Vector3.zero : shangfamenPosV3;
|
|
|
tEul = shangfamenBool ? Vector3.zero : shangfamenEul;
|
|
|
}else if (QuestionIndex == 3)
|
|
|
{
|
|
|
tPos = shangfamenBool ? shangfamenPosV3:Vector3.zero;
|
|
|
tEul = shangfamenBool ? shangfamenEul:Vector3.zero;
|
|
|
}
|
|
|
shangfamenObj.transform.localPosition = tPos;
|
|
|
shangfamenObj.transform.localEulerAngles = tEul;
|
|
|
answerbool[0] = shangfamenBool;
|
|
|
});
|
|
|
xiafamenBtn.onClick.AddListener(delegate ()
|
|
|
{
|
|
|
if (isClickFaMen == false) isClickFaMen = true;
|
|
|
xiafamenBool = !xiafamenBool;
|
|
|
Vector3 tPos = Vector3.zero ;
|
|
|
Vector3 tEul = Vector3.zero ;
|
|
|
if (QuestionIndex == 2)
|
|
|
{
|
|
|
tPos = xiafamenBool ? Vector3.zero : xiafamenPosV3;
|
|
|
tEul = xiafamenBool ? Vector3.zero : xiafamenEul;
|
|
|
}else if (QuestionIndex == 3)
|
|
|
{
|
|
|
tPos = xiafamenBool ? xiafamenPosV3:Vector3.zero ;
|
|
|
tEul = xiafamenBool ? xiafamenEul:Vector3.zero ;
|
|
|
}
|
|
|
xiafamenObj.transform.localPosition = tPos;
|
|
|
xiafamenObj.transform.localEulerAngles = tEul;
|
|
|
answerbool[1] = xiafamenBool;
|
|
|
});
|
|
|
endTipsOkBtn.onClick.AddListener(delegate ()
|
|
|
{
|
|
|
GameRoot.ReturnMenu();
|
|
|
});
|
|
|
|
|
|
SetUIData(QuestionIndex);
|
|
|
}
|
|
|
|
|
|
public void PassOver()
|
|
|
{
|
|
|
GameRoot.SubmitPassState(12, true);
|
|
|
}
|
|
|
|
|
|
public void MoveDown()
|
|
|
{
|
|
|
Vector3 tmpV3 = model.transform.localPosition;
|
|
|
if (tmpV3.y < upMax)
|
|
|
{
|
|
|
GuanModel1.transform.localPosition = new Vector3(tmpV3.x, tmpV3.y += 0.2f, tmpV3.z);
|
|
|
GuanModel2.transform.localPosition = new Vector3(tmpV3.x, tmpV3.y += 0.2f, tmpV3.z);
|
|
|
}
|
|
|
}
|
|
|
public void MoveUp()
|
|
|
{
|
|
|
|
|
|
Vector3 tmpV3 = model.transform.localPosition;
|
|
|
if (tmpV3.y > 1 || scaleX > 1)
|
|
|
{
|
|
|
string s = string.Format("{0:N1}", scaleX);
|
|
|
string[] strArr = s.Split('.');
|
|
|
s = strArr[1];
|
|
|
float newV = float.Parse(s) * 0.1f;
|
|
|
if (tmpV3.y < 0)
|
|
|
newV = 2.0f;
|
|
|
if (tmpV3.y > -newV)
|
|
|
{
|
|
|
GuanModel1.transform.localPosition = new Vector3(tmpV3.x, tmpV3.y -= 0.2f, tmpV3.z);
|
|
|
GuanModel2.transform.localPosition = new Vector3(tmpV3.x, tmpV3.y -= 0.2f, tmpV3.z);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void SubmitChoiceAnswer()
|
|
|
{
|
|
|
GameRoot.SubmitChoiceAnswer(PassIndex, QuestionIndex, answer[QuestionIndex-1]);
|
|
|
Debug.Log("提交第" + QuestionIndex);
|
|
|
}
|
|
|
void SetUIData(int index)
|
|
|
{
|
|
|
if (index >= AllQuesition) return;
|
|
|
title.text = subjectsList[index].title;
|
|
|
one.text = subjectsList[index].one;
|
|
|
two.text = subjectsList[index].two;
|
|
|
three.text = subjectsList[index].three;
|
|
|
four.text = subjectsList[index].four;
|
|
|
togGroup.SetAllTogglesOff(false);
|
|
|
if (index == 2)
|
|
|
{
|
|
|
model.SetActive(false);
|
|
|
modelImg.transform.parent.gameObject.SetActive(false);
|
|
|
togGroup.gameObject.SetActive(false);
|
|
|
model2.SetActive(true);
|
|
|
romModel.gameObject.SetActive(true);
|
|
|
model2Img.SetActive(true);
|
|
|
shangfamenBtn.gameObject.SetActive(true);
|
|
|
xiafamenBtn.gameObject.SetActive(true);
|
|
|
}
|
|
|
if (index == 3)
|
|
|
{
|
|
|
isClickFaMen = false;
|
|
|
answerbool[0] = false;answerbool[1] = false;
|
|
|
shangfamenBool = false;xiafamenBool = false;
|
|
|
xiafamenObj.transform.localPosition = Vector3.zero;
|
|
|
xiafamenObj.transform.localEulerAngles = Vector3.zero;
|
|
|
shangfamenObj.transform.localPosition = Vector3.zero;
|
|
|
shangfamenObj.transform.localEulerAngles = Vector3.zero;
|
|
|
}
|
|
|
}
|
|
|
//上下旋转最大角度限制
|
|
|
public int yMinLimit = -20;
|
|
|
public int yMaxLimit = 80;
|
|
|
//旋转速度
|
|
|
public float xSpeed = 250.0f;//左右旋转速度
|
|
|
public float ySpeed = 120.0f;//上下旋转速度
|
|
|
//旋转角度
|
|
|
private float x = 0.0f;
|
|
|
private float y = 0.0f;
|
|
|
|
|
|
//角度范围值限定
|
|
|
static float ClampAngle(float angle, float min, float max)
|
|
|
{
|
|
|
if (angle < -360)
|
|
|
angle += 360;
|
|
|
if (angle > 360)
|
|
|
angle -= 360;
|
|
|
return Mathf.Clamp(angle, min, max);
|
|
|
}
|
|
|
void InitData()
|
|
|
{
|
|
|
Subject one = new Subject();
|
|
|
one.title = "【1/4】请检查消防水箱的玻璃管液位计。(单选)";
|
|
|
one.one = "刻度模糊、上阀门丢失";
|
|
|
one.two = "上阀门丢失、下阀门破裂、管壁破裂、刻度模糊";
|
|
|
one.three = "刻度缺失、下阀门缺失";
|
|
|
one.four = "刻度模糊、管壁破裂、下阀门丢失";
|
|
|
subjectsList.Add(one);
|
|
|
Subject two = new Subject();
|
|
|
two.title = "【2/4】请读取液位计显示刻度。(单选)";
|
|
|
two.one = "110CM≤水位<130CM";
|
|
|
two.two = "140CM≤水位<160CM";
|
|
|
two.three = "170CM≤水位<190CM";
|
|
|
two.four = "200CM≤水位<220CM";
|
|
|
subjectsList.Add(two);
|
|
|
Subject three = new Subject();
|
|
|
three.title = "【3/4】请关闭液位计阀门";
|
|
|
subjectsList.Add(three);
|
|
|
Subject four = new Subject();
|
|
|
four.title = "【4/4】请开启液位计阀门";
|
|
|
subjectsList.Add(four);
|
|
|
}
|
|
|
float modelScale;
|
|
|
void Update()
|
|
|
{
|
|
|
#region MyRegion
|
|
|
//if (Input.GetMouseButton(0))
|
|
|
//{
|
|
|
// x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
|
|
|
// y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
|
|
|
// y = ClampAngle(y, yMinLimit, yMaxLimit);
|
|
|
// //欧拉角转化为四元数
|
|
|
// Quaternion rotation = Quaternion.Euler(0, x, 0);
|
|
|
// model.transform.rotation = rotation;
|
|
|
//}
|
|
|
//modelScale = Input.GetAxis("Mouse ScrollWheel");
|
|
|
//if (model.transform.localScale.x > 2)
|
|
|
// return;
|
|
|
//if ((modelScale > 0)|| (model.transform.localScale.x > 1 && modelScale < 0))
|
|
|
//{
|
|
|
// Vector3 tV3 = model.transform.localScale;
|
|
|
// model.transform.localScale = new Vector3(tV3.x + modelScale, tV3.y + modelScale, tV3.z + modelScale);
|
|
|
// if (model.transform.localScale.x > 2)
|
|
|
// model.transform.localScale = Vector3.one * 2;
|
|
|
// if (model.transform.localScale.x < 1)
|
|
|
// {
|
|
|
// model.transform.localScale = Vector3.one;
|
|
|
// model.transform.localPosition = new Vector3(model.transform.localPosition.x, 1, 0);
|
|
|
// }
|
|
|
|
|
|
// scaleX = model.transform.localScale.y;
|
|
|
//}
|
|
|
#endregion
|
|
|
|
|
|
RotateModel(GuanModel1);
|
|
|
RotateModel(GuanModel2);
|
|
|
|
|
|
}
|
|
|
|
|
|
void RotateModel(GameObject model)
|
|
|
{
|
|
|
if (Input.GetMouseButton(0))
|
|
|
{
|
|
|
x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
|
|
|
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
|
|
|
y = ClampAngle(y, yMinLimit, yMaxLimit);
|
|
|
//欧拉角转化为四元数
|
|
|
Quaternion rotation = Quaternion.Euler(0, x, 0);
|
|
|
model.transform.rotation = rotation;
|
|
|
}
|
|
|
modelScale = Input.GetAxis("Mouse ScrollWheel");
|
|
|
if (model.transform.localScale.x > 2)
|
|
|
return;
|
|
|
if ((modelScale > 0) || (model.transform.localScale.x > 1 && modelScale < 0))
|
|
|
{
|
|
|
Vector3 tV3 = model.transform.localScale;
|
|
|
model.transform.localScale = new Vector3(tV3.x + modelScale, tV3.y + modelScale, tV3.z + modelScale);
|
|
|
if (model.transform.localScale.x > 2)
|
|
|
model.transform.localScale = Vector3.one * 2;
|
|
|
if (model.transform.localScale.x < 1)
|
|
|
{
|
|
|
model.transform.localScale = Vector3.one;
|
|
|
model.transform.localPosition = new Vector3(model.transform.localPosition.x, 1, 0);
|
|
|
}
|
|
|
|
|
|
scaleX = model.transform.localScale.y;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Subject
|
|
|
{
|
|
|
public string title;
|
|
|
public string one;
|
|
|
public string two;
|
|
|
public string three;
|
|
|
public string four;
|
|
|
}
|
|
|
class UIEventListener : UnityEngine.EventSystems.EventTrigger
|
|
|
{
|
|
|
public delegate void VoidDelegate(GameObject go);
|
|
|
public delegate void VoidEventDelegate(PointerEventData eventData);
|
|
|
public VoidDelegate onClick;
|
|
|
|
|
|
public VoidEventDelegate onDrag;
|
|
|
public VoidEventDelegate onBeginDrag;
|
|
|
public VoidEventDelegate onEndDrag;
|
|
|
|
|
|
|
|
|
static public UIEventListener Get(GameObject go)
|
|
|
{
|
|
|
UIEventListener listener = go.GetComponent<UIEventListener>();
|
|
|
if (listener == null) listener = go.AddComponent<UIEventListener>();
|
|
|
return listener;
|
|
|
}
|
|
|
public override void OnPointerClick(PointerEventData eventData)
|
|
|
{
|
|
|
if (onClick != null) onClick(gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public override void OnDrag(PointerEventData eventData)
|
|
|
{
|
|
|
//if (eventData.button == PointerEventData.InputButton.Left)
|
|
|
if (onDrag != null) onDrag(eventData);
|
|
|
}
|
|
|
|
|
|
public override void OnBeginDrag(PointerEventData eventData)
|
|
|
{
|
|
|
if (eventData.button == PointerEventData.InputButton.Left)
|
|
|
if (onBeginDrag != null)
|
|
|
onBeginDrag(eventData);
|
|
|
}
|
|
|
public override void OnEndDrag(PointerEventData eventData)
|
|
|
{
|
|
|
if (eventData.button == PointerEventData.InputButton.Left)
|
|
|
if (onEndDrag != null) onEndDrag(eventData);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|