Created
December 10, 2022 15:04
-
-
Save RimuruDev/506e8d61a2deade36a74cf4be7177a20 to your computer and use it in GitHub Desktop.
Implementation of switching fields using enam.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using TMPro; | |
using UnityEngine; | |
public sealed class CoordinateTracker : MonoBehaviour | |
{ | |
public Coordinate coordinate = Coordinate.XYZ; | |
public GameObject targetGameObject; | |
public TextMeshProUGUI coordinateX; | |
public TextMeshProUGUI coordinateY; | |
public TextMeshProUGUI coordinateZ; | |
private void Awake() => EventContainer.OnCoordinateTracker += DisplayingObjectCoordinates; | |
private void DisplayingObjectCoordinates() | |
{ | |
switch (coordinate) | |
{ | |
case Coordinate.X: coordinateX.text = $"{(int)targetGameObject.transform.position.x}:X"; break; | |
case Coordinate.Y: coordinateY.text = $"{(int)targetGameObject.transform.position.y}:Y"; break; | |
case Coordinate.Z: coordinateZ.text = $"{(int)targetGameObject.transform.position.z}:Z"; break; | |
case Coordinate.XY: | |
coordinateX.text = $"{(int)targetGameObject.transform.position.x}:X"; | |
coordinateY.text = $"{(int)targetGameObject.transform.position.y}:Y"; | |
break; | |
case Coordinate.XZ: | |
coordinateX.text = $"{(int)targetGameObject.transform.position.x}:X"; | |
coordinateZ.text = $"{(int)targetGameObject.transform.position.z}:Z"; | |
break; | |
case Coordinate.YZ: | |
coordinateY.text = $"{(int)targetGameObject.transform.position.y}:Y"; | |
coordinateZ.text = $"{(int)targetGameObject.transform.position.z}:Z"; | |
break; | |
case Coordinate.XYZ: | |
coordinateX.text = $"{(int)targetGameObject.transform.position.x}:X"; | |
coordinateY.text = $"{(int)targetGameObject.transform.position.y}:Y"; | |
coordinateZ.text = $"{(int)targetGameObject.transform.position.z}:Z"; | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
[CanEditMultipleObjects] | |
[CustomEditor(typeof(CoordinateTracker))] | |
public sealed class CoordinateTrackerEditor : Editor | |
{ | |
private CoordinateTracker coordinateTracker; | |
private SerializedProperty targetGameObject; | |
private SerializedProperty coordinate; | |
private SerializedProperty coordinateX; | |
private SerializedProperty coordinateY; | |
private SerializedProperty coordinateZ; | |
private void OnEnable() | |
{ | |
coordinateTracker = target as CoordinateTracker; | |
{ | |
targetGameObject = serializedObject.FindProperty("targetGameObject"); | |
coordinate = serializedObject.FindProperty("coordinate"); | |
coordinateX = serializedObject.FindProperty("coordinateX"); | |
coordinateY = serializedObject.FindProperty("coordinateY"); | |
coordinateZ = serializedObject.FindProperty("coordinateZ"); | |
} | |
} | |
public override void OnInspectorGUI() | |
{ | |
serializedObject.Update(); | |
{ | |
EditorGUILayout.PropertyField(targetGameObject); | |
EditorGUILayout.Space(); | |
EditorGUILayout.PropertyField(coordinate); | |
{ | |
if (coordinateTracker.coordinate == Coordinate.X) | |
EditorGUILayout.PropertyField(coordinateX); | |
if (coordinateTracker.coordinate == Coordinate.Y) | |
EditorGUILayout.PropertyField(coordinateY); | |
if (coordinateTracker.coordinate == Coordinate.Z) | |
EditorGUILayout.PropertyField(coordinateZ); | |
if (coordinateTracker.coordinate == Coordinate.XY) | |
{ | |
EditorGUILayout.PropertyField(coordinateX); | |
EditorGUILayout.PropertyField(coordinateY); | |
} | |
if (coordinateTracker.coordinate == Coordinate.XZ) | |
{ | |
EditorGUILayout.PropertyField(coordinateX); | |
EditorGUILayout.PropertyField(coordinateZ); | |
} | |
if (coordinateTracker.coordinate == Coordinate.YZ) | |
{ | |
EditorGUILayout.PropertyField(coordinateY); | |
EditorGUILayout.PropertyField(coordinateZ); | |
} | |
if (coordinateTracker.coordinate == Coordinate.XYZ) | |
{ | |
EditorGUILayout.PropertyField(coordinateX); | |
EditorGUILayout.PropertyField(coordinateY); | |
EditorGUILayout.PropertyField(coordinateZ); | |
} | |
} | |
} | |
serializedObject.ApplyModifiedProperties(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment