Skip to content
Snippets Groups Projects
Commit 75f6304b authored by Richard Marcus's avatar Richard Marcus
Browse files

two scenes

parents 9623ac34 df069852
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: case ToolMode.CreateLineMode:
//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) foreach (Fact fact in Facts)
{ {
if (typeof(LineFact).IsInstanceOfType(fact))
GameObject gO = fact.Representation; {
if (gO == null) continue; LineFact line = (LineFact)fact;
if ((gO.layer == LayerMask.NameToLayer("Ray"))) if (line.Pid1 == ids[0] && line.Pid2 == ids[1])
gO.GetComponentInChildren<Collider>().enabled = true; {
return true;
} }
break; }
}
case ToolMode.CreateRayMode: return false;
//same as for line mode atm case ToolMode.CreateAngleMode:
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(AngleFact).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; AngleFact angle = (AngleFact)fact;
} if (angle.Pid1 == ids[0] && angle.Pid2 == ids[1] && angle.Pid3 == ids[2])
else if (gO.layer == LayerMask.NameToLayer("Point"))
{ {
gO.GetComponentInChildren<Collider>().enabled = true; return true;
}
}
}
return false;
default:
return false;
} }
} }
break;
public static Boolean gameSolved() {
Vector3 tempDir1 = new Vector3(0, 0, 0);
Vector3 tempDir2 = new Vector3(0, 0, 0);
case ToolMode.CreateAngleMode: if (solved == true)
//If CreateAngleMode is activated we want to have the ability to select Points for the Angle return true;
//but we don't want to have the ability to select Lines or Angles else {
//Look for solutionFact in global factList
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.GetComponentInChildren<Collider>().enabled = false; 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;
else if (gO.layer == LayerMask.NameToLayer("Point")) if (solutionVector == tempDir1 || solutionVector == tempDir2)
{ {
gO.GetComponentInChildren<Collider>().enabled = true; solved = true;
return true;
} }
} }
break;
/*
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;*/ return false;
case ToolMode.ExtraMode:
/*foreach (Fact fact in Facts)
{
} }
*/
break;
} }
//Stop PreviewEvents in ShineThings on ToolModeChange
CommunicationEvents.StopPreviewsEvent.Invoke(null);
}
//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) { {
case ToolMode.CreateLineMode: //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) foreach (Fact fact in Facts)
{ {
if (typeof(LineFact).IsInstanceOfType(fact))
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:
//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)
{ {
LineFact line = (LineFact)fact; GameObject gO = fact.Representation;
if (line.Pid1 == ids[0] && line.Pid2 == ids[1]) if (gO == null) continue;
if (gO.layer == LayerMask.NameToLayer("Line") || gO.layer == LayerMask.NameToLayer("Angle")|| gO.layer == LayerMask.NameToLayer("Ray"))
{ {
return true; gO.GetComponentInChildren<Collider>().enabled = false;
} }
else if (gO.layer == LayerMask.NameToLayer("Point"))
{
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;
} }
} }
break;
/*
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;
} }
return false; break;*/
default: case ToolMode.ExtraMode:
return false; /*foreach (Fact fact in Facts)
{
} }
return false; */
break;
}
//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()
{
if (!gameSucceeded)
{
textDisplay.text = ""; textDisplay.text = "";
//Last Sentence is the Pushout-Sentence //Last Sentence is the Pushout-Sentence
sentenceIndex = sentences.Length - 1; sentenceIndex = sentences.Length - 1;
letterIndex = 0; letterIndex = 0;
typingActive = true; typingActive = true;
timer = 0; timer = 0;
pushoutSucceeded = true; gameSucceeded = true;
//Disable Hint With Enter-Key for Talking //Disable Hint With Enter-Key for Talking
textHint.GetComponent<MeshRenderer>().enabled = false; textHint.GetComponent<MeshRenderer>().enabled = false;
//Type final message //Type final message
TypeFkt(); 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:
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment