diff --git a/Assets/FactManager.cs b/Assets/FactManager.cs index a78b1f3541491e433e23e540c0f948888e620c52..865860515b8094752ef3f841c4a37088127019bb 100644 --- a/Assets/FactManager.cs +++ b/Assets/FactManager.cs @@ -10,14 +10,20 @@ public class FactManager : MonoBehaviour private List<int> NextEmpties = new List<int>(); //Variables for LineMode distinction - public bool lineModeIsFirstPointSelected = false; - public Fact lineModeFirstPointSelected = null; + private bool lineModeIsFirstPointSelected = false; + private Fact lineModeFirstPointSelected = null; //Variables for AngleMode distinction - public bool angleModeIsFirstPointSelected = false; - public Fact angleModeFirstPointSelected = null; - public bool angleModeIsSecondPointSelected = false; - public Fact angleModeSecondPointSelected = null; + private bool angleModeIsFirstPointSelected = false; + private Fact angleModeFirstPointSelected = null; + private bool angleModeIsSecondPointSelected = false; + 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 void Start() @@ -31,6 +37,8 @@ void Start() NextEmpties.Add(0); + //Calculate Solution-Vector + solutionVector = snapZoneTop.transform.position - snapZoneBottom.transform.position; } // Update is called once per frame @@ -151,92 +159,66 @@ public int GetFirstEmptyID() } - - public void OnToolModeChanged(ToolMode ActiveToolMode) + public Boolean factAlreadyExists(int[] ids) { - //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: - //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) { - GameObject gO = fact.Representation; - 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")) + if (typeof(LineFact).IsInstanceOfType(fact)) { - 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: - //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) { - GameObject gO = fact.Representation; - 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")) + if (typeof(AngleFact).IsInstanceOfType(fact)) { - 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; - /* - 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; + default: + return false; } - //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 public void Rocket(RaycastHit hit) @@ -297,38 +279,86 @@ public void SmallRocket(RaycastHit hit, int idA) CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(idB, idA, idC, GetFirstEmptyID())); } - public Boolean factAlreadyExists(int[] ids) { - switch (ActiveToolMode) { + public void OnToolModeChanged(ToolMode 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: + //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) { - 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; - if (line.Pid1 == ids[0] && line.Pid2 == ids[1]) - { - 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: + //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) { - 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; - if (angle.Pid1 == ids[0] && angle.Pid2 == ids[1] && angle.Pid3 == ids[2]) - { - return true; - } + gO.GetComponentInChildren<Collider>().enabled = false; + } + else if (gO.layer == LayerMask.NameToLayer("Point")) + { + gO.GetComponentInChildren<Collider>().enabled = true; } } - return false; - default: - return false; + 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;*/ + 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) diff --git a/Assets/InteractionEngine/Character_Animations/CharacterDialog.cs b/Assets/InteractionEngine/Character_Animations/CharacterDialog.cs index c1183086588e5fe0f075fb32ac61b50c029d6ec8..e9a48adfce5f8827d0b1f8c801803d645812a416 100644 --- a/Assets/InteractionEngine/Character_Animations/CharacterDialog.cs +++ b/Assets/InteractionEngine/Character_Animations/CharacterDialog.cs @@ -18,43 +18,35 @@ public class CharacterDialog : MonoBehaviour //Only reset once after Player is out of range of the TaskCharacter private bool textReseted = true; - //If pushoutSucceeded -> Disable Talking with TaskCharacter - private bool pushoutSucceeded = false; + //If gameSucceeded -> Disable Talking with TaskCharacter + private bool gameSucceeded = false; // Start is called before the first frame update void Start() { - CommunicationEvents.PushoutFactEvent.AddListener(PushoutSucceededSentence); + CommunicationEvents.gameSucceededEvent.AddListener(StartGameSucceededSentence); + CommunicationEvents.gameNotSucceededEvent.AddListener(StopGameSucceededSentence); //Type first sentence typingActive = true; TypeFkt(); - } private void Update() { 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 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 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() { if (typingActive) { @@ -85,6 +77,7 @@ public void NextSentence() { //-2 because the last sentence is only for SucceededPushout-Purposes if (sentenceIndex < sentences.Length - 2) { + TaskCharakterAnimation.setTaskCharacterAddressed(true); sentenceIndex++; letterIndex = 0; typingActive = true; @@ -103,6 +96,7 @@ public void NextSentence() { } public void ResetSentence() { + TaskCharakterAnimation.setTaskCharacterAddressed(false); sentenceIndex = 0; letterIndex = 0; typingActive = true; @@ -113,17 +107,32 @@ public void ResetSentence() { textReseted = true; } - public void PushoutSucceededSentence(Fact startFact) { - textDisplay.text = ""; - //Last Sentence is the Pushout-Sentence - sentenceIndex = sentences.Length - 1; - letterIndex = 0; - typingActive = true; - timer = 0; - pushoutSucceeded = true; - //Disable Hint With Enter-Key for Talking - textHint.GetComponent<MeshRenderer>().enabled = false; - //Type final message - TypeFkt(); + public void StartGameSucceededSentence() + { + if (!gameSucceeded) + { + textDisplay.text = ""; + //Last Sentence is the Pushout-Sentence + sentenceIndex = sentences.Length - 1; + letterIndex = 0; + typingActive = true; + timer = 0; + gameSucceeded = true; + //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(); + } } } diff --git a/Assets/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs b/Assets/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs index 13e04112a7c91a2912af84fc24cef1987ecd1780..5750a581f578dd6eae9b268eae17deffed4860af 100644 --- a/Assets/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs +++ b/Assets/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs @@ -26,15 +26,19 @@ public class TaskCharakterAnimation : MonoBehaviour private float rotationTime = 2; 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 taskCharacterAddressed = false; + // Start is called before the first frame update void Start() { anim = GetComponent<Animator>(); currentTransform = GetComponent<Transform>(); - CommunicationEvents.PushoutFactEvent.AddListener(startHappy); - CommunicationEvents.PushoutFactEndEvent.AddListener(stopHappy); } // Update is called once per frame @@ -42,7 +46,12 @@ void Update() { //Do nothing else than the animation if animationController is in happy-State if (happy) + { + this.happyTimer += Time.deltaTime; + if (happyTimer >= happyTime) + stopHappy(); return; + } RaycastHit hit; Ray ray = new Ray(player.transform.position, player.transform.forward); @@ -63,6 +72,12 @@ void Update() //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)); + if(checkGameSolved() && taskCharacterAddressed && !happyAnimationDone) + { + startHappy(); + happyAnimationDone = true; + } + return; } else { @@ -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 anim.SetBool("solved", 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 anim.SetBool("solved", false); happy = false; @@ -182,4 +207,16 @@ public static void setPlayerInTalkingZone(bool 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; + } + } diff --git a/Assets/InteractionEngine/CommunicationEvents.cs b/Assets/InteractionEngine/CommunicationEvents.cs index 9d861b07c7b1035760eee663cef4ee5c2062a96e..83ec7a29579a84540eae73b55d4797060e8da840 100644 --- a/Assets/InteractionEngine/CommunicationEvents.cs +++ b/Assets/InteractionEngine/CommunicationEvents.cs @@ -42,6 +42,10 @@ public class ShinyEvent : UnityEvent<Fact> { } + public class SignalEvent : UnityEvent { + + } + public static HitEvent SnapEvent = new HitEvent(); @@ -69,6 +73,9 @@ public class ShinyEvent : UnityEvent<Fact> { public static ShinyEvent PushoutFactEndEvent = new ShinyEvent(); public static ShinyEvent PushoutFactFailEvent = new ShinyEvent(); + public static SignalEvent gameSucceededEvent = new SignalEvent(); + public static SignalEvent gameNotSucceededEvent = new SignalEvent(); + diff --git a/Assets/InteractionEngine/Fact.cs b/Assets/InteractionEngine/Fact.cs index 0e67d40d1f0cc920907019d0173936e01eb8844a..e63cf21f8522c4d311238bf21a18172b35edf431 100644 --- a/Assets/InteractionEngine/Fact.cs +++ b/Assets/InteractionEngine/Fact.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEngine.Networking; +using static CommunicationEvents; public abstract class Fact { @@ -67,12 +68,8 @@ public PointFact(int i, float a, float b, float c, string uri) this.backendURI = uri; } - } - - - public class LineFact : Fact { //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) { this.backendURI = uri; this.backendValueURI = valuri; } - - } public class OpenLineFact : Fact @@ -146,8 +141,6 @@ public RayFact(int i, int pid1, int pid2, string uri, string valuri) this.backendURI = uri; this.backendValueURI = valuri; } - - } @@ -171,8 +164,6 @@ public OnLineFact(int i, int pid, int lid) this.backendValueURI = res.factValUri; Debug.Log("created onLine" + this.backendURI + " " + this.backendValueURI); } - - } diff --git a/Assets/InteractionEngine/WorldCursor.cs b/Assets/InteractionEngine/WorldCursor.cs index 8878fc18324ba5afdd7252f7828a3f5d9ed2a116..cdecea4b150fcfa890db76581c6667c83814ecd2 100644 --- a/Assets/InteractionEngine/WorldCursor.cs +++ b/Assets/InteractionEngine/WorldCursor.cs @@ -14,7 +14,6 @@ public class WorldCursor : MonoBehaviour void Start() { - Cam = Camera.main; //Set MarkPointMode as the default ActiveToolMode // ActiveToolMode = ToolMode.ExtraMode;//ToolMode.MarkPointMode; diff --git a/Assets/InventoryStuff/Inventory.meta b/Assets/InventoryStuff/Inventory.meta deleted file mode 100644 index 9818e1d19efb2406338d62594c7ffb0012b023e8..0000000000000000000000000000000000000000 --- a/Assets/InventoryStuff/Inventory.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b543d9677cbde534ab69c0a229bfdb06 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/StreamingAssets.meta b/Assets/StreamingAssets.meta deleted file mode 100644 index b1b07ad2bd0c4c86fda809f9a39b2942c4460d0c..0000000000000000000000000000000000000000 --- a/Assets/StreamingAssets.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b0574a63df238c64a82978b4879a0835 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TreeWorld_02.unity b/Assets/TreeWorld_02.unity index 910ed676fc2a8c10649ccd744f23c124445f834e..64cb66fe7d4e8f4a9b21852a2abda1c9a1bb336a 100644 --- a/Assets/TreeWorld_02.unity +++ b/Assets/TreeWorld_02.unity @@ -31765,9 +31765,8 @@ MonoBehaviour: m_EditorClassIdentifier: SmartMenu: {fileID: 5601740127768851631, guid: e693bf633c633d243b0254d117ec3893, type: 3} - lineModeIsFirstPointSelected: 0 - angleModeIsFirstPointSelected: 0 - angleModeIsSecondPointSelected: 0 + snapZoneTop: {fileID: 1563243733} + snapZoneBottom: {fileID: 1009368148} --- !u!23 &1661088671 stripped MeshRenderer: m_CorrespondingSourceObject: {fileID: 2600518978420199386, guid: 9cb473a50d07f1245b0f6a7ee2557d4f, @@ -41838,7 +41837,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {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_Pivot: {x: 0.5, y: 0.5} --- !u!222 &5443790102444080682 @@ -42993,7 +42992,7 @@ PrefabInstance: - target: {fileID: 6789101892953060368, guid: e8183f1330bd6124a9a9bb4d35ef2216, type: 3} propertyPath: m_AnchoredPosition.y - value: 0.000012135336 + value: -0.000018352279 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: e8183f1330bd6124a9a9bb4d35ef2216, type: 3}