Skip to content
Snippets Groups Projects
Commit df069852 authored by John Schihada's avatar John Schihada
Browse files

Adjusted NPC-Happy-Animation to trigger when talking with him again

parent 7a8045d6
No related branches found
No related tags found
No related merge requests found
...@@ -10,14 +10,20 @@ public class FactManager : MonoBehaviour ...@@ -10,14 +10,20 @@ public class FactManager : MonoBehaviour
private List<int> NextEmpties = new List<int>(); private List<int> NextEmpties = new List<int>();
//Variables for LineMode distinction //Variables for LineMode distinction
public bool lineModeIsFirstPointSelected = false; private bool lineModeIsFirstPointSelected = false;
public Fact lineModeFirstPointSelected = null; private Fact lineModeFirstPointSelected = null;
//Variables for AngleMode distinction //Variables for AngleMode distinction
public bool angleModeIsFirstPointSelected = false; private bool angleModeIsFirstPointSelected = false;
public Fact angleModeFirstPointSelected = null; private Fact angleModeFirstPointSelected = null;
public bool angleModeIsSecondPointSelected = false; private bool angleModeIsSecondPointSelected = false;
public Fact angleModeSecondPointSelected = null; private Fact angleModeSecondPointSelected = null;
//Solving game parameters
public GameObject snapZoneTop;
public GameObject snapZoneBottom;
private static Vector3 solutionVector;
private static bool solved = false;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
...@@ -31,6 +37,8 @@ void Start() ...@@ -31,6 +37,8 @@ void Start()
NextEmpties.Add(0); NextEmpties.Add(0);
//Calculate Solution-Vector
solutionVector = snapZoneTop.transform.position - snapZoneBottom.transform.position;
} }
// Update is called once per frame // Update is called once per frame
...@@ -151,92 +159,66 @@ public int GetFirstEmptyID() ...@@ -151,92 +159,66 @@ public int GetFirstEmptyID()
} }
public Boolean factAlreadyExists(int[] ids)
public void OnToolModeChanged(ToolMode ActiveToolMode)
{ {
//We need to do this somehwere...
CommunicationEvents.ActiveToolMode = ActiveToolMode;
switch (ActiveToolMode) switch (ActiveToolMode)
{ {
case ToolMode.MarkPointMode:
//If MarkPointMode is activated we want to have the ability to mark the point
//everywhere, independent of already existing facts
foreach (Fact fact in Facts)
{
GameObject gO = fact.Representation;
if (gO == null) continue;
if ((gO.layer == LayerMask.NameToLayer("Ray")))
gO.GetComponentInChildren<Collider>().enabled = true;
}
break;
case ToolMode.CreateRayMode:
//same as for line mode atm
case ToolMode.CreateLineMode: case ToolMode.CreateLineMode:
//If CreateLineMode is activated we want to have the ability to select points for the Line
//but we don't want to have the ability to select Lines or Angles
foreach (Fact fact in Facts) foreach (Fact fact in Facts)
{ {
GameObject gO = fact.Representation; if (typeof(LineFact).IsInstanceOfType(fact))
if (gO == null) continue;
if (gO.layer == LayerMask.NameToLayer("Line") || gO.layer == LayerMask.NameToLayer("Angle")|| gO.layer == LayerMask.NameToLayer("Ray"))
{
gO.GetComponentInChildren<Collider>().enabled = false;
}
else if (gO.layer == LayerMask.NameToLayer("Point"))
{ {
gO.GetComponentInChildren<Collider>().enabled = true; LineFact line = (LineFact)fact;
if (line.Pid1 == ids[0] && line.Pid2 == ids[1])
{
return true;
}
} }
} }
break; return false;
case ToolMode.CreateAngleMode: case ToolMode.CreateAngleMode:
//If CreateAngleMode is activated we want to have the ability to select Points for the Angle
//but we don't want to have the ability to select Lines or Angles
foreach (Fact fact in Facts) foreach (Fact fact in Facts)
{ {
GameObject gO = fact.Representation; if (typeof(AngleFact).IsInstanceOfType(fact))
if (gO == null) continue;
if (gO.layer == LayerMask.NameToLayer("Line") || gO.layer == LayerMask.NameToLayer("Angle"))
{
gO.GetComponentInChildren<Collider>().enabled = false;
}
else if (gO.layer == LayerMask.NameToLayer("Point"))
{ {
gO.GetComponentInChildren<Collider>().enabled = true; AngleFact angle = (AngleFact)fact;
if (angle.Pid1 == ids[0] && angle.Pid2 == ids[1] && angle.Pid3 == ids[2])
{
return true;
}
} }
} }
break; return false;
/* default:
case ToolMode.DeleteMode: return false;
//If DeleteMode is activated we want to have the ability to delete every Fact
//independent of the concrete type of fact
foreach (Fact fact in Facts)
{
GameObject gO = fact.Representation;
gO.GetComponentInChildren<Collider>().enabled = true;
}
break;*/
case ToolMode.ExtraMode:
/*foreach (Fact fact in Facts)
{
}
*/
break;
} }
//Stop PreviewEvents in ShineThings on ToolModeChange
CommunicationEvents.StopPreviewsEvent.Invoke(null);
} }
public static Boolean gameSolved() {
Vector3 tempDir1 = new Vector3(0, 0, 0);
Vector3 tempDir2 = new Vector3(0, 0, 0);
if (solved == true)
return true;
else {
//Look for solutionFact in global factList
foreach (Fact fact in Facts)
{
if (typeof(LineFact).IsInstanceOfType(fact))
{
tempDir1 = ((PointFact)Facts.Find(x => x.Id == ((LineFact)fact).Pid1)).Point - ((PointFact)Facts.Find(x => x.Id == ((LineFact)fact).Pid2)).Point;
tempDir2 = ((PointFact)Facts.Find(x => x.Id == ((LineFact)fact).Pid2)).Point - ((PointFact)Facts.Find(x => x.Id == ((LineFact)fact).Pid1)).Point;
if (solutionVector == tempDir1 || solutionVector == tempDir2)
{
solved = true;
return true;
}
}
}
return false;
}
}
//automatic 90 degree angle construction //automatic 90 degree angle construction
public void Rocket(RaycastHit hit) public void Rocket(RaycastHit hit)
...@@ -297,38 +279,86 @@ public void SmallRocket(RaycastHit hit, int idA) ...@@ -297,38 +279,86 @@ public void SmallRocket(RaycastHit hit, int idA)
CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(idB, idA, idC, GetFirstEmptyID())); CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(idB, idA, idC, GetFirstEmptyID()));
} }
public Boolean factAlreadyExists(int[] ids) { public void OnToolModeChanged(ToolMode ActiveToolMode)
switch (ActiveToolMode) { {
//We need to do this somehwere...
CommunicationEvents.ActiveToolMode = ActiveToolMode;
switch (ActiveToolMode)
{
case ToolMode.MarkPointMode:
//If MarkPointMode is activated we want to have the ability to mark the point
//everywhere, independent of already existing facts
foreach (Fact fact in Facts)
{
GameObject gO = fact.Representation;
if (gO == null) continue;
if ((gO.layer == LayerMask.NameToLayer("Ray")))
gO.GetComponentInChildren<Collider>().enabled = true;
}
break;
case ToolMode.CreateRayMode:
//same as for line mode atm
case ToolMode.CreateLineMode: case ToolMode.CreateLineMode:
//If CreateLineMode is activated we want to have the ability to select points for the Line
//but we don't want to have the ability to select Lines or Angles
foreach (Fact fact in Facts) foreach (Fact fact in Facts)
{ {
if (typeof(LineFact).IsInstanceOfType(fact)) GameObject gO = fact.Representation;
if (gO == null) continue;
if (gO.layer == LayerMask.NameToLayer("Line") || gO.layer == LayerMask.NameToLayer("Angle")|| gO.layer == LayerMask.NameToLayer("Ray"))
{ {
LineFact line = (LineFact)fact; gO.GetComponentInChildren<Collider>().enabled = false;
if (line.Pid1 == ids[0] && line.Pid2 == ids[1]) }
{ else if (gO.layer == LayerMask.NameToLayer("Point"))
return true; {
} gO.GetComponentInChildren<Collider>().enabled = true;
} }
} }
return false; break;
case ToolMode.CreateAngleMode: case ToolMode.CreateAngleMode:
//If CreateAngleMode is activated we want to have the ability to select Points for the Angle
//but we don't want to have the ability to select Lines or Angles
foreach (Fact fact in Facts) foreach (Fact fact in Facts)
{ {
if (typeof(AngleFact).IsInstanceOfType(fact)) GameObject gO = fact.Representation;
if (gO == null) continue;
if (gO.layer == LayerMask.NameToLayer("Line") || gO.layer == LayerMask.NameToLayer("Angle"))
{ {
AngleFact angle = (AngleFact)fact; gO.GetComponentInChildren<Collider>().enabled = false;
if (angle.Pid1 == ids[0] && angle.Pid2 == ids[1] && angle.Pid3 == ids[2]) }
{ else if (gO.layer == LayerMask.NameToLayer("Point"))
return true; {
} gO.GetComponentInChildren<Collider>().enabled = true;
} }
} }
return false; break;
default: /*
return false; case ToolMode.DeleteMode:
//If DeleteMode is activated we want to have the ability to delete every Fact
//independent of the concrete type of fact
foreach (Fact fact in Facts)
{
GameObject gO = fact.Representation;
gO.GetComponentInChildren<Collider>().enabled = true;
}
break;*/
case ToolMode.ExtraMode:
/*foreach (Fact fact in Facts)
{
}
*/
break;
} }
return false; //Stop PreviewEvents in ShineThings on ToolModeChange
CommunicationEvents.StopPreviewsEvent.Invoke(null);
} }
public void OnHit(RaycastHit hit) public void OnHit(RaycastHit hit)
......
...@@ -18,43 +18,35 @@ public class CharacterDialog : MonoBehaviour ...@@ -18,43 +18,35 @@ public class CharacterDialog : MonoBehaviour
//Only reset once after Player is out of range of the TaskCharacter //Only reset once after Player is out of range of the TaskCharacter
private bool textReseted = true; private bool textReseted = true;
//If pushoutSucceeded -> Disable Talking with TaskCharacter //If gameSucceeded -> Disable Talking with TaskCharacter
private bool pushoutSucceeded = false; private bool gameSucceeded = false;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
CommunicationEvents.PushoutFactEvent.AddListener(PushoutSucceededSentence); CommunicationEvents.gameSucceededEvent.AddListener(StartGameSucceededSentence);
CommunicationEvents.gameNotSucceededEvent.AddListener(StopGameSucceededSentence);
//Type first sentence //Type first sentence
typingActive = true; typingActive = true;
TypeFkt(); TypeFkt();
} }
private void Update() private void Update()
{ {
TypeFkt(); TypeFkt();
if(!pushoutSucceeded && Input.GetKeyDown(KeyCode.Return) && TaskCharakterAnimation.getPlayerInTalkingZone()) if(!gameSucceeded && Input.GetKeyDown(KeyCode.Return) && TaskCharakterAnimation.getPlayerInTalkingZone())
{ {
//Type Next sentence if player is in the talkinZone around the TaskCharacter AND the player typed the return-Key //Type Next sentence if player is in the talkinZone around the TaskCharacter AND the player typed the return-Key
NextSentence(); NextSentence();
} }
else if (!pushoutSucceeded && !TaskCharakterAnimation.getPlayerInTalkingZone() && !textReseted) else if (!gameSucceeded && !TaskCharakterAnimation.getPlayerInTalkingZone() && !textReseted)
{ {
//Reset Sentence if Player is out of range of the TaskCharacter and it's not already reseted //Reset Sentence if Player is out of range of the TaskCharacter and it's not already reseted
ResetSentence(); ResetSentence();
} }
} }
//Type a sentence slowly
IEnumerator Type() {
foreach (char letter in sentences[sentenceIndex].ToCharArray()) {
textDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
public void TypeFkt() { public void TypeFkt() {
if (typingActive) if (typingActive)
{ {
...@@ -85,6 +77,7 @@ public void NextSentence() { ...@@ -85,6 +77,7 @@ public void NextSentence() {
//-2 because the last sentence is only for SucceededPushout-Purposes //-2 because the last sentence is only for SucceededPushout-Purposes
if (sentenceIndex < sentences.Length - 2) if (sentenceIndex < sentences.Length - 2)
{ {
TaskCharakterAnimation.setTaskCharacterAddressed(true);
sentenceIndex++; sentenceIndex++;
letterIndex = 0; letterIndex = 0;
typingActive = true; typingActive = true;
...@@ -103,6 +96,7 @@ public void NextSentence() { ...@@ -103,6 +96,7 @@ public void NextSentence() {
} }
public void ResetSentence() { public void ResetSentence() {
TaskCharakterAnimation.setTaskCharacterAddressed(false);
sentenceIndex = 0; sentenceIndex = 0;
letterIndex = 0; letterIndex = 0;
typingActive = true; typingActive = true;
...@@ -113,17 +107,32 @@ public void ResetSentence() { ...@@ -113,17 +107,32 @@ public void ResetSentence() {
textReseted = true; textReseted = true;
} }
public void PushoutSucceededSentence(Fact startFact) { public void StartGameSucceededSentence()
textDisplay.text = ""; {
//Last Sentence is the Pushout-Sentence if (!gameSucceeded)
sentenceIndex = sentences.Length - 1; {
letterIndex = 0; textDisplay.text = "";
typingActive = true; //Last Sentence is the Pushout-Sentence
timer = 0; sentenceIndex = sentences.Length - 1;
pushoutSucceeded = true; letterIndex = 0;
//Disable Hint With Enter-Key for Talking typingActive = true;
textHint.GetComponent<MeshRenderer>().enabled = false; timer = 0;
//Type final message gameSucceeded = true;
TypeFkt(); //Disable Hint With Enter-Key for Talking
textHint.GetComponent<MeshRenderer>().enabled = false;
//Type final message
TypeFkt();
}
}
public void StopGameSucceededSentence()
{
if (gameSucceeded)
{
gameSucceeded = false;
//Enable Hint With Enter-Key for Talking
textHint.GetComponent<MeshRenderer>().enabled = true;
ResetSentence();
}
} }
} }
...@@ -26,15 +26,19 @@ public class TaskCharakterAnimation : MonoBehaviour ...@@ -26,15 +26,19 @@ public class TaskCharakterAnimation : MonoBehaviour
private float rotationTime = 2; private float rotationTime = 2;
private bool happy = false; private bool happy = false;
private bool happyAnimationDone = false;
private float happyTimer = 0;
private float happyTime = 7.5f;
private static bool playerInTalkingZone = false; private static bool playerInTalkingZone = false;
private static bool taskCharacterAddressed = false;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
anim = GetComponent<Animator>(); anim = GetComponent<Animator>();
currentTransform = GetComponent<Transform>(); currentTransform = GetComponent<Transform>();
CommunicationEvents.PushoutFactEvent.AddListener(startHappy);
CommunicationEvents.PushoutFactEndEvent.AddListener(stopHappy);
} }
// Update is called once per frame // Update is called once per frame
...@@ -42,7 +46,12 @@ void Update() ...@@ -42,7 +46,12 @@ void Update()
{ {
//Do nothing else than the animation if animationController is in happy-State //Do nothing else than the animation if animationController is in happy-State
if (happy) if (happy)
{
this.happyTimer += Time.deltaTime;
if (happyTimer >= happyTime)
stopHappy();
return; return;
}
RaycastHit hit; RaycastHit hit;
Ray ray = new Ray(player.transform.position, player.transform.forward); Ray ray = new Ray(player.transform.position, player.transform.forward);
...@@ -63,6 +72,12 @@ void Update() ...@@ -63,6 +72,12 @@ void Update()
//Face walkAroundObject to Player (but only on y-Axis, so ignore x-and z-axis) //Face walkAroundObject to Player (but only on y-Axis, so ignore x-and z-axis)
currentTransform.LookAt(new Vector3(player.transform.position.x, currentTransform.position.y, player.transform.position.z)); currentTransform.LookAt(new Vector3(player.transform.position.x, currentTransform.position.y, player.transform.position.z));
if(checkGameSolved() && taskCharacterAddressed && !happyAnimationDone)
{
startHappy();
happyAnimationDone = true;
}
return; return;
} }
else { else {
...@@ -146,14 +161,24 @@ void Update() ...@@ -146,14 +161,24 @@ void Update()
} }
} }
public void startHappy(Fact startFact) public bool checkGameSolved()
{
return FactManager.gameSolved();
}
public void startHappy()
{ {
//Set Variable in animationController to change the state //Set Variable in animationController to change the state
anim.SetBool("solved", true); anim.SetBool("solved", true);
happy = true; happy = true;
//Trigger for CharacterDialog
CommunicationEvents.gameSucceededEvent.Invoke();
//StartHappyTimer
happyTimer = 0;
} }
public void stopHappy(Fact startFact) { public void stopHappy()
{
//Set Variable in animationController to change the state //Set Variable in animationController to change the state
anim.SetBool("solved", false); anim.SetBool("solved", false);
happy = false; happy = false;
...@@ -182,4 +207,16 @@ public static void setPlayerInTalkingZone(bool value) { ...@@ -182,4 +207,16 @@ public static void setPlayerInTalkingZone(bool value) {
playerInTalkingZone = value; playerInTalkingZone = value;
} }
//Static Method for CharacterDialog
public static bool getTaskCharacterAddressed()
{
return taskCharacterAddressed;
}
//Static Method for CharacterDialog
public static void setTaskCharacterAddressed(bool value)
{
taskCharacterAddressed = value;
}
} }
...@@ -42,6 +42,10 @@ public class ShinyEvent : UnityEvent<Fact> { ...@@ -42,6 +42,10 @@ public class ShinyEvent : UnityEvent<Fact> {
} }
public class SignalEvent : UnityEvent {
}
public static HitEvent SnapEvent = new HitEvent(); public static HitEvent SnapEvent = new HitEvent();
...@@ -69,6 +73,9 @@ public class ShinyEvent : UnityEvent<Fact> { ...@@ -69,6 +73,9 @@ public class ShinyEvent : UnityEvent<Fact> {
public static ShinyEvent PushoutFactEndEvent = new ShinyEvent(); public static ShinyEvent PushoutFactEndEvent = new ShinyEvent();
public static ShinyEvent PushoutFactFailEvent = new ShinyEvent(); public static ShinyEvent PushoutFactFailEvent = new ShinyEvent();
public static SignalEvent gameSucceededEvent = new SignalEvent();
public static SignalEvent gameNotSucceededEvent = new SignalEvent();
......
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
using static CommunicationEvents;
public abstract class Fact public abstract class Fact
{ {
...@@ -67,12 +68,8 @@ public PointFact(int i, float a, float b, float c, string uri) ...@@ -67,12 +68,8 @@ public PointFact(int i, float a, float b, float c, string uri)
this.backendURI = uri; this.backendURI = uri;
} }
} }
public class LineFact : Fact public class LineFact : Fact
{ {
//Id's of the 2 Point-Facts that are connected //Id's of the 2 Point-Facts that are connected
...@@ -103,8 +100,6 @@ public LineFact(int i, int pid1, int pid2, string uri, string valuri) { ...@@ -103,8 +100,6 @@ public LineFact(int i, int pid1, int pid2, string uri, string valuri) {
this.backendURI = uri; this.backendURI = uri;
this.backendValueURI = valuri; this.backendValueURI = valuri;
} }
} }
public class OpenLineFact : Fact public class OpenLineFact : Fact
...@@ -146,8 +141,6 @@ public RayFact(int i, int pid1, int pid2, string uri, string valuri) ...@@ -146,8 +141,6 @@ public RayFact(int i, int pid1, int pid2, string uri, string valuri)
this.backendURI = uri; this.backendURI = uri;
this.backendValueURI = valuri; this.backendValueURI = valuri;
} }
} }
...@@ -171,8 +164,6 @@ public OnLineFact(int i, int pid, int lid) ...@@ -171,8 +164,6 @@ public OnLineFact(int i, int pid, int lid)
this.backendValueURI = res.factValUri; this.backendValueURI = res.factValUri;
Debug.Log("created onLine" + this.backendURI + " " + this.backendValueURI); Debug.Log("created onLine" + this.backendURI + " " + this.backendValueURI);
} }
} }
......
...@@ -14,7 +14,6 @@ public class WorldCursor : MonoBehaviour ...@@ -14,7 +14,6 @@ public class WorldCursor : MonoBehaviour
void Start() void Start()
{ {
Cam = Camera.main; Cam = Camera.main;
//Set MarkPointMode as the default ActiveToolMode //Set MarkPointMode as the default ActiveToolMode
// ActiveToolMode = ToolMode.ExtraMode;//ToolMode.MarkPointMode; // ActiveToolMode = ToolMode.ExtraMode;//ToolMode.MarkPointMode;
......
fileFormatVersion: 2
guid: b543d9677cbde534ab69c0a229bfdb06
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b0574a63df238c64a82978b4879a0835
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
...@@ -31765,9 +31765,8 @@ MonoBehaviour: ...@@ -31765,9 +31765,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
SmartMenu: {fileID: 5601740127768851631, guid: e693bf633c633d243b0254d117ec3893, SmartMenu: {fileID: 5601740127768851631, guid: e693bf633c633d243b0254d117ec3893,
type: 3} type: 3}
lineModeIsFirstPointSelected: 0 snapZoneTop: {fileID: 1563243733}
angleModeIsFirstPointSelected: 0 snapZoneBottom: {fileID: 1009368148}
angleModeIsSecondPointSelected: 0
--- !u!23 &1661088671 stripped --- !u!23 &1661088671 stripped
MeshRenderer: MeshRenderer:
m_CorrespondingSourceObject: {fileID: 2600518978420199386, guid: 9cb473a50d07f1245b0f6a7ee2557d4f, m_CorrespondingSourceObject: {fileID: 2600518978420199386, guid: 9cb473a50d07f1245b0f6a7ee2557d4f,
...@@ -41838,7 +41837,7 @@ RectTransform: ...@@ -41838,7 +41837,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 300, y: -241.69922} m_AnchoredPosition: {x: 300, y: -241.5}
m_SizeDelta: {x: 600, y: 480} m_SizeDelta: {x: 600, y: 480}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &5443790102444080682 --- !u!222 &5443790102444080682
...@@ -42993,7 +42992,7 @@ PrefabInstance: ...@@ -42993,7 +42992,7 @@ PrefabInstance:
- target: {fileID: 6789101892953060368, guid: e8183f1330bd6124a9a9bb4d35ef2216, - target: {fileID: 6789101892953060368, guid: e8183f1330bd6124a9a9bb4d35ef2216,
type: 3} type: 3}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0.000012135336 value: -0.000018352279
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: e8183f1330bd6124a9a9bb4d35ef2216, type: 3} m_SourcePrefab: {fileID: 100100000, guid: e8183f1330bd6124a9a9bb4d35ef2216, type: 3}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment