From 4b6d4fda91c999d5b48fcc090d282f94b9a1b15d Mon Sep 17 00:00:00 2001 From: Davcris911 Date: Sun, 17 Oct 2021 18:38:35 -0400 Subject: [PATCH] Modification to Movement Scripts : added interface and made Teleportation work. See BugList.txt for the list of bugs that I found. --- Assets/Scripts/JoyCon/JoyConMovement.cs | 9 ++- Assets/Scripts/MovementGen.cs | 12 +++ Assets/Scripts/Movements/IScriptDeMovement.cs | 7 ++ .../Movements/IScriptDeMovement.cs.meta | 11 +++ Assets/Scripts/Movements/JoystickMovement.cs | 9 ++- Assets/Scripts/Movements/OmniMovement.cs | 8 +- Assets/Scripts/Movements/TeleportMovement.cs | 75 +++++++++++++++++-- Assets/Scripts/Movements/WasdMovement.cs | 13 +++- BugList.txt | 1 + 9 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 Assets/Scripts/Movements/IScriptDeMovement.cs create mode 100644 Assets/Scripts/Movements/IScriptDeMovement.cs.meta create mode 100644 BugList.txt diff --git a/Assets/Scripts/JoyCon/JoyConMovement.cs b/Assets/Scripts/JoyCon/JoyConMovement.cs index cabfa6f..f816f4b 100644 --- a/Assets/Scripts/JoyCon/JoyConMovement.cs +++ b/Assets/Scripts/JoyCon/JoyConMovement.cs @@ -1,10 +1,11 @@ -using UnityEngine; +using Assets.Scripts.Movements; +using UnityEngine; namespace JoyCon { // Blame Jimmy - public class JoyConMovement : JoyConBehaviour + public class JoyConMovement : JoyConBehaviour, IScriptDeMovement { [Header("References")] [SerializeField] private Rigidbody body; @@ -50,5 +51,9 @@ namespace JoyCon } public bool IsWalking() => Mathf.Abs(_gyroMagnitude.Total) > 1; + public void BeforeDisable() + { + // TODO throw new System.NotImplementedException(); + } } } diff --git a/Assets/Scripts/MovementGen.cs b/Assets/Scripts/MovementGen.cs index 45637a7..2162ea3 100644 --- a/Assets/Scripts/MovementGen.cs +++ b/Assets/Scripts/MovementGen.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using Assets.Scripts.Movements; using UnityEngine; public class MovementGen : MonoBehaviour @@ -30,12 +31,23 @@ public class MovementGen : MonoBehaviour { if(selectedMovement != currentMovement) { + if (components[currentMovement] is IScriptDeMovement) + { + + ((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, diff --git a/Assets/Scripts/Movements/IScriptDeMovement.cs b/Assets/Scripts/Movements/IScriptDeMovement.cs new file mode 100644 index 0000000..00ac64d --- /dev/null +++ b/Assets/Scripts/Movements/IScriptDeMovement.cs @@ -0,0 +1,7 @@ +namespace Assets.Scripts.Movements +{ + public interface IScriptDeMovement + { + public void BeforeDisable(); + } +} diff --git a/Assets/Scripts/Movements/IScriptDeMovement.cs.meta b/Assets/Scripts/Movements/IScriptDeMovement.cs.meta new file mode 100644 index 0000000..4b37637 --- /dev/null +++ b/Assets/Scripts/Movements/IScriptDeMovement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 381f097ec95f20743a0287e68f70a011 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Movements/JoystickMovement.cs b/Assets/Scripts/Movements/JoystickMovement.cs index 601c530..f7721e2 100644 --- a/Assets/Scripts/Movements/JoystickMovement.cs +++ b/Assets/Scripts/Movements/JoystickMovement.cs @@ -1,8 +1,10 @@ using System.Collections; using System.Collections.Generic; +using Assets.Scripts.Movements; using UnityEngine; -public class JoystickMovement : MonoBehaviour +// Useless, voir WASD movement +public class JoystickMovement : MonoBehaviour, IScriptDeMovement { [Header("References")] [SerializeField] private Rigidbody body; @@ -18,4 +20,9 @@ public class JoystickMovement : MonoBehaviour { } + + public void BeforeDisable() + { + // TODO throw new System.NotImplementedException(); + } } diff --git a/Assets/Scripts/Movements/OmniMovement.cs b/Assets/Scripts/Movements/OmniMovement.cs index 7150f7b..e9a1ab6 100644 --- a/Assets/Scripts/Movements/OmniMovement.cs +++ b/Assets/Scripts/Movements/OmniMovement.cs @@ -1,8 +1,9 @@ using System.Collections; using System.Collections.Generic; +using Assets.Scripts.Movements; using UnityEngine; -public class OmniMovement : MonoBehaviour +public class OmniMovement : MonoBehaviour, IScriptDeMovement { [Header("References")] [SerializeField] private Rigidbody body; @@ -18,4 +19,9 @@ public class OmniMovement : MonoBehaviour { } + + public void BeforeDisable() + { + //TODO throw new System.NotImplementedException(); + } } diff --git a/Assets/Scripts/Movements/TeleportMovement.cs b/Assets/Scripts/Movements/TeleportMovement.cs index 1187ab2..1a109c6 100644 --- a/Assets/Scripts/Movements/TeleportMovement.cs +++ b/Assets/Scripts/Movements/TeleportMovement.cs @@ -1,21 +1,86 @@ -using System.Collections; using System.Collections.Generic; +using System.Linq; +using Assets.Scripts.Movements; using UnityEngine; -public class TeleportMovement : MonoBehaviour +public class TeleportMovement : MonoBehaviour, IScriptDeMovement { [Header("References")] [SerializeField] private Rigidbody body; + private bool flag = true; + private List scriptsList; + // Start is called before the first frame update void Start() { - + flag = true; + scriptsList = new List(); + GameObject teleportScript = GameObject.FindGameObjectsWithTag("TeleportationScriptsList").FirstOrDefault(); + if (teleportScript != null) + { + scriptsList.Add(teleportScript.GetComponent()); + scriptsList.Add(teleportScript.GetComponent()); + scriptsList.Add(teleportScript.GetComponent()); + scriptsList.Add(teleportScript.GetComponent()); + scriptsList.Add(teleportScript.GetComponent()); + scriptsList.Add(teleportScript.GetComponent()); + scriptsList.Add(teleportScript.GetComponent()); + scriptsList.Add(teleportScript.GetComponent()); + } + else + { + Debug.Log("Sheeeet, Cant find!"); + } } // Update is called once per frame void Update() { - + } -} + + void FixedUpdate() + { + if (scriptsList.Count == 0) + { + Debug.Log("SHEEEET"); + } + + if (flag) + { + foreach (var script in scriptsList) + { + script.enabled = true; + } + + flag = false; + } + + //changer à false si on désactive le script + } + + public void BeforeDisable() + { + if (scriptsList.Count != 0) + { + foreach (var script in scriptsList) + { + script.enabled = false; + } + } + + flag = true; + } + + /* + public Transform teleportTarget; + //public GameObject thePlayer; + + void OnTriggerEnter(Collider other) + { + transform.position = teleportTarget.transform.position; + //thePlayer.transform.position = teleportTarget.transform.position; + } + */ +} \ No newline at end of file diff --git a/Assets/Scripts/Movements/WasdMovement.cs b/Assets/Scripts/Movements/WasdMovement.cs index 0aa1c46..5fa2837 100644 --- a/Assets/Scripts/Movements/WasdMovement.cs +++ b/Assets/Scripts/Movements/WasdMovement.cs @@ -1,9 +1,15 @@ using System.Collections; using System.Collections.Generic; +using Assets.Scripts.Movements; using UnityEngine; -public class WasdMovement : MonoBehaviour +public class WasdMovement : MonoBehaviour, IScriptDeMovement { + /* + Si version non-vr, utilise WASD. + Si utilise la version VR, utilise les joysticks + */ + [Header("References")] [SerializeField] private Rigidbody body; @@ -26,4 +32,9 @@ public class WasdMovement : MonoBehaviour transform.Rotate(0.0f, moveHorizontal * constSpeed * 2, 0.0f); transform.Translate(0, 0, moveVertical * constSpeed / 20); } + + public void BeforeDisable() + { + //TODO throw new System.NotImplementedException(); + } } diff --git a/BugList.txt b/BugList.txt new file mode 100644 index 0000000..2944f50 --- /dev/null +++ b/BugList.txt @@ -0,0 +1 @@ +Bug WASDmovement avec controllers : quand tourne + avance au max, Character est propulser \ No newline at end of file