AR_Celement/Assets/Scripts/SwipeManagementScript.cs
2023-01-24 12:07:25 +01:00

201 lines
6.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class SwipeManagementScript : MonoBehaviour
{
public TMP_Text header;
public TMP_Text textSteps;
public List<Text> lengths;
public int numberImage;
public int lengthTexts;
public GameObject arrowLeft;
public GameObject arrowRight;
public GameObject arrow;
public GameObject arrowGravure;
public GameObject arrowXY;
public GameObject arrowHB;
public GameObject arrowPause;
public GameObject circleXY;
public GameObject circleHB;
public GameObject warning;
public Button buttonleft;
public Button buttonright;
public Animator m_Animator;
public TMP_Text textNumber;
public List<int> images;
private Vector2 startTouchPosition;
private Vector2 endTouchPosition;
private GameObject image;
private Image imageUI;
// Start is called before the first frame update
void Start()
{
header.text = "Allumer la Speedy 100";
textSteps.text = lengths[0].text;
textNumber.text = "Step 1/" + (lengthTexts+1);
arrowLeft.gameObject.SetActive(false);
Button btnLeft = buttonleft.GetComponent<Button>();
Button btnRight = buttonright.GetComponent<Button>();
btnLeft.onClick.AddListener(PreviousText);
btnRight.onClick.AddListener(NextText);
}
// Update is called once per frame
void Update()
{
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
startTouchPosition = Input.GetTouch(0).position;
}
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){
endTouchPosition = Input.GetTouch(0).position;
if(endTouchPosition.x < startTouchPosition.x){
NextText();
}else{
PreviousText();
}
if(endTouchPosition.y + 100 < startTouchPosition.y){
SwipeDown();
}
if(endTouchPosition.y - 100 > startTouchPosition.y){
SwipeUp();
}
}
if(numberImage == 1){
header.text = "Pour rappel : ";
arrow.SetActive(true);
warning.SetActive(false);
}
if(numberImage == 2)
{
header.text = "Initialisation : Sécurité";
arrow.SetActive(false);
warning.SetActive(true);
}
if(numberImage == 3)
{
header.text = "Initialisation : Positionnement automatique";
warning.SetActive(false);
}
if(numberImage == 4)
{
header.text = "Placer la pièce à graver";
arrowGravure.SetActive(true);
arrowXY.SetActive(false);
}
if(numberImage == 5)
{
header.text = "Mise au point : Tête de traitement";
arrowGravure.SetActive(false);
arrowXY.SetActive(true);
}
if(numberImage == 7)
{
header.text = "Mise au point : Outil focal";
arrowXY.SetActive(false);
arrowHB.SetActive(false);
}
if(numberImage == 8){
header.text = "Mise au point : Table de gravure";
arrowHB.SetActive(true);
}
if(numberImage == 10){
header.text = "Mise au point : Position du laser";
arrowHB.SetActive(false);
arrowXY.SetActive(true);
}
if(numberImage == 11){
header.text = "Procédure sur ordinateur";
arrowXY.SetActive(false);
arrowPause.SetActive(false);
}
else{
header.text = "Suivre la découpe";
arrowPause.SetActive(true);
}
}
private void NextText(){
if(numberImage < lengthTexts)
{
numberImage ++;
if(numberImage == lengthTexts){
arrowRight.gameObject.SetActive(false);
}else{
arrowRight.gameObject.SetActive(true);
}
if(numberImage != 0){
arrowLeft.gameObject.SetActive(true);
}
if(images.Contains(numberImage - 1)){
DisableImageStep();
}
if(images.Contains(numberImage)){
SetImageStep();
}else{
textSteps.text = lengths[numberImage].text;
textNumber.text = "Step" + (numberImage+1) + "/" + (lengthTexts+1);
}
}
}
private void PreviousText(){
if(numberImage > 0) {
numberImage --;
if(numberImage == 0){
arrowLeft.gameObject.SetActive(false);
}else{
arrowLeft.gameObject.SetActive(true);
}
if(numberImage != lengthTexts){
arrowRight.gameObject.SetActive(true);
}
if(images.Contains(numberImage + 1)){
DisableImageStep();
}
if(images.Contains(numberImage)){
SetImageStep();
}else{
textSteps.text = lengths[numberImage].text;
textNumber.text = "Step" + (numberImage+1) + "/" + (lengthTexts+1);
}
}
}
private void SwipeDown(){
m_Animator.ResetTrigger("SwipeUp");
m_Animator.SetTrigger("SwipeDown");
}
private void SwipeUp(){
m_Animator.ResetTrigger("SwipeDown");
m_Animator.SetTrigger("SwipeUp");
}
private void SetImageStep(){
textSteps.text = "";
textNumber.text = "Step" + (numberImage+1) + "/" + (lengthTexts+1);
image = GameObject.Find("Image"+ numberImage);
imageUI = image.GetComponent<Image>();
imageUI.enabled = true;
}
private void DisableImageStep(){
imageUI.enabled = false;
}
}