inject input prompt sprites into dialogue

This commit is contained in:
Cat Flynn 2021-03-11 20:25:09 +00:00
parent ca03ab9150
commit 7d5c493bcd
14 changed files with 812 additions and 53 deletions

View File

@ -12,6 +12,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a6a4c7f569d69ca4e8498fdcd96476ce, type: 3}
m_Name: Dialogue Settings
m_EditorClassIdentifier:
_gamepadInputPrompts:
blink: 0
boost: 1
timeFreeze: 2
_keyboardInputPrompts:
blink: 4
boost: 5
timeFreeze: 6
_hideAfter: 5
_radioDialogueKey: event:/VO/Radio Dialogue Line
_dialogueClips:

File diff suppressed because one or more lines are too long

View File

@ -186,7 +186,20 @@ MonoBehaviour:
m_Calls: []
m_ControlsChangedEvent:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 11400000, guid: 56369c4e83cc59e44bf55cd16fafc4e8, type: 2}
m_TargetAssemblyTypeName: DialogueSystem, Assembly-CSharp
m_MethodName: UpdateControlPrompts
m_Mode: 2
m_Arguments:
m_ObjectArgument: {fileID: 13726836969441780}
m_ObjectArgumentAssemblyTypeName: UnityEngine.InputSystem.PlayerInput,
Unity.InputSystem
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_ActionEvents:
- m_PersistentCalls:
m_Calls:
@ -268,7 +281,7 @@ MonoBehaviour:
m_CallState: 2
m_ActionId: 0eb55067-1328-4b0a-9494-b427befe049a
m_ActionName: CoreMap/New action
m_NeverAutoSwitchControlSchemes: 1
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme: Gamepad
m_DefaultActionMap: CoreMap
m_SplitScreenIndex: -1
@ -288,6 +301,7 @@ MonoBehaviour:
_nearbyArtefactID: {fileID: 11400000, guid: caba70196fbb1c549a934f7566f7a247, type: 2}
_inputSettings: {fileID: 11400000, guid: 09b165d6ce14f86459be7213da9688a7, type: 2}
_camera: {fileID: 0}
_dialogue: {fileID: 11400000, guid: 56369c4e83cc59e44bf55cd16fafc4e8, type: 2}
--- !u!114 &13726837176080779
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -84,7 +84,7 @@ MonoBehaviour:
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_spriteAsset: {fileID: 11400000, guid: 5942ceb29a684b547911383b7099a062, type: 2}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901

View File

@ -1,11 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
[CreateAssetMenu(menuName = "KernelPanic/Dialogue/Settings")]
public class DialogueSettings : ScriptableObject
{
[Serializable]
public struct InputPromptSpriteIndices
{
public int blink;
public int boost;
public int timeFreeze;
}
public InputPromptSpriteIndices GamepadInputPrompts => _gamepadInputPrompts;
[SerializeField] private InputPromptSpriteIndices _gamepadInputPrompts;
public InputPromptSpriteIndices KeyboardInputPrompts => _keyboardInputPrompts;
[SerializeField] private InputPromptSpriteIndices _keyboardInputPrompts;
public float HideAfter => _hideAfter;
[SerializeField] private float _hideAfter;

View File

@ -5,8 +5,11 @@ using System.Runtime.InteropServices;
using FMOD;
using FMOD.Studio;
using FMODUnity;
using Ktyl.Util;
using UnityEngine;
using UnityEngine.Animations.Rigging;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Users;
using UnityEngine.Networking;
using Debug = UnityEngine.Debug;
using STOP_MODE = FMOD.Studio.STOP_MODE;
@ -18,6 +21,9 @@ using UnityEditor;
[CreateAssetMenu(menuName = "KernelPanic/Dialogue/Dialogue System")]
public partial class DialogueSystem : ScriptableObject
{
private const string PCMR = "PCMR";
private const string GAMEPAD = "Gamepad";
[SerializeField] private DialogueSettings _settings;
// https://stackoverflow.com/questions/2282476/actiont-vs-delegate-event
@ -28,6 +34,7 @@ public partial class DialogueSystem : ScriptableObject
private EVENT_CALLBACK _dialogueCallback;
private EventInstance _currentInstance;
private string _currentControlScheme;
private void OnEnable()
{
@ -133,7 +140,10 @@ public partial class DialogueSystem : ScriptableObject
_currentInstance.setUserData(GCHandle.ToIntPtr(stringHandle));
DialogueLine dl;
dl.text = DialogueDatabase.ReadDialogue(key);
var line = DialogueDatabase.ReadDialogue(key);
// process templates in string
line = ProcessTemplates(line);
dl.text = line;
var clip = _settings.GetDialogueClip(key);
dl.duration = clip.length;
@ -143,6 +153,31 @@ public partial class DialogueSystem : ScriptableObject
onDialogueLine?.Invoke(this, dl);
}
private string ProcessTemplates(string text)
{
var spriteIndices = _currentControlScheme == GAMEPAD
? _settings.GamepadInputPrompts
: _settings.KeyboardInputPrompts;
text = text.Replace("[BLINK]", $"<sprite index={spriteIndices.blink}>");
text = text.Replace("[BOOST]", $"<sprite index={spriteIndices.boost}>");
text = text.Replace("[TIME_FREEZE]", $"<sprite index={spriteIndices.timeFreeze}>");
return text;
}
public void UpdateControlPrompts(PlayerInput playerInput)
{
var controlScheme = playerInput.currentControlScheme;
if (controlScheme != PCMR && controlScheme != GAMEPAD)
{
Debug.LogError($"could not set unknown control scheme {controlScheme}");
return;
}
_currentControlScheme = playerInput.currentControlScheme;
}
}
public struct DialogueLine

View File

@ -5,6 +5,7 @@ using UnityEngine;
using UnityEngine.InputSystem;
using Ktyl.Util;
[RequireComponent(typeof(PlayerInput))]
public class PlayerInputHandler : MonoBehaviour
{
//to get the artifact id you are near to
@ -16,6 +17,8 @@ public class PlayerInputHandler : MonoBehaviour
[SerializeField]
private Camera _camera;
[SerializeField] private DialogueSystem _dialogue;
public class PlayerInputState
{
public BufferedInput Jump;
@ -53,6 +56,10 @@ public class PlayerInputHandler : MonoBehaviour
_inputSettings.BlinkBufferTime,
_inputSettings.UseBufferTime
);
// run a first time update to ensure the dialogue system has an updated
// value for the player's input control scheme
_dialogue.UpdateControlPrompts(GetComponent<PlayerInput>());
}
private void FixedUpdate()

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 43d857810d1a7f945bcf677bbc0c8dfc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c059e6cb774d95e4cb11f781552c31e4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,205 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &-3506835878812899197
Material:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: TextMeshPro/Sprite
m_Shader: {fileID: 4800000, guid: cf81c85f95fe47e1a27f6ae460cf182c, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: 0611a1c41577fb94ca74d3bdf8b8a621, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _ColorMask: 15
- _CullMode: 0
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UseUIAlphaClip: 0
m_Colors:
- _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767}
- _Color: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: []
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 84a92b25f83d49b9bc132d206b370281, type: 3}
m_Name: input_prompts
m_EditorClassIdentifier:
hashCode: 948431038
material: {fileID: -3506835878812899197}
materialHashCode: 0
m_Version: 1.1.0
m_FaceInfo:
m_FamilyName:
m_StyleName:
m_PointSize: 0
m_Scale: 0
m_LineHeight: 0
m_AscentLine: 0
m_CapLine: 0
m_MeanLine: 0
m_Baseline: 0
m_DescentLine: 0
m_SuperscriptOffset: 0
m_SuperscriptSize: 0
m_SubscriptOffset: 0
m_SubscriptSize: 0
m_UnderlineOffset: 0
m_UnderlineThickness: 0
m_StrikethroughOffset: 0
m_StrikethroughThickness: 0
m_TabWidth: 0
spriteSheet: {fileID: 2800000, guid: 0611a1c41577fb94ca74d3bdf8b8a621, type: 3}
m_SpriteCharacterTable:
- m_ElementType: 2
m_Unicode: 65534
m_GlyphIndex: 0
m_Scale: 1
m_Name: input_prompts_0
m_HashCode: 2049246321
- m_ElementType: 2
m_Unicode: 65534
m_GlyphIndex: 1
m_Scale: 1
m_Name: input_prompts_1
m_HashCode: 2049246320
- m_ElementType: 2
m_Unicode: 65534
m_GlyphIndex: 2
m_Scale: 1
m_Name: input_prompts_2
m_HashCode: 2049246323
- m_ElementType: 2
m_Unicode: 65534
m_GlyphIndex: 3
m_Scale: 1
m_Name: input_prompts_3
m_HashCode: 2049246322
- m_ElementType: 2
m_Unicode: 65534
m_GlyphIndex: 4
m_Scale: 1
m_Name: input_prompts_4
m_HashCode: 2049246325
- m_ElementType: 2
m_Unicode: 65534
m_GlyphIndex: 5
m_Scale: 1
m_Name: input_prompts_5
m_HashCode: 2049246324
m_SpriteGlyphTable:
- m_Index: 0
m_Metrics:
m_Width: 128
m_Height: 128
m_HorizontalBearingX: -0
m_HorizontalBearingY: 92
m_HorizontalAdvance: 128
m_GlyphRect:
m_X: 0
m_Y: 128
m_Width: 128
m_Height: 128
m_Scale: 1.5
m_AtlasIndex: 0
sprite: {fileID: 7816068872284341956, guid: 0611a1c41577fb94ca74d3bdf8b8a621, type: 3}
- m_Index: 1
m_Metrics:
m_Width: 128
m_Height: 128
m_HorizontalBearingX: -0
m_HorizontalBearingY: 92
m_HorizontalAdvance: 128
m_GlyphRect:
m_X: 127
m_Y: 128
m_Width: 128
m_Height: 128
m_Scale: 1.5
m_AtlasIndex: 0
sprite: {fileID: 2864374711127359003, guid: 0611a1c41577fb94ca74d3bdf8b8a621, type: 3}
- m_Index: 2
m_Metrics:
m_Width: 128
m_Height: 128
m_HorizontalBearingX: -0
m_HorizontalBearingY: 92
m_HorizontalAdvance: 128
m_GlyphRect:
m_X: 256
m_Y: 128
m_Width: 128
m_Height: 128
m_Scale: 1.5
m_AtlasIndex: 0
sprite: {fileID: 268328667761342747, guid: 0611a1c41577fb94ca74d3bdf8b8a621, type: 3}
- m_Index: 3
m_Metrics:
m_Width: 128
m_Height: 128
m_HorizontalBearingX: -0
m_HorizontalBearingY: 92
m_HorizontalAdvance: 128
m_GlyphRect:
m_X: 0
m_Y: 3
m_Width: 128
m_Height: 128
m_Scale: 1.5
m_AtlasIndex: 0
sprite: {fileID: 5331073594579601401, guid: 0611a1c41577fb94ca74d3bdf8b8a621, type: 3}
- m_Index: 4
m_Metrics:
m_Width: 128
m_Height: 128
m_HorizontalBearingX: -0
m_HorizontalBearingY: 92
m_HorizontalAdvance: 128
m_GlyphRect:
m_X: 128
m_Y: 0
m_Width: 128
m_Height: 128
m_Scale: 1.5
m_AtlasIndex: 0
sprite: {fileID: 8039778415432188907, guid: 0611a1c41577fb94ca74d3bdf8b8a621, type: 3}
- m_Index: 5
m_Metrics:
m_Width: 128
m_Height: 128
m_HorizontalBearingX: -0
m_HorizontalBearingY: 92
m_HorizontalAdvance: 128
m_GlyphRect:
m_X: 256
m_Y: 0
m_Width: 128
m_Height: 128
m_Scale: 1.5
m_AtlasIndex: 0
sprite: {fileID: -1826817245344109917, guid: 0611a1c41577fb94ca74d3bdf8b8a621, type: 3}
spriteInfoList: []
fallbackSpriteAssets: []

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5942ceb29a684b547911383b7099a062
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

BIN
game/Assets/UI/Input Prompts/Sprites/input_prompts.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,336 @@
fileFormatVersion: 2
guid: 0611a1c41577fb94ca74d3bdf8b8a621
TextureImporter:
internalIDToNameTable:
- first:
213: 7816068872284341956
second: input_prompts_0
- first:
213: 2864374711127359003
second: input_prompts_1
- first:
213: 268328667761342747
second: input_prompts_2
- first:
213: 5331073594579601401
second: input_prompts_3
- first:
213: 8039778415432188907
second: input_prompts_4
- first:
213: -1826817245344109917
second: input_prompts_5
- first:
213: -8816819014231479301
second: input_prompts_6
- first:
213: -4420420969662096701
second: input_prompts_7
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: 2
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: iPhone
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Windows Store Apps
maxTextureSize: 8192
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites:
- serializedVersion: 2
name: input_prompts_0
rect:
serializedVersion: 2
x: 0
y: 128
width: 128
height: 128
alignment: 1
pivot: {x: 0, y: 1}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 4c60f706a31487c60800000000000000
internalID: 7816068872284341956
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: input_prompts_1
rect:
serializedVersion: 2
x: 128
y: 128
width: 128
height: 128
alignment: 1
pivot: {x: 0, y: 1}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: b1ebb58af9d40c720800000000000000
internalID: 2864374711127359003
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: input_prompts_2
rect:
serializedVersion: 2
x: 256
y: 128
width: 128
height: 128
alignment: 1
pivot: {x: 0, y: 1}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: b19f7fc608b49b300800000000000000
internalID: 268328667761342747
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: input_prompts_3
rect:
serializedVersion: 2
x: 384
y: 128
width: 128
height: 128
alignment: 1
pivot: {x: 0, y: 1}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 9f7c1646037cbf940800000000000000
internalID: 5331073594579601401
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: input_prompts_4
rect:
serializedVersion: 2
x: 0
y: 0
width: 128
height: 128
alignment: 1
pivot: {x: 0, y: 1}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: be340bc4fd7039f60800000000000000
internalID: 8039778415432188907
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: input_prompts_5
rect:
serializedVersion: 2
x: 128
y: 0
width: 128
height: 128
alignment: 1
pivot: {x: 0, y: 1}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 3aae4bde467d5a6e0800000000000000
internalID: -1826817245344109917
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: input_prompts_6
rect:
serializedVersion: 2
x: 256
y: 0
width: 128
height: 128
alignment: 1
pivot: {x: 0, y: 1}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: bfba2dfe1dd54a580800000000000000
internalID: -8816819014231479301
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: input_prompts_7
rect:
serializedVersion: 2
x: 384
y: 0
width: 128
height: 128
alignment: 1
pivot: {x: 0, y: 1}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 3ca5a996c8287a2c0800000000000000
internalID: -4420420969662096701
vertices: []
indices:
edges: []
weights: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 36bfc57a05107a74a9a3db8ea5ddbba6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: