diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index bae8166..95d3e7e 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -1,9 +1,10 @@ using UnityEngine; +using UnityEngine.InputSystem; public class GameManager : MonoBehaviour { - private ConjureCreativeJam20 _controls; - private GameState _state; + [SerializeField] private PlayerInput _controls; + [SerializeField, ReadOnly] private GameState _state; public static GameManager Instance { get; private set; } @@ -16,7 +17,6 @@ public class GameManager : MonoBehaviour else { Instance = this; - _controls = new ConjureCreativeJam20(); _state = GameState.InGame; } } @@ -26,8 +26,7 @@ public class GameManager : MonoBehaviour if (_state == GameState.Loss) return; // Stop controls - _controls.Player.Disable(); - _controls.UI.Enable(); + _controls.SwitchCurrentActionMap("UI"); // Show Game Over Message Debug.Log("Game Over: Dimension " + dimensionID + " has been destroyed"); diff --git a/Assets/Scripts/ShowOnlyAttribute.cs b/Assets/Scripts/ShowOnlyAttribute.cs new file mode 100644 index 0000000..f8caf74 --- /dev/null +++ b/Assets/Scripts/ShowOnlyAttribute.cs @@ -0,0 +1,151 @@ +using System; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +// Source: https://answers.unity.com/questions/489942/how-to-make-a-readonly-property-in-inspector.html + +/// +/// Display a field with disabled read-only controls in the inspector. +/// Works with CustomPropertyDrawers. +/// +/// +/// +/// +public class ShowOnlyAttribute : PropertyAttribute { } + +/// +/// Display a field as a custom read-only text in the inspector. +/// CustomPropertyDrawers will not work when this attribute is used. +/// +/// +/// +/// +public class ReadOnlyAttribute : PropertyAttribute { } + +/// +/// Display one or more fields as read-only in the inspector. +/// Use to close the group. +/// Works with CustomPropertyDrawers. +/// +/// +/// +public class BeginShowOnlyGroupAttribute : PropertyAttribute { } + +/// +/// Use with . +/// Close the read-only group and resume editable fields. +/// +/// +/// +public class EndShowOnlyGroupAttribute : PropertyAttribute { } + +// Custom Drawers declarations must be in a if Unity Editor assembly condition to allow a project to compile +#if UNITY_EDITOR + [CustomPropertyDrawer(typeof(ShowOnlyAttribute))] + public class ShowOnlyDrawer : PropertyDrawer + { + public override float GetPropertyHeight( SerializedProperty property, GUIContent label ) { + return EditorGUI.GetPropertyHeight( property, label, true ); + } + + public override void OnGUI( Rect position, SerializedProperty prop, GUIContent label ) + { + var currentGuiState = GUI.enabled; + GUI.enabled = false; + EditorGUI.PropertyField(position, prop, label, true); + GUI.enabled = currentGuiState; + } + } + + [CustomPropertyDrawer( typeof( ReadOnlyAttribute ) )] + public class ReadOnlyDrawer : PropertyDrawer { + + public override float GetPropertyHeight( SerializedProperty property, GUIContent label ) { + return EditorGUI.GetPropertyHeight( property, label, true ); + } + + public override void OnGUI( Rect position, SerializedProperty prop, GUIContent label ) + { + EditorGUI.LabelField(position, label.text,PropToString(prop)); + } + + private string PropToString(SerializedProperty prop) + { + string valueStr; + + switch (prop.propertyType) + { + case SerializedPropertyType.Generic: + valueStr = "Array"; + break; + case SerializedPropertyType.Integer: + valueStr = prop.intValue.ToString(); + break; + case SerializedPropertyType.Boolean: + valueStr = prop.boolValue.ToString(); + break; + case SerializedPropertyType.Float: + valueStr = prop.floatValue.ToString("0.00000"); + break; + case SerializedPropertyType.String: + valueStr = prop.stringValue; + break; + case SerializedPropertyType.Enum: + valueStr = prop.enumDisplayNames[prop.enumValueIndex]; + break; + case SerializedPropertyType.ObjectReference: + try { + valueStr = prop.objectReferenceValue.ToString(); + } catch (NullReferenceException) { + valueStr = "Object ToString not defined"; + } + break; + case SerializedPropertyType.Vector4: + valueStr = prop.vector4Value.ToString(); + break; + case SerializedPropertyType.Vector3: + valueStr = prop.vector3Value.ToString(); + break; + case SerializedPropertyType.Vector2: + valueStr = prop.vector2Value.ToString(); + break; + case SerializedPropertyType.Vector2Int: + valueStr = prop.vector2IntValue.ToString(); + break; + case SerializedPropertyType.Vector3Int: + valueStr = prop.vector3IntValue.ToString(); + break; + default: + valueStr = "( " + prop.type + " isn't supported )"; + break; + } + + return valueStr; + } + } + + [CustomPropertyDrawer( typeof( BeginShowOnlyGroupAttribute ) )] + public class BeginShowOnlyGroupDrawer : DecoratorDrawer { + + public override float GetHeight() { return 0; } + + public override void OnGUI( Rect position ) + { + GUI.enabled = false; + } + + } + + [CustomPropertyDrawer( typeof( EndShowOnlyGroupAttribute ) )] + public class EndShowOnlyGroupDrawer : DecoratorDrawer { + + public override float GetHeight() { return 0; } + + public override void OnGUI( Rect position ) + { + GUI.enabled = true; + } + } +#endif \ No newline at end of file diff --git a/Assets/Scripts/ShowOnlyAttribute.cs.meta b/Assets/Scripts/ShowOnlyAttribute.cs.meta new file mode 100644 index 0000000..ac53c62 --- /dev/null +++ b/Assets/Scripts/ShowOnlyAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9ceea82f853bfa8469552ca95eceae9a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: