From ee9cba43896286bb97c20bf53e353a460a96e0c7 Mon Sep 17 00:00:00 2001 From: kafeijao Date: Mon, 13 Mar 2023 19:50:28 +0000 Subject: [PATCH] [CVRSuperMario64] Added Teleporters. --- CVRSuperMario64/CVRSM64Mario.cs | 1 + CVRSuperMario64/CVRSM64Teleporter.cs | 83 ++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 CVRSuperMario64/CVRSM64Teleporter.cs diff --git a/CVRSuperMario64/CVRSM64Mario.cs b/CVRSuperMario64/CVRSM64Mario.cs index 5c9fbaf..23396b0 100644 --- a/CVRSuperMario64/CVRSM64Mario.cs +++ b/CVRSuperMario64/CVRSM64Mario.cs @@ -86,6 +86,7 @@ public class CVRSM64CMarioEditor : Editor { {"HasVanishCap", AnimatorControllerParameterType.Bool}, {"IsMine", AnimatorControllerParameterType.Bool}, {"IsBypassed", AnimatorControllerParameterType.Bool}, + {"IsTeleporting", AnimatorControllerParameterType.Bool}, }; SerializedProperty spawnable; diff --git a/CVRSuperMario64/CVRSM64Teleporter.cs b/CVRSuperMario64/CVRSM64Teleporter.cs new file mode 100644 index 0000000..9461905 --- /dev/null +++ b/CVRSuperMario64/CVRSM64Teleporter.cs @@ -0,0 +1,83 @@ +using UnityEditor; +using UnityEngine; + +namespace Kafe.CVRSuperMario64; + +public class CVRSM64Teleporter : MonoBehaviour { + [Tooltip("Determines whether the teleporter is currently active or not, you can animate this value.")] + [SerializeField] internal bool isActive = true; + + [Tooltip("Determines whether the teleporter can be used in both directions, you can animate this value.")] + [SerializeField] internal bool isTwoWays = false; + + [Tooltip("The transform of the object where the teleporter is located.")] + [SerializeField] internal Transform sourcePoint = null; + + [Tooltip("The transform of the object where the player will be teleported.")] + [SerializeField] internal Transform targetPoint = null; +} + +[CanEditMultipleObjects] +[CustomEditor(typeof(CVRSM64Teleporter))] +public class CVRSM64TeleporterEditor : Editor { + + SerializedProperty isActive; + SerializedProperty isTwoWays; + SerializedProperty sourcePoint; + SerializedProperty targetPoint; + + private void OnEnable() { + isActive = serializedObject.FindProperty("isActive"); + isTwoWays = serializedObject.FindProperty("isTwoWays"); + sourcePoint = serializedObject.FindProperty("sourcePoint"); + targetPoint = serializedObject.FindProperty("targetPoint"); + } + + public override void OnInspectorGUI() { + + serializedObject.Update(); + EditorGUILayout.PropertyField(isActive); + EditorGUILayout.Space(); + + EditorGUILayout.PropertyField(sourcePoint); + EditorGUILayout.PropertyField(targetPoint); + + EditorGUILayout.Space(); + EditorGUILayout.PropertyField(isTwoWays); + serializedObject.ApplyModifiedProperties(); + + var behavior = (CVRSM64Teleporter) target; + + if (behavior.sourcePoint == null) { + var err = $"The {nameof(CVRSM64Teleporter)} component requires a valid GameObject as the Source Point!"; + EditorGUILayout.HelpBox(err, MessageType.Error); + if (Application.isPlaying) throw new Exception(err); + return; + } + + if (behavior.targetPoint == null) { + var err = $"The {nameof(CVRSM64Teleporter)} component requires a valid GameObject as the Target Point!"; + EditorGUILayout.HelpBox(err, MessageType.Error); + if (Application.isPlaying) throw new Exception(err); + return; + } + + EditorGUILayout.HelpBox( + $"You CAN animate isActive via animation to enable/disable the teleporter. Disabling/Enabling the " + + $"game object should also work!", + MessageType.Info); + + EditorGUILayout.HelpBox( + $"The target/source rotation also matter, if the pivot is set to Local in the unity view, the blue " + + $"arrow represent where mario will be facing when teleports!", + MessageType.Info); + + if (behavior.isTwoWays) { + EditorGUILayout.HelpBox( + $"Since Is Two Ways is enabled, this teleporter will work (as the name suggests) two ways! " + + $"Teleporting from the source to target (when standing on the source) and from the target to the " + + $"source (when standing on the target).", + MessageType.Info); + } + } +}