platform-specific input prompt above nearby artefacts

This commit is contained in:
Cat Flynn 2021-03-12 18:29:36 +00:00
parent 3c4f28844f
commit b8a2e67a33
10 changed files with 114 additions and 212 deletions

View File

@ -12,7 +12,7 @@ GameObject:
- component: {fileID: 2205831332405259923} - component: {fileID: 2205831332405259923}
- component: {fileID: 8272008737841710381} - component: {fileID: 8272008737841710381}
m_Layer: 0 m_Layer: 0
m_Name: Cylinder m_Name: Graphics
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -30,7 +30,7 @@ Transform:
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5} m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_Children: [] m_Children: []
m_Father: {fileID: 8781564213167799764} m_Father: {fileID: 8781564213167799764}
m_RootOrder: 1 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &2205831332405259923 --- !u!33 &2205831332405259923
MeshFilter: MeshFilter:
@ -146,7 +146,7 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_text: press <sprite index=7> to interact m_text: '[INTERACT]'
m_isRightToLeft: 0 m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@ -173,15 +173,15 @@ MonoBehaviour:
m_faceColor: m_faceColor:
serializedVersion: 2 serializedVersion: 2
rgba: 4294967295 rgba: 4294967295
m_fontSize: 0.6 m_fontSize: 0.85
m_fontSizeBase: 36 m_fontSizeBase: 36
m_fontWeight: 400 m_fontWeight: 400
m_enableAutoSizing: 1 m_enableAutoSizing: 1
m_fontSizeMin: 0 m_fontSizeMin: 0
m_fontSizeMax: 72 m_fontSizeMax: 72
m_fontStyle: 0 m_fontStyle: 0
m_HorizontalAlignment: 1 m_HorizontalAlignment: 2
m_VerticalAlignment: 256 m_VerticalAlignment: 512
m_textAlignment: 65535 m_textAlignment: 65535
m_characterSpacing: 0 m_characterSpacing: 0
m_wordSpacing: 0 m_wordSpacing: 0
@ -228,6 +228,7 @@ GameObject:
- component: {fileID: 2620423025316115099} - component: {fileID: 2620423025316115099}
- component: {fileID: 7284579036519760679} - component: {fileID: 7284579036519760679}
- component: {fileID: 8457166438655354348} - component: {fileID: 8457166438655354348}
- component: {fileID: 5393817111832759879}
m_Layer: 0 m_Layer: 0
m_Name: Canvas m_Name: Canvas
m_TagString: Untagged m_TagString: Untagged
@ -248,7 +249,7 @@ RectTransform:
m_Children: m_Children:
- {fileID: 1483347660088856974} - {fileID: 1483347660088856974}
m_Father: {fileID: 8781564213167799764} m_Father: {fileID: 8781564213167799764}
m_RootOrder: 2 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
@ -328,6 +329,20 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f5353ef6941310847ada59b565108370, type: 3} m_Script: {fileID: 11500000, guid: f5353ef6941310847ada59b565108370, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!114 &5393817111832759879
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3398621272691566433}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b1c74c0921372b9439e9b80c4a537ccc, type: 3}
m_Name:
m_EditorClassIdentifier:
_text: {fileID: 2658148745440365952}
_settings: {fileID: 11400000, guid: 67880aab3a7f5124999fcef662a147f9, type: 2}
--- !u!1 &8781564213167799763 --- !u!1 &8781564213167799763
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -339,8 +354,8 @@ GameObject:
- component: {fileID: 8781564213167799764} - component: {fileID: 8781564213167799764}
- component: {fileID: 8781564213167799767} - component: {fileID: 8781564213167799767}
- component: {fileID: 8781564213167799766} - component: {fileID: 8781564213167799766}
- component: {fileID: 8781564213167799761}
- component: {fileID: 3201523991801391447} - component: {fileID: 3201523991801391447}
- component: {fileID: 8215073799250001962}
m_Layer: 0 m_Layer: 0
m_Name: Interactable Artefact m_Name: Interactable Artefact
m_TagString: Untagged m_TagString: Untagged
@ -359,7 +374,6 @@ Transform:
m_LocalPosition: {x: 0, y: 0.5, z: 0} m_LocalPosition: {x: 0, y: 0.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 8781564214893312960}
- {fileID: 2663749718261374877} - {fileID: 2663749718261374877}
- {fileID: 7585491580055765505} - {fileID: 7585491580055765505}
m_Father: {fileID: 0} m_Father: {fileID: 0}
@ -414,20 +428,6 @@ MeshRenderer:
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0} m_AdditionalVertexStreams: {fileID: 0}
--- !u!136 &8781564213167799761
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8781564213167799763}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 0
m_Radius: 0.5000001
m_Height: 2
m_Direction: 1
m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697}
--- !u!114 &3201523991801391447 --- !u!114 &3201523991801391447
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -443,114 +443,17 @@ MonoBehaviour:
_data: {fileID: 0} _data: {fileID: 0}
_nearbyArtefactID: {fileID: 11400000, guid: caba70196fbb1c549a934f7566f7a247, type: 2} _nearbyArtefactID: {fileID: 11400000, guid: caba70196fbb1c549a934f7566f7a247, type: 2}
_artefacts: {fileID: 11400000, guid: f523ac0d77530064b8b41c627b13fae0, type: 2} _artefacts: {fileID: 11400000, guid: f523ac0d77530064b8b41c627b13fae0, type: 2}
_text: {fileID: 2658148745440365952} _ui: {fileID: 5393817111832759879}
--- !u!1 &8781564214893312975 --- !u!135 &8215073799250001962
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8781564214893312960}
- component: {fileID: 8781564214893312963}
- component: {fileID: 8781564214893312962}
- component: {fileID: 8781564214893312973}
- component: {fileID: 8781564214893312972}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8781564214893312960
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8781564214893312975}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8781564213167799764}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &8781564214893312963
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8781564214893312975}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &8781564214893312962
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8781564214893312975}
m_Enabled: 0
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!135 &8781564214893312973
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8781564214893312975} m_GameObject: {fileID: 8781564213167799763}
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_IsTrigger: 1 m_IsTrigger: 1
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Radius: 4 m_Radius: 4
m_Center: {x: 0, y: 0, z: 0} m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &8781564214893312972
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8781564214893312975}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 44966bb2b773ce145a9d6c7c9f42aeba, type: 3}
m_Name:
m_EditorClassIdentifier:
_nearbyArtefactID: {fileID: 11400000, guid: caba70196fbb1c549a934f7566f7a247, type: 2}
_artefact: {fileID: 3201523991801391447}

View File

@ -1,18 +1,18 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using FMOD.Studio;
using Google.Apis.Http;
using UnityEngine; using UnityEngine;
using Ktyl.Util; using Ktyl.Util;
using TMPro; using TMPro;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.InputSystem;
public class ArtefactControl : MonoBehaviour public class ArtefactControl : MonoBehaviour
{ {
private bool _show;
protected bool _canInteract; protected bool _canInteract;
private GUIStyle guiS = new GUIStyle();
public Artefact data => _data; public Artefact data => _data;
[SerializeField] private Artefact _data; [SerializeField] private Artefact _data;
public int artefactID => _artefactID; public int artefactID => _artefactID;
@ -21,57 +21,49 @@ public class ArtefactControl : MonoBehaviour
[SerializeField] private ArtefactSystem _artefacts; [SerializeField] private ArtefactSystem _artefacts;
[SerializeField] private TMP_Text _text; [SerializeField] private ArtefactInteractUI _ui;
// TODO: template system
private void OnEnable() private void OnEnable()
{ {
_artefacts.RegisterArtefact(_data); _artefacts.RegisterArtefact(_data);
SetNearby(false);
}
private void SetNearby(bool playerNearby)
{
_canInteract = playerNearby;
_ui.gameObject.SetActive(playerNearby);
_nearbyArtefactID.Value = playerNearby ? artefactID : -1;
} }
protected virtual void Start() protected virtual void Start()
{ {
_artefactID = data.artefactID; _artefactID = data.artefactID;
_show = data.show;
_canInteract = data.canInteract; _canInteract = data.canInteract;
EventHandler.current.onArtefactTriggerEnter += NearArtefact;
EventHandler.current.onArtefactTriggerExit += AwayArtefact;
EventHandler.current.onArtefactPickUp += PickUp; EventHandler.current.onArtefactPickUp += PickUp;
guiS.fontSize = 22;
guiS.normal.textColor = Color.white;
guiS.alignment = TextAnchor.MiddleCenter;
} }
private void LateUpdate() private void OnTriggerEnter(Collider other)
{ {
_text.enabled = _show; if (!other.gameObject.TryGetComponent(out PlayerInput playerInput))
}
private void NearArtefact(int id)
{
if (id == this._artefactID)
{ {
_show = true; Debug.LogError("collided with not the player ????", this);
this._canInteract = true; return;
} }
SetNearby(true);
_ui.Input = playerInput;
} }
private void AwayArtefact(int id) private void OnTriggerExit(Collider other)
{ {
if (id == this._artefactID) SetNearby(false);
{
_show = false;
_canInteract = false;
}
} }
protected virtual void PickUp(int id) protected virtual void PickUp(int id)
{ {
if (id == this._artefactID) if (id == this._artefactID)
{ {
if (_canInteract == true) if (_canInteract == true)
@ -89,7 +81,6 @@ public class ArtefactControl : MonoBehaviour
EventHandler.current.ArtefactUI(); EventHandler.current.ArtefactUI();
Destroy(this.gameObject); Destroy(this.gameObject);
} }
} }
} }
} }

View File

@ -22,9 +22,6 @@ public class ArtefactPreview : MonoBehaviour
private bool Active => gameObject.activeSelf && ( _isPressed && !_useVelocity ); private bool Active => gameObject.activeSelf && ( _isPressed && !_useVelocity );
public const string PCMR = "PCMR";
public const string GAMEPAD = "Gamepad";
private void OnEnable() private void OnEnable()
{ {
ChangeInput( _playerInput ); ChangeInput( _playerInput );
@ -72,11 +69,11 @@ public class ArtefactPreview : MonoBehaviour
{ {
switch ( playerInput.currentControlScheme ) switch ( playerInput.currentControlScheme )
{ {
case PCMR: case InputSchemes.PCMR:
_useVelocity = false; _useVelocity = false;
break; break;
case GAMEPAD: case InputSchemes.GAMEPAD:
_useVelocity = true; _useVelocity = true;
break; break;

View File

@ -1,27 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Ktyl.Util;
public class ArtefactTriggerArea : MonoBehaviour
{
[SerializeField] private SerialInt _nearbyArtefactID;
[SerializeField] private ArtefactControl _artefact;
private int id => _artefact.artefactID;
private void OnTriggerEnter(Collider Player)
{
EventHandler.current.ArtefactTriggerEnter(id);
//PlayerInputHandler.id = _id;
_nearbyArtefactID.Value = id;
}
private void OnTriggerExit(Collider Player)
{
EventHandler.current.ArtefactTriggerExit(id);
//PlayerInputHandler.id = 0;
_nearbyArtefactID.Value = -1;
}
}

View File

@ -13,26 +13,6 @@ public class EventHandler : MonoBehaviour
current = this; current = this;
} }
public event Action<int> onArtefactTriggerEnter;
public void ArtefactTriggerEnter(int id)
{
if (onArtefactTriggerEnter != null)
{
onArtefactTriggerEnter(id);
}
}
public event Action<int> onArtefactTriggerExit;
public void ArtefactTriggerExit(int id)
{
if (onArtefactTriggerExit != null)
{
onArtefactTriggerExit(id);
}
}
public event Action<int> onArtefactPickUp; public event Action<int> onArtefactPickUp;
public void ArtefactPickUp(int id) public void ArtefactPickUp(int id)
{ {

View File

@ -21,9 +21,6 @@ using UnityEditor;
[CreateAssetMenu(menuName = "KernelPanic/Dialogue/Dialogue System")] [CreateAssetMenu(menuName = "KernelPanic/Dialogue/Dialogue System")]
public partial class DialogueSystem : ScriptableObject public partial class DialogueSystem : ScriptableObject
{ {
private const string PCMR = "PCMR";
private const string GAMEPAD = "Gamepad";
[SerializeField] private DialogueSettings _settings; [SerializeField] private DialogueSettings _settings;
// https://stackoverflow.com/questions/2282476/actiont-vs-delegate-event // https://stackoverflow.com/questions/2282476/actiont-vs-delegate-event
@ -156,7 +153,7 @@ public partial class DialogueSystem : ScriptableObject
private string ProcessTemplates(string text) private string ProcessTemplates(string text)
{ {
var spriteIndices = _currentControlScheme == GAMEPAD var spriteIndices = _currentControlScheme == InputSchemes.GAMEPAD
? _settings.GamepadInputPrompts ? _settings.GamepadInputPrompts
: _settings.KeyboardInputPrompts; : _settings.KeyboardInputPrompts;
@ -170,7 +167,7 @@ public partial class DialogueSystem : ScriptableObject
public void UpdateControlPrompts(PlayerInput playerInput) public void UpdateControlPrompts(PlayerInput playerInput)
{ {
var controlScheme = playerInput.currentControlScheme; var controlScheme = playerInput.currentControlScheme;
if (controlScheme != PCMR && controlScheme != GAMEPAD) if (controlScheme != InputSchemes.PCMR && controlScheme != InputSchemes.GAMEPAD)
{ {
Debug.LogError($"could not set unknown control scheme {controlScheme}"); Debug.LogError($"could not set unknown control scheme {controlScheme}");
return; return;

View File

@ -0,0 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public struct InputSchemes
{
public const string PCMR = "PCMR";
public const string GAMEPAD = "Gamepad";
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 44966bb2b773ce145a9d6c7c9f42aeba guid: e153d34772fac3b4a83e3112eb54847f
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -0,0 +1,41 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
public class ArtefactInteractUI : MonoBehaviour
{
[SerializeField] private TMP_Text _text;
[SerializeField] private DialogueSettings _settings;
private string _gamepadText;
private string _keyboardText;
public PlayerInput Input { get; set; }
void Awake()
{
_gamepadText = _text.text.Replace("[INTERACT]", $"<sprite index={_settings.GamepadInputPrompts.interact}>");
_keyboardText = _text.text.Replace("[INTERACT]", $"<sprite index={_settings.KeyboardInputPrompts.interact}>");
}
private void OnDisable()
{
Input = null;
}
private void LateUpdate()
{
switch (Input.currentControlScheme)
{
case InputSchemes.PCMR:
_text.text = _keyboardText;
break;
case InputSchemes.GAMEPAD:
_text.text = _gamepadText;
break;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1c74c0921372b9439e9b80c4a537ccc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: