Skip to content

Commit

Permalink
You can now skip dialogue, and also controller support and also fix s…
Browse files Browse the repository at this point in the history
…hooting
  • Loading branch information
FredTheNoob committed Mar 16, 2021
1 parent 1ba70f6 commit afb751d
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 126 deletions.
56 changes: 56 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"files.exclude":
{
"**/.DS_Store":true,
"**/.git":true,
"**/.gitignore":true,
"**/.gitmodules":true,
"**/*.booproj":true,
"**/*.pidb":true,
"**/*.suo":true,
"**/*.user":true,
"**/*.userprefs":true,
"**/*.unityproj":true,
"**/*.dll":true,
"**/*.exe":true,
"**/*.pdf":true,
"**/*.mid":true,
"**/*.midi":true,
"**/*.wav":true,
"**/*.gif":true,
"**/*.ico":true,
"**/*.jpg":true,
"**/*.jpeg":true,
"**/*.png":true,
"**/*.psd":true,
"**/*.tga":true,
"**/*.tif":true,
"**/*.tiff":true,
"**/*.3ds":true,
"**/*.3DS":true,
"**/*.fbx":true,
"**/*.FBX":true,
"**/*.lxo":true,
"**/*.LXO":true,
"**/*.ma":true,
"**/*.MA":true,
"**/*.obj":true,
"**/*.OBJ":true,
"**/*.asset":true,
"**/*.cubemap":true,
"**/*.flare":true,
"**/*.mat":true,
"**/*.meta":true,
"**/*.prefab":true,
"**/*.unity":true,
"build/":true,
"Build/":true,
"Library/":true,
"library/":true,
"obj/":true,
"Obj/":true,
"ProjectSettings/":true,
"temp/":true,
"Temp/":true
}
}
2 changes: 1 addition & 1 deletion Assets/Prefabs/Objects/Bullet.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a040e9002c48ded429daabbcfd29dc65, type: 3}
m_Name:
m_EditorClassIdentifier:
speed: 20
speed: 10
rb: {fileID: 3790830501145301816}
--- !u!50 &3790830501145301816
Rigidbody2D:
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scenes/Game World.unity
Original file line number Diff line number Diff line change
Expand Up @@ -62076,6 +62076,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6cc6661eaf796f04596dc4570d3c0077, type: 3}
m_Name:
m_EditorClassIdentifier:
typeDelay: 0.01
nameText: {fileID: 1739398908}
dialogueText: {fileID: 1323578051}
animator: {fileID: 1047787944}
Expand All @@ -62084,7 +62085,7 @@ MonoBehaviour:
dialogueOptionsButtonPrefab: {fileID: 1759206441773302835, guid: 5bcc9fad4b8f9c64997ada265b9e7478,
type: 3}
continueButton: {fileID: 1182101428}
isInDialogue: 0
isDialogueStarted: 0
--- !u!4 &366715259
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -62305,7 +62306,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 'Quest Name '
m_text: Quest Name
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scriptable Objects/Dialogue/JohnDillermand.asset
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ MonoBehaviour:
dialogueText: Hej det er john dillermand!
choices: []
- speakerName: Fred
dialogueText: "Hold din k\xE6ft din perverse stodder"
dialogueText: Dummy dialogue lmao. Did y'all notice this font is ugly as shit,
matter of fact it's arial
choices: []
- speakerName: Fred
dialogueText: Would you like to commit neckrope?
Expand Down
35 changes: 29 additions & 6 deletions Assets/Scripts/Dialogue/DialogueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using TMPro;

public class DialogueManager : MonoBehaviour {

public float typeDelay = 0.2f;
public TMP_Text nameText;
public TMP_Text dialogueText;

Expand All @@ -17,14 +17,17 @@ public class DialogueManager : MonoBehaviour {
public GameObject dialogueOptionsButtonPrefab;
public Button continueButton;

public bool isInDialogue = false;
public bool isDialogueStarted = false;

private Queue<string> sentences; // A queue containing a string of sentences to be dequeued
private Queue<string> speakers;
private Queue<DialogueChoice[]> choices;

private List<GameObject> spawnedButtons;

private string currSentence;
private DialogueChoice[] currChoiceArr;
private bool isTyping = false;
public static DialogueManager instance;

private void Awake()
Expand Down Expand Up @@ -52,7 +55,7 @@ void Start () {

public void StartDialogue (Dialogue dialogue)
{
isInDialogue = true;
isDialogueStarted = true;
animator.SetBool("IsOpen", true); // Animate the dialogue

nameText.text = dialogue.dialogueSegments[0].speakerName; // Set the speakerName to the first element in the dialogueElements array
Expand All @@ -73,17 +76,27 @@ public void StartDialogue (Dialogue dialogue)

public void DisplayNextSentence ()
{
if (isTyping)
{
StopAllCoroutines();
dialogueText.text = currSentence;
CheckForChoices(currChoiceArr);
isTyping = false;
return;
}

// If we have nothing else to say we end the dialogue
if (sentences.Count == 0)
{
isInDialogue = false;
isDialogueStarted = false;
EndDialogue();
return;
}

// We dequeue a choice, this is an array of the dialogueChoice object
DialogueChoice[] choiceArr = choices.Dequeue();

currChoiceArr = choiceArr;

// We dequeue the speaker and set it to the text
nameText.text = speakers.Dequeue();
// We also dequeue the sentence to display
Expand All @@ -94,16 +107,26 @@ public void DisplayNextSentence ()

IEnumerator TypeSentence (string sentence, DialogueChoice[] choiceArr)
{
isTyping = true;
currSentence = sentence;
// We set the dialogueText to an empty string
dialogueText.text = "";

// We then go through each individual letter in the sentence
foreach (char letter in sentence.ToCharArray())
{
dialogueText.text += letter; // Append the letter onto the string
yield return null; // Wait one frame
//yield return null; // Wait one frame
yield return new WaitForSeconds(typeDelay);
}
isTyping = false;

CheckForChoices(choiceArr);

}

private void CheckForChoices(DialogueChoice[] choiceArr)
{
// Go through each choice in the choiceArr
foreach (DialogueChoice choice in choiceArr)
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Dialogue/DialogueTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class DialogueTrigger : MonoBehaviour {

public void TriggerDialogue()
{
if (DialogueManager.instance.isInDialogue == false)
if (DialogueManager.instance.isDialogueStarted == false)
{
DialogueManager.instance.StartDialogue(QuestManager.instance.GetActive().dialogue[0]);
QuestManager.instance.CompleteActive();
Expand Down
93 changes: 39 additions & 54 deletions Assets/Scripts/InputMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public @InputMaster()
""processors"": """",
""interactions"": """"
},
{
""name"": ""ControllerShoot"",
""type"": ""Button"",
""id"": ""1c730fdf-87a8-44e9-bb31-8a0e5bf0e4d2"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Shoot"",
""type"": ""Button"",
Expand All @@ -44,7 +52,7 @@ public @InputMaster()
},
{
""name"": ""Aim"",
""type"": ""Value"",
""type"": ""PassThrough"",
""id"": ""c6fa2cd7-cf78-420a-95b0-52d5e44a1f37"",
""expectedControlType"": ""Vector2"",
""processors"": """",
Expand Down Expand Up @@ -108,59 +116,15 @@ public @InputMaster()
""isPartOfComposite"": true
},
{
""name"": ""Moving (Controller)"",
""id"": ""9e8ba210-5c41-4f44-b0b4-5d88ee2e2d20"",
""path"": ""2DVector"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Movement"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""e948ab91-3762-4da3-9e4e-41c5883984c5"",
""path"": ""<Gamepad>/leftStick/up"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Movement"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""131673e4-b008-4b3d-85ce-4d7deed7ed9c"",
""path"": ""<Gamepad>/leftStick/down"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Movement"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""260725c7-aeff-470a-a154-4cd2ebc04899"",
""path"": ""<Gamepad>/leftStick/left"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Movement"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""775a2c3e-d55a-43fa-94c2-42e02b3a8045"",
""path"": ""<Gamepad>/leftStick/right"",
""name"": """",
""id"": ""d209cbad-387e-4401-a82b-6667dd572b91"",
""path"": ""<Gamepad>/leftStick"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Movement"",
""isComposite"": false,
""isPartOfComposite"": true
""isPartOfComposite"": false
},
{
""name"": """",
Expand Down Expand Up @@ -197,25 +161,36 @@ public @InputMaster()
},
{
""name"": """",
""id"": ""aaec98ba-ed76-4cfc-9354-4226bead63f7"",
""path"": ""<Gamepad>/buttonEast"",
""id"": ""c1876bfe-834d-49c4-863b-fac6d6a635c9"",
""path"": ""<Mouse>/position"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Shoot"",
""action"": ""Aim"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""c1876bfe-834d-49c4-863b-fac6d6a635c9"",
""path"": ""<Mouse>/position"",
""id"": ""bbf8a245-b046-4226-8f72-229965e67d61"",
""path"": ""<Gamepad>/rightStick"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Aim"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""aaec98ba-ed76-4cfc-9354-4226bead63f7"",
""path"": ""<Gamepad>/rightShoulder"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""ControllerShoot"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
Expand All @@ -226,6 +201,7 @@ public @InputMaster()
m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
m_Player_Movement = m_Player.FindAction("Movement", throwIfNotFound: true);
m_Player_Interact = m_Player.FindAction("Interact", throwIfNotFound: true);
m_Player_ControllerShoot = m_Player.FindAction("ControllerShoot", throwIfNotFound: true);
m_Player_Shoot = m_Player.FindAction("Shoot", throwIfNotFound: true);
m_Player_Aim = m_Player.FindAction("Aim", throwIfNotFound: true);
}
Expand Down Expand Up @@ -279,6 +255,7 @@ public void Disable()
private IPlayerActions m_PlayerActionsCallbackInterface;
private readonly InputAction m_Player_Movement;
private readonly InputAction m_Player_Interact;
private readonly InputAction m_Player_ControllerShoot;
private readonly InputAction m_Player_Shoot;
private readonly InputAction m_Player_Aim;
public struct PlayerActions
Expand All @@ -287,6 +264,7 @@ public struct PlayerActions
public PlayerActions(@InputMaster wrapper) { m_Wrapper = wrapper; }
public InputAction @Movement => m_Wrapper.m_Player_Movement;
public InputAction @Interact => m_Wrapper.m_Player_Interact;
public InputAction @ControllerShoot => m_Wrapper.m_Player_ControllerShoot;
public InputAction @Shoot => m_Wrapper.m_Player_Shoot;
public InputAction @Aim => m_Wrapper.m_Player_Aim;
public InputActionMap Get() { return m_Wrapper.m_Player; }
Expand All @@ -304,6 +282,9 @@ public void SetCallbacks(IPlayerActions instance)
@Interact.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnInteract;
@Interact.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnInteract;
@Interact.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnInteract;
@ControllerShoot.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnControllerShoot;
@ControllerShoot.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnControllerShoot;
@ControllerShoot.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnControllerShoot;
@Shoot.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnShoot;
@Shoot.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnShoot;
@Shoot.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnShoot;
Expand All @@ -320,6 +301,9 @@ public void SetCallbacks(IPlayerActions instance)
@Interact.started += instance.OnInteract;
@Interact.performed += instance.OnInteract;
@Interact.canceled += instance.OnInteract;
@ControllerShoot.started += instance.OnControllerShoot;
@ControllerShoot.performed += instance.OnControllerShoot;
@ControllerShoot.canceled += instance.OnControllerShoot;
@Shoot.started += instance.OnShoot;
@Shoot.performed += instance.OnShoot;
@Shoot.canceled += instance.OnShoot;
Expand All @@ -334,6 +318,7 @@ public interface IPlayerActions
{
void OnMovement(InputAction.CallbackContext context);
void OnInteract(InputAction.CallbackContext context);
void OnControllerShoot(InputAction.CallbackContext context);
void OnShoot(InputAction.CallbackContext context);
void OnAim(InputAction.CallbackContext context);
}
Expand Down
Loading

0 comments on commit afb751d

Please sign in to comment.