Commit 6bc8a02f authored by mmaluschnig's avatar mmaluschnig
Browse files

added framework that allows characters to produce dialogue from their...

added framework that allows characters to produce dialogue from their individual character script and display this dialogue at certain events e.g player in proximity or interacting.
parent c8417c7b
......@@ -118,6 +118,25 @@ Transform:
m_CorrespondingSourceObject: {fileID: 4118635779259584, guid: 36e15d0d933814ddd8f60f70726d5cdd,
type: 2}
m_PrefabInternal: {fileID: 1404345547}
--- !u!1 &195089826 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1201578362876714, guid: 2c7917ac87eca42679b31ab33e2eec29,
type: 2}
m_PrefabInternal: {fileID: 1345390424}
--- !u!114 &195089831
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 195089826}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2b6520c4e0b254f33b7f838739288d21, type: 3}
m_Name:
m_EditorClassIdentifier:
interactButton: {fileID: 827663221}
speechBox: {fileID: 1499010756}
secondarySpeechBox: {fileID: 555095869}
--- !u!1 &221139806
GameObject:
m_ObjectHideFlags: 0
......@@ -416,6 +435,81 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &555095867
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 555095868}
- component: {fileID: 555095870}
- component: {fileID: 555095869}
m_Layer: 5
m_Name: SecondarySpeech
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &555095868
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 555095867}
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: 2134632993}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 52}
m_SizeDelta: {x: 300, y: 200}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &555095869
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 555095867}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 30
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 3
m_MaxSize: 61
m_Alignment: 7
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: My beard sense is tingling
--- !u!222 &555095870
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 555095867}
m_CullTransparentMesh: 0
--- !u!1 &601223109
GameObject:
m_ObjectHideFlags: 0
......@@ -613,6 +707,12 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &827663221 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 114816900526660398, guid: 2c7917ac87eca42679b31ab33e2eec29,
type: 2}
m_PrefabInternal: {fileID: 1345390424}
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3}
--- !u!1 &1193059960
GameObject:
m_ObjectHideFlags: 0
......@@ -802,6 +902,14 @@ Prefab:
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1297585788650952, guid: 2c7917ac87eca42679b31ab33e2eec29, type: 2}
propertyPath: m_Name
value: BeardedLadyImage
objectReference: {fileID: 0}
- target: {fileID: 1142052670255770, guid: 2c7917ac87eca42679b31ab33e2eec29, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2c7917ac87eca42679b31ab33e2eec29, type: 2}
m_IsPrefabAsset: 0
......@@ -852,6 +960,81 @@ Transform:
m_CorrespondingSourceObject: {fileID: 4549546449924174, guid: 9e7fbf1a7c7a84dbc9e793c25c9e722a,
type: 2}
m_PrefabInternal: {fileID: 251658272}
--- !u!1 &1499010754
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1499010755}
- component: {fileID: 1499010757}
- component: {fileID: 1499010756}
m_Layer: 5
m_Name: PrimarySpeech
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &1499010755
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1499010754}
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: 2134632993}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 5}
m_SizeDelta: {x: 300, y: 300}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1499010756
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1499010754}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.01886791, g: 0.01886791, b: 0.01886791, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 30
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 7
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Didnt want to admire my glorious beard?
--- !u!222 &1499010757
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1499010754}
m_CullTransparentMesh: 0
--- !u!1 &1554845410
GameObject:
m_ObjectHideFlags: 0
......@@ -1190,3 +1373,8 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!224 &2134632993 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 224304718089781694, guid: 2c7917ac87eca42679b31ab33e2eec29,
type: 2}
m_PrefabInternal: {fileID: 1345390424}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AhavaScript : MonoBehaviour {
public Button interactButton;
private bool interactable;
private CharacterMovement moveScript;
// Use this for initialization
void Start () {
moveScript = GetComponent<CharacterMovement>();
interactButton.gameObject.SetActive(false);
}
// Update is called once per frame
void Update () {
checkInteractable();
//do things while the player is in range of the character
if(interactable){
if(Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)){
print("Hello Player, I am Ahava");
}
}
}
void checkInteractable(){
if (!moveScript.wandering)
{
interactable = true;
interactButton.gameObject.SetActive(true);
}
else
{
interactable = false;
interactButton.gameObject.SetActive(false);
}
public class AhavaScript : MonoBehaviour, Character {
public string GreetingMessage(){
return "Hello Player, I am Ahava";
}
public string GoodbyeMessage(){
return "See you soon!";
}
public string ProximityMessage(){
return "My beard sense is tingling...";
}
public string butthurtGoodbye(){
return "Didnt want to admire my glorious beard?";
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public interface Character {
string GreetingMessage();
string GoodbyeMessage();
string butthurtGoodbye();
string ProximityMessage();
}
fileFormatVersion: 2
guid: 7332230770cb4416ca0e92716fdb02f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CharacterInteractions : MonoBehaviour {
public Button interactButton;
public Text speechBox;
public Text secondarySpeechBox;
public Character characterScript;
private bool interactable;
private bool interacting;
private float proximityTimer;
private float speechBoxTimer;
private CharacterMovement moveScript;
// Use this for initialization
void Start()
{
moveScript = GetComponent<CharacterMovement>();
interactButton.gameObject.SetActive(false);
speechBox.gameObject.SetActive(false);
secondarySpeechBox.gameObject.SetActive(false);
characterScript = GetComponent<Character>();
}
// Update is called once per frame
void Update()
{
//do things while the player is in range of the character
if (interactable)
{
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow))
{
interacting = true;
setText(speechBox, characterScript.GreetingMessage());
interactButton.gameObject.SetActive(false);
}
if(!interacting){
//generate speech every so often while the player is nearby
if(Time.time % 5 < 0.01){
if (Random.Range(0f, 1f) < 0.3)
{
proximityTimer = Time.time;
setText(secondarySpeechBox, characterScript.ProximityMessage());
}
}
//deactivate the secondary box
if(Time.time > proximityTimer + 4){
secondarySpeechBox.gameObject.SetActive(false);
}
}
}
//remove speechBoxes after certain time
if(Time.time > speechBoxTimer + 5){
speechBox.gameObject.SetActive(false);
secondarySpeechBox.gameObject.SetActive(false);
}
}
//characterMovement script sets this for us when the player
//enters or exits characters range
public void setInteractable(bool value){
interactable = value;
if(interactable){
enterInteractable();
}else{
exitInteractable();
}
}
//player enters characters range
void enterInteractable(){
speechBox.gameObject.SetActive(false);
interactButton.gameObject.SetActive(true);
}
//player exits characters range
void exitInteractable(){
interactButton.gameObject.SetActive(false);
if (interacting)
{
setText(speechBox, characterScript.GoodbyeMessage());
}
else{
setText(speechBox, characterScript.butthurtGoodbye());
}
interacting = false;
}
//sets the text of a given text box and sets it to active.
void setText(Text box, string text){
speechBoxTimer = Time.time;
box.gameObject.SetActive(true);
box.text = text;
print(text);
}
}
fileFormatVersion: 2
guid: 2b6520c4e0b254f33b7f838739288d21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -10,15 +10,16 @@ public class CharacterMovement : MonoBehaviour {
private GameObject player;
private BoxCollider2D thisCollider;
private CharacterInteractions interactions;
private ContactFilter2D filter = new ContactFilter2D();
private bool facingRight = true;
[HideInInspector]
public bool wandering = true;
private bool wandering = true;
// Use this for initialization
void Start () {
thisCollider = GetComponent<BoxCollider2D>();
groundLevel = DaytimeManager.groundLevel;
player = GameObject.FindWithTag("Player");
interactions = GetComponent<CharacterInteractions>();
filter.SetLayerMask(LayerMask.GetMask("Player"));
}
......@@ -54,10 +55,23 @@ public class CharacterMovement : MonoBehaviour {
Collider2D[] foundPlayers = new Collider2D[1];
if (thisCollider.OverlapCollider(filter, foundPlayers) > 0)
{
wandering = false;
Wandering = false;
lookAtPlayer();
}else{
wandering = true;
Wandering = true;
}
}
// accessor for variable wandering(does extra things when its changed)
public bool Wandering{
set{
if(wandering != value){
//transition interactable
interactions.setInteractable(!value);
}
wandering = value;
}
get {
return wandering;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment