Disabling controls works
This commit is contained in:
parent
09c6fc05d9
commit
9992e0955c
@ -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");
|
||||
|
||||
151
Assets/Scripts/ShowOnlyAttribute.cs
Normal file
151
Assets/Scripts/ShowOnlyAttribute.cs
Normal file
@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Display a field with disabled read-only controls in the inspector.
|
||||
/// Works with CustomPropertyDrawers.
|
||||
/// </summary>
|
||||
/// <seealso cref="ReadOnlyAttribute"/>
|
||||
/// <seealso cref="BeginShowOnlyGroupAttribute"/>
|
||||
/// <seealso cref="EndShowOnlyGroupAttribute"/>
|
||||
public class ShowOnlyAttribute : PropertyAttribute { }
|
||||
|
||||
/// <summary>
|
||||
/// Display a field as a custom read-only text in the inspector.
|
||||
/// CustomPropertyDrawers will not work when this attribute is used.
|
||||
/// </summary>
|
||||
/// <seealso cref="ShowOnlyAttribute"/>
|
||||
/// <seealso cref="BeginShowOnlyGroupAttribute"/>
|
||||
/// <seealso cref="EndShowOnlyGroupAttribute"/>
|
||||
public class ReadOnlyAttribute : PropertyAttribute { }
|
||||
|
||||
/// <summary>
|
||||
/// Display one or more fields as read-only in the inspector.
|
||||
/// Use <see cref="EndShowOnlyGroupAttribute"/> to close the group.
|
||||
/// Works with CustomPropertyDrawers.
|
||||
/// </summary>
|
||||
/// <seealso cref="EndShowOnlyGroupAttribute"/>
|
||||
/// <seealso cref="ShowOnlyAttribute"/>
|
||||
public class BeginShowOnlyGroupAttribute : PropertyAttribute { }
|
||||
|
||||
/// <summary>
|
||||
/// Use with <see cref="BeginShowOnlyGroupAttribute"/>.
|
||||
/// Close the read-only group and resume editable fields.
|
||||
/// </summary>
|
||||
/// <seealso cref="BeginShowOnlyGroupAttribute"/>
|
||||
/// <seealso cref="ShowOnlyAttribute"/>
|
||||
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
|
||||
11
Assets/Scripts/ShowOnlyAttribute.cs.meta
Normal file
11
Assets/Scripts/ShowOnlyAttribute.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ceea82f853bfa8469552ca95eceae9a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user