Skip to content

Commit

Permalink
[CVRSuperMario64] Added Teleporters.
Browse files Browse the repository at this point in the history
  • Loading branch information
kafeijao committed Mar 13, 2023
1 parent d5e53d6 commit ee9cba4
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions CVRSuperMario64/CVRSM64Mario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class CVRSM64CMarioEditor : Editor {
{"HasVanishCap", AnimatorControllerParameterType.Bool},
{"IsMine", AnimatorControllerParameterType.Bool},
{"IsBypassed", AnimatorControllerParameterType.Bool},
{"IsTeleporting", AnimatorControllerParameterType.Bool},
};

SerializedProperty spawnable;
Expand Down
83 changes: 83 additions & 0 deletions CVRSuperMario64/CVRSM64Teleporter.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit ee9cba4

Please sign in to comment.