mirror of
https://github.com/ConjureETS/MTI860_VR_Multi_Controller.git
synced 2026-03-24 04:21:15 +00:00
Refactor
This commit is contained in:
parent
f23ed304ba
commit
04d85e080b
@ -1,93 +1,93 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Utilities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using static MovementGen;
|
||||
using UnityEngine.SceneManagement;
|
||||
using static Assets.Scripts.MovementGen;
|
||||
|
||||
public class Executable : MonoBehaviour
|
||||
namespace Assets.Scripts.HammerScript
|
||||
{
|
||||
public Timer timer;
|
||||
public string NextScene;
|
||||
public TextMesh text;
|
||||
public bool noMovementChange = true;
|
||||
public bool bloquer = false;
|
||||
public ChoiceOfMovement nextMouv;
|
||||
|
||||
// Si on veut skipper/bypasser le 5-4-3-2-1
|
||||
public bool IsQuickTeleport = false;
|
||||
|
||||
void Start()
|
||||
public class Executable : MonoBehaviour
|
||||
{
|
||||
//Set the tag of this GameObject to Player
|
||||
gameObject.tag = Constant.GT_TARGET;
|
||||
if(noMovementChange)
|
||||
text.text = "";
|
||||
else
|
||||
text.text = nextMouv.ToString();
|
||||
}
|
||||
public Timer timer;
|
||||
public string NextScene;
|
||||
public TextMesh text;
|
||||
public bool noMovementChange = true;
|
||||
public bool bloquer = false;
|
||||
public ChoiceOfMovement nextMouv;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
if (!bloquer) {
|
||||
bloquer = true;
|
||||
if (timer)
|
||||
{
|
||||
timer.Stop();
|
||||
}
|
||||
// Si on veut skipper/bypasser le 5-4-3-2-1
|
||||
public bool IsQuickTeleport = false;
|
||||
|
||||
if (!noMovementChange)
|
||||
{
|
||||
PlayerPrefs.SetInt(Constant.PPK_MOVEMENT_CHOICE, (int)nextMouv);
|
||||
}
|
||||
|
||||
if (IsQuickTeleport)
|
||||
{
|
||||
LoadScene();
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine("TimerExecute");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int count = 0;
|
||||
IEnumerator TimerExecute()
|
||||
{
|
||||
count = 6;
|
||||
while (true)
|
||||
void Start()
|
||||
{
|
||||
count--;
|
||||
if (text != null) {
|
||||
if (count >= 0)
|
||||
text.text = "" + count;
|
||||
else
|
||||
text.text = "Done";
|
||||
}
|
||||
|
||||
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
DataSaver.SaveTime();
|
||||
if (count <= 0)
|
||||
{
|
||||
LoadScene();
|
||||
}
|
||||
//Set the tag of this GameObject to Player
|
||||
gameObject.tag = Constant.GT_TARGET;
|
||||
if(noMovementChange)
|
||||
text.text = "";
|
||||
else
|
||||
text.text = nextMouv.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
public void Execute()
|
||||
{
|
||||
if (!bloquer) {
|
||||
bloquer = true;
|
||||
if (timer)
|
||||
{
|
||||
timer.Stop();
|
||||
}
|
||||
|
||||
private void LoadScene()
|
||||
{
|
||||
PlayerPrefs.SetString(Constant.PPK_SCENE_NAME, NextScene);
|
||||
SceneManager.LoadScene(NextScene);
|
||||
}
|
||||
if (!noMovementChange)
|
||||
{
|
||||
PlayerPrefs.SetInt(Constant.PPK_MOVEMENT_CHOICE, (int)nextMouv);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Debug.Log("Demon detected the colision");
|
||||
if (IsQuickTeleport)
|
||||
{
|
||||
LoadScene();
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine("TimerExecute");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int count = 0;
|
||||
private IEnumerator TimerExecute()
|
||||
{
|
||||
count = 6;
|
||||
while (true)
|
||||
{
|
||||
count--;
|
||||
if (text != null) {
|
||||
if (count >= 0)
|
||||
text.text = "" + count;
|
||||
else
|
||||
text.text = "Done";
|
||||
}
|
||||
|
||||
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
DataSaver.SaveTime();
|
||||
if (count <= 0)
|
||||
{
|
||||
LoadScene();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LoadScene()
|
||||
{
|
||||
PlayerPrefs.SetString(Constant.PPK_SCENE_NAME, NextScene);
|
||||
SceneManager.LoadScene(NextScene);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Debug.Log("Demon detected the colision");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,29 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
public class HammerTrigger : MonoBehaviour
|
||||
namespace Assets.Scripts.HammerScript
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
public class HammerTrigger : MonoBehaviour
|
||||
{
|
||||
gameObject.tag = Constant.GT_HAMMER;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Debug.Log("Hammer detected the colision");
|
||||
if (other.gameObject.tag == Constant.GT_TARGET)
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Executable ex = other.gameObject.GetComponent("Executable") as Executable;
|
||||
ex.Execute();
|
||||
gameObject.tag = Constant.GT_HAMMER;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Debug.Log("Hammer detected the colision");
|
||||
if (other.gameObject.tag == Constant.GT_TARGET)
|
||||
{
|
||||
Executable ex = other.gameObject.GetComponent("Executable") as Executable;
|
||||
ex.Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,67 +1,69 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Movements;
|
||||
using Assets.Scripts.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
public class MovementGen : MonoBehaviour
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
private Dictionary<ChoiceOfMovement, MonoBehaviour> components;
|
||||
private ChoiceOfMovement currentMovement;
|
||||
|
||||
[SerializeField] private ChoiceOfMovement selectedMovement;
|
||||
[SerializeField] private String nomDuJoueur = string.Empty;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
public class MovementGen : MonoBehaviour
|
||||
{
|
||||
components = new Dictionary<ChoiceOfMovement, MonoBehaviour>();
|
||||
components.Add(ChoiceOfMovement.wasd, this.GetComponent<WasdMovement>());
|
||||
components.Add(ChoiceOfMovement.teleport, this.GetComponent<TeleportMovement>());
|
||||
components.Add(ChoiceOfMovement.joystick, this.GetComponent<JoystickMovement>());
|
||||
components.Add(ChoiceOfMovement.joycon, this.GetComponent<JoyCon.JoyConMovement>());
|
||||
components.Add(ChoiceOfMovement.omni, this.GetComponent<OmniMovement>());
|
||||
private Dictionary<ChoiceOfMovement, MonoBehaviour> components;
|
||||
private ChoiceOfMovement currentMovement;
|
||||
|
||||
selectedMovement = (ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE, 0);
|
||||
currentMovement = (ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE, 0);
|
||||
components[currentMovement].enabled = true;
|
||||
[SerializeField] private ChoiceOfMovement selectedMovement;
|
||||
[SerializeField] private String nomDuJoueur = string.Empty;
|
||||
|
||||
if (nomDuJoueur == string.Empty)
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
nomDuJoueur = DateTime.Now.ToString("MM-dd HH:mm");
|
||||
}
|
||||
PlayerPrefs.SetString(Constant.PPK_PLAYER_NAME, nomDuJoueur);
|
||||
}
|
||||
components = new Dictionary<ChoiceOfMovement, MonoBehaviour>();
|
||||
components.Add(ChoiceOfMovement.wasd, this.GetComponent<WasdMovement>());
|
||||
components.Add(ChoiceOfMovement.teleport, this.GetComponent<TeleportMovement>());
|
||||
components.Add(ChoiceOfMovement.joystick, this.GetComponent<JoystickMovement>());
|
||||
components.Add(ChoiceOfMovement.joycon, this.GetComponent<JoyCon.JoyConMovement>());
|
||||
components.Add(ChoiceOfMovement.omni, this.GetComponent<OmniMovement>());
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if(selectedMovement != currentMovement)
|
||||
{
|
||||
if (components[currentMovement] is IScriptDeMovement)
|
||||
selectedMovement = (ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE, 0);
|
||||
currentMovement = (ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE, 0);
|
||||
components[currentMovement].enabled = true;
|
||||
|
||||
if (nomDuJoueur == string.Empty)
|
||||
{
|
||||
|
||||
((IScriptDeMovement) components[currentMovement]).BeforeDisable();
|
||||
nomDuJoueur = DateTime.Now.ToString("MM-dd HH:mm");
|
||||
}
|
||||
|
||||
components[currentMovement].enabled = false;
|
||||
components[selectedMovement].enabled = true;
|
||||
currentMovement = selectedMovement;
|
||||
PlayerPrefs.SetString(Constant.PPK_PLAYER_NAME, nomDuJoueur);
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeMovement(ChoiceOfMovement newChoice)
|
||||
{
|
||||
selectedMovement = newChoice;
|
||||
}
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if(selectedMovement != currentMovement)
|
||||
{
|
||||
if (components[currentMovement] is IScriptDeMovement)
|
||||
{
|
||||
|
||||
public enum ChoiceOfMovement
|
||||
{
|
||||
wasd = 0,
|
||||
teleport = 1,
|
||||
joystick = 2,
|
||||
joycon = 3,
|
||||
omni = 4
|
||||
((IScriptDeMovement) components[currentMovement]).BeforeDisable();
|
||||
}
|
||||
|
||||
components[currentMovement].enabled = false;
|
||||
components[selectedMovement].enabled = true;
|
||||
currentMovement = selectedMovement;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeMovement(ChoiceOfMovement newChoice)
|
||||
{
|
||||
selectedMovement = newChoice;
|
||||
}
|
||||
|
||||
public enum ChoiceOfMovement
|
||||
{
|
||||
wasd = 0,
|
||||
teleport = 1,
|
||||
joystick = 2,
|
||||
joycon = 3,
|
||||
omni = 4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,26 +1,26 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = System.Random;
|
||||
|
||||
public class RandomDemonSpawn : MonoBehaviour
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public GameObject[] listeCommeTuVeux;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
public class RandomDemonSpawn : MonoBehaviour
|
||||
{
|
||||
Random rnd = new Random();
|
||||
int card = rnd.Next(1, 3);
|
||||
public GameObject[] listeCommeTuVeux;
|
||||
|
||||
listeCommeTuVeux[0].SetActive(card == 1);
|
||||
listeCommeTuVeux[1].SetActive(card != 1);
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
int card = rnd.Next(1, 3);
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
listeCommeTuVeux[0].SetActive(card == 1);
|
||||
listeCommeTuVeux[1].SetActive(card != 1);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts
|
||||
namespace Assets.Scripts.Utilities
|
||||
{
|
||||
class Constant
|
||||
public class Constant
|
||||
{
|
||||
public const string SEPARATOR = "-";
|
||||
|
||||
|
||||
@ -1,14 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Utilities
|
||||
{
|
||||
class DataSaver
|
||||
public class DataSaver
|
||||
{
|
||||
public static void SaveTime()
|
||||
{
|
||||
@ -17,7 +13,7 @@ namespace Assets.Scripts.Utilities
|
||||
string time = PlayerPrefs.GetString(Constant.PPK_TIMER_TIME);
|
||||
string stage = PlayerPrefs.GetString(Constant.PPK_SCENE_NAME);
|
||||
string toSave = movementName + Constant.SEPARATOR + playerName + Constant.SEPARATOR + stage + Constant.SEPARATOR + time;
|
||||
writeToFile(toSave);
|
||||
WriteToFile(toSave);
|
||||
}
|
||||
|
||||
public static void SavePosition(List<Position> positions)
|
||||
@ -25,17 +21,17 @@ namespace Assets.Scripts.Utilities
|
||||
string playerName = PlayerPrefs.GetString(Constant.PPK_PLAYER_NAME);
|
||||
string movementName = ((MovementGen.ChoiceOfMovement)PlayerPrefs.GetInt(Constant.PPK_MOVEMENT_CHOICE)).ToString();
|
||||
string stage = PlayerPrefs.GetString(Constant.PPK_SCENE_NAME);
|
||||
string fileName = movementName + Constant.SEPARATOR + playerName + Constant.SEPARATOR + stage;
|
||||
writeToFile(positions, fileName);
|
||||
string fileName = "position" + Constant.SEPARATOR + movementName + Constant.SEPARATOR + playerName + Constant.SEPARATOR + stage;
|
||||
WriteToFile(positions, fileName);
|
||||
}
|
||||
|
||||
private static async void writeToFile(string toSave)
|
||||
private static async void WriteToFile(string toSave)
|
||||
{
|
||||
using StreamWriter file = File.AppendText(Constant.FILE_PATH + Constant.FILE_TIME + Constant.FILE_EXTENSION);
|
||||
await file.WriteLineAsync(toSave);
|
||||
}
|
||||
|
||||
private static async void writeToFile(List<Position> positions, string fileName)
|
||||
private static async void WriteToFile(List<Position> positions, string fileName)
|
||||
{
|
||||
using StreamWriter file = File.AppendText(Constant.FILE_PATH + fileName + Constant.FILE_EXTENSION);
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
namespace Assets.Scripts.Utilities
|
||||
{
|
||||
class Position
|
||||
public class Position
|
||||
{
|
||||
private float x { get; set; }
|
||||
private float y { get; set; }
|
||||
|
||||
@ -1,40 +1,42 @@
|
||||
using Assets.Scripts.Utilities;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PositionManager : MonoBehaviour
|
||||
namespace Assets.Scripts.Utilities
|
||||
{
|
||||
public GameObject player;
|
||||
private List<Position> data;
|
||||
public bool notSended = true;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
public class PositionManager : MonoBehaviour
|
||||
{
|
||||
data = new List<Position>();
|
||||
StartCoroutine("TackerExecute");
|
||||
}
|
||||
public GameObject player;
|
||||
private List<Position> data;
|
||||
public bool notSended = true;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
IEnumerator TackerExecute()
|
||||
{
|
||||
while (notSended)
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
data.Add(new Position(player.transform.position.x, player.transform.position.y));
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
data = new List<Position>();
|
||||
StartCoroutine("TackerExecute");
|
||||
}
|
||||
}
|
||||
public void sendData()
|
||||
{
|
||||
notSended = false;
|
||||
DataSaver.SavePosition(data);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
IEnumerator TackerExecute()
|
||||
{
|
||||
while (notSended)
|
||||
{
|
||||
data.Add(new Position(player.transform.position.x, player.transform.position.y));
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
}
|
||||
}
|
||||
public void sendData()
|
||||
{
|
||||
notSended = false;
|
||||
DataSaver.SavePosition(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,53 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Timer : MonoBehaviour
|
||||
namespace Assets.Scripts.Utilities
|
||||
{
|
||||
private float time { get; set; }
|
||||
private bool timerStop { get; set; }
|
||||
|
||||
// TODO JIMMY : Rename this
|
||||
[SerializeField]
|
||||
private TextMesh text;
|
||||
// TODO JIMMY : ^ Rename this
|
||||
|
||||
private Coroutine timerRoutine;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
public class Timer : MonoBehaviour
|
||||
{
|
||||
time = 0;
|
||||
timerRoutine = StartCoroutine("TimerExecute");
|
||||
}
|
||||
private float time { get; set; }
|
||||
private bool timerStop { get; set; }
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// TODO JIMMY : Rename this
|
||||
[SerializeField]
|
||||
private TextMesh text;
|
||||
// TODO JIMMY : ^ Rename this
|
||||
|
||||
}
|
||||
private Coroutine timerRoutine;
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
timerStop = true;
|
||||
PlayerPrefs.SetString(Constant.PPK_TIMER_TIME, text.text);
|
||||
StopCoroutine(timerRoutine);
|
||||
|
||||
}
|
||||
|
||||
IEnumerator TimerExecute()
|
||||
{
|
||||
while (true)
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
if (!timerStop)
|
||||
{
|
||||
time += 0.1f;
|
||||
if (text != null)
|
||||
text.text = ""+ (Mathf.Round(time * 10) * 0.1f).ToString("F1");
|
||||
yield return new WaitForSeconds(.1f);
|
||||
}
|
||||
time = 0;
|
||||
timerRoutine = StartCoroutine("TimerExecute");
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
timerStop = true;
|
||||
PlayerPrefs.SetString(Constant.PPK_TIMER_TIME, text.text);
|
||||
StopCoroutine(timerRoutine);
|
||||
|
||||
}
|
||||
|
||||
IEnumerator TimerExecute()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!timerStop)
|
||||
{
|
||||
time += 0.1f;
|
||||
if (text != null)
|
||||
text.text = ""+ (Mathf.Round(time * 10) * 0.1f).ToString("F1");
|
||||
yield return new WaitForSeconds(.1f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user