diff --git a/Assets/Materials/LineMaterial.mat b/Assets/Materials/LineMaterial.mat index 18c3d92723034595b0d9f8dff2ff9de256a6cac7..3f0d9d14bd13e21cb4bf971179274166f60bce3f 100644 --- a/Assets/Materials/LineMaterial.mat +++ b/Assets/Materials/LineMaterial.mat @@ -2,14 +2,15 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: LineMaterial m_Shader: {fileID: 4800000, guid: 2649b895a4c22d649852a0ca4c825c74, type: 3} - m_ShaderKeywords: + m_ValidKeywords: [] + m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -55,6 +56,7 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: - _BumpScale: 1 - _ColorMask: 15 @@ -81,3 +83,4 @@ Material: m_Colors: - _Color: {r: 0.2737103, g: 0.5471698, b: 0.028390888, a: 0.43529412} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Materials/RayMaterial.mat b/Assets/Materials/RayMaterial.mat index 011ce2ff6a868d32696628e7844d3d1ab7d7fc34..66ea964ba9b01f7d7e14ffa509c2b4743488370e 100644 --- a/Assets/Materials/RayMaterial.mat +++ b/Assets/Materials/RayMaterial.mat @@ -2,14 +2,15 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: RayMaterial m_Shader: {fileID: 4800000, guid: 2649b895a4c22d649852a0ca4c825c74, type: 3} - m_ShaderKeywords: + m_ValidKeywords: [] + m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -55,6 +56,7 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: - _BumpScale: 1 - _ColorMask: 15 @@ -81,3 +83,4 @@ Material: m_Colors: - _Color: {r: 0.027450988, g: 0.5252068, b: 0.54901963, a: 0.43529412} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Materials/SolutionMaterial.mat b/Assets/Materials/SolutionMaterial.mat index fa7820a79143c1e1d50c70adc817cbdc12e985db..76ed17b45a494bb9f5d6ecbccde85b22ed42fa6f 100644 --- a/Assets/Materials/SolutionMaterial.mat +++ b/Assets/Materials/SolutionMaterial.mat @@ -81,6 +81,6 @@ Material: - _UVSec: 0 - _ZWrite: 1 m_Colors: - - _Color: {r: 0.18332769, g: 0.6415094, b: 0.021181926, a: 0.9843137} + - _Color: {r: 0.993973, g: 1, b: 0, a: 0.9843137} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} m_BuildTextureStacks: [] diff --git a/Assets/Resources/Prefabs/Facts/Angle.prefab b/Assets/Resources/Prefabs/Facts/Angle.prefab index 0ab4ab380d36f1399e9ce3b6098ed8b44df8847f..e4f4372ce241f0069cfb2380b3b40f485eef869b 100644 --- a/Assets/Resources/Prefabs/Facts/Angle.prefab +++ b/Assets/Resources/Prefabs/Facts/Angle.prefab @@ -188,7 +188,7 @@ GameObject: - component: {fileID: 7137147696081341476} m_Layer: 12 m_Name: AngleOuter - m_TagString: Untagged + m_TagString: Selectable m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -270,7 +270,7 @@ MeshCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 4 - m_Convex: 0 + m_Convex: 1 m_CookingOptions: 30 m_Mesh: {fileID: 0} --- !u!114 &3394522495515098196 @@ -327,7 +327,7 @@ GameObject: - component: {fileID: 3394522496185282007} m_Layer: 12 m_Name: AngleInner - m_TagString: Untagged + m_TagString: Selectable m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 diff --git a/Assets/Scripts/CheckServer.cs b/Assets/Scripts/CheckServer.cs index 89524b97825de9ab32d5726ccc7ba6864acc21d6..f203639dd6f028b53b4c7939e911f659cf31befd 100644 --- a/Assets/Scripts/CheckServer.cs +++ b/Assets/Scripts/CheckServer.cs @@ -14,7 +14,6 @@ public class CheckServer : MonoBehaviour public static Process process; public static ProcessStartInfo processInfo; - // Start is called before the first frame update @@ -29,8 +28,6 @@ void Start() StartCoroutine(waiter(CommunicationEvents.IPslot2, 4, CommunicationEvents.IPcheckGeneration)); StartCoroutine(waiter(CommunicationEvents.IPslot3, 5, CommunicationEvents.IPcheckGeneration)); StartCoroutine(waiter(CommunicationEvents.IPslot3, 6, CommunicationEvents.IPcheckGeneration)); - - } public void CheckIPAdr() @@ -44,49 +41,31 @@ public void CheckIPAdr() //StartCoroutine(waiter(CommunicationEvents.IPslot1, 3, CommunicationEvents.IPcheckGeneration)); //StartCoroutine(waiter(CommunicationEvents.IPslot2, 4, CommunicationEvents.IPcheckGeneration)); //StartCoroutine(waiter(CommunicationEvents.IPslot3, 5, CommunicationEvents.IPcheckGeneration)); - - } IEnumerator waiter(String NetwAddress, int NA_id, double ics) { - - - //while(CommunicationEvents.IPcheckGeneration== ics) while (CheckNetLoop == 1) { //Wait for 1 seconds yield return new WaitForSecondsRealtime(1f); - if(CommunicationEvents.CheckServerA[NA_id] == 1) + if (CommunicationEvents.CheckServerA[NA_id] == 1) { CommunicationEvents.CheckServerA[NA_id] = 0; - switch (NA_id){ - case 1: - NetwAddress = CommunicationEvents.lastIP; - break; - case 2: - NetwAddress = CommunicationEvents.newIP; - break; - case 3: - NetwAddress = CommunicationEvents.IPslot1; - break; - case 4: - NetwAddress = CommunicationEvents.IPslot2; - break; - case 5: - NetwAddress = CommunicationEvents.IPslot3; - break; - case 6: - NetwAddress = CommunicationEvents.selecIP; - break; - //default: - - - } + NetwAddress = NA_id switch + { + 1 => CommunicationEvents.lastIP, + 2 => CommunicationEvents.newIP, + 3 => CommunicationEvents.IPslot1, + 4 => CommunicationEvents.IPslot2, + 5 => CommunicationEvents.IPslot3, + 6 => CommunicationEvents.selecIP, + _ => NetwAddress, + }; if (string.IsNullOrEmpty(NetwAddress)) { @@ -128,70 +107,34 @@ IEnumerator waiter(String NetwAddress, int NA_id, double ics) } } } - - } } - public void StartCheck(String NetwAddress, int NA_id, double ics) + public void StartCheck(String NetwAddress, int NA_id, double ics) { - CommunicationEvents.ServerRunningA_test[NA_id] = false; StartCoroutine(ServerRoutine(NetwAddress, NA_id, ics)); - } - void PrepareGame() - { - //WaitingText.text = "Press any key to start the game"; - //CommunicationEvents.ServerRunning_test = true; - //UnityEngine.Debug.Log("server fin"); - - } - - IEnumerator ServerRoutine(String NetwAddress, int NA_id, double ics) - { - using UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list"); - - yield return request.SendWebRequest(); - if (request.result == UnityWebRequest.Result.ConnectionError - || request.result == UnityWebRequest.Result.ProtocolError) + IEnumerator ServerRoutine(String NetwAddress, int NA_id, double ics) { - UnityEngine.Debug.Log("no running server " + request.error); + CommunicationEvents.ServerRunningA_test[NA_id] = false; + UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list"); + yield return request.SendWebRequest(); - while (true) + while (request.result == UnityWebRequest.Result.ConnectionError + || request.result == UnityWebRequest.Result.ProtocolError) { - using UnityWebRequest request2 = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list"); - yield return request2.SendWebRequest(); - if (request2.result == UnityWebRequest.Result.ConnectionError - || request2.result == UnityWebRequest.Result.ProtocolError) - { - // UnityEngine.Debug.Log("no running server"); - } - else - { - break; - } - + UnityEngine.Debug.Log("Wait for Server to Respond: " + request.error); + request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list"); + yield return request.SendWebRequest(); - - yield return null; + request.Dispose(); } - } + request.Dispose(); - //PrepareGame(); - if (CommunicationEvents.IPcheckGeneration == ics || (NA_id!=6))// && NA_id!=2)) - { - CommunicationEvents.ServerRunningA_test[NA_id] = true; - } - yield return null; - } - - - - void Update() - { - + if (CommunicationEvents.IPcheckGeneration == ics || (NA_id != 6))// && NA_id!=2)) + CommunicationEvents.ServerRunningA_test[NA_id] = true; + } } - } diff --git a/Assets/Scripts/CircleSegmentGenerator.cs b/Assets/Scripts/CircleSegmentGenerator.cs index ce0ded896fbb84fdc9477aa16cc647cf34718b9d..db10a772d3152abd580baba9495343097771c1f6 100644 --- a/Assets/Scripts/CircleSegmentGenerator.cs +++ b/Assets/Scripts/CircleSegmentGenerator.cs @@ -29,7 +29,7 @@ private void CreateSegment(float angle, float radius) verticeList.Add(center0); //Center-Point of upper side - Vector3 center1 = new Vector3(0, height, 0); + Vector3 center1 = new Vector3(0, height/2, 0); int center1Index = 1; verticeList.Add(center1); @@ -104,10 +104,13 @@ private void CreateSegment(float angle, float radius) i += 2; } - mesh = new Mesh(); - mesh.vertices = verticeList.ToArray(); - mesh.triangles = triangleList.ToArray(); + mesh = new Mesh + { + vertices = verticeList.ToArray(), + triangles = triangleList.ToArray() + }; GetComponent<MeshFilter>().mesh = mesh; + GetComponent<MeshCollider>().sharedMesh = mesh; mesh.RecalculateNormals(); } } diff --git a/Assets/Scripts/TestScripts.meta b/Assets/Scripts/Extensions.meta similarity index 77% rename from Assets/Scripts/TestScripts.meta rename to Assets/Scripts/Extensions.meta index 420f43beb2ac55d2b13c4af4c6af0cb18046c5bc..632a8e2fef8dec5db480471ac231f28aef7aeac2 100644 --- a/Assets/Scripts/TestScripts.meta +++ b/Assets/Scripts/Extensions.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1346ddcf92354374f97f2f7051bb47bc +guid: dfe354480e19bef46898d1159390cbdd folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/GameObjectExtensions.cs b/Assets/Scripts/Extensions/GameObjectExtensions.cs similarity index 100% rename from Assets/Scripts/GameObjectExtensions.cs rename to Assets/Scripts/Extensions/GameObjectExtensions.cs diff --git a/Assets/Scripts/GameObjectExtensions.cs.meta b/Assets/Scripts/Extensions/GameObjectExtensions.cs.meta similarity index 100% rename from Assets/Scripts/GameObjectExtensions.cs.meta rename to Assets/Scripts/Extensions/GameObjectExtensions.cs.meta diff --git a/Assets/Scripts/LayerMaskExtensions.cs b/Assets/Scripts/Extensions/LayerMaskExtensions.cs similarity index 100% rename from Assets/Scripts/LayerMaskExtensions.cs rename to Assets/Scripts/Extensions/LayerMaskExtensions.cs diff --git a/Assets/Scripts/LayerMaskExtensions.cs.meta b/Assets/Scripts/Extensions/LayerMaskExtensions.cs.meta similarity index 100% rename from Assets/Scripts/LayerMaskExtensions.cs.meta rename to Assets/Scripts/Extensions/LayerMaskExtensions.cs.meta diff --git a/Assets/Scripts/Extensions/MathfExtensions.cs b/Assets/Scripts/Extensions/MathfExtensions.cs new file mode 100644 index 0000000000000000000000000000000000000000..89fc33b01f042f733a2ee046103190a0bb685d6c --- /dev/null +++ b/Assets/Scripts/Extensions/MathfExtensions.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class MathfExtensions +{ + /// <summary> + /// Lineary Lerps between <paramref name="start"/> and <paramref name="end"/> within <paramref name="time"/>, using <see cref="Time.deltaTime"/>. + /// Guarantees returning <paramref name="end"/> at last step, + /// </summary> + /// <param name="start">Value to start</param> + /// <param name="end">Value to end</param> + /// <param name="time">Time to pass</param> + /// <returns>IEnumerator<float> with statet behaviour</returns> + public static IEnumerator<float> LerpInTime(float start, float end, float time) + { + if (time < 0) yield break; + + for (float current_time = 0; time > current_time; current_time += Time.deltaTime) + yield return Mathf.Lerp(start, end, current_time / time); + + yield return end; + } + + /// \copydoc LerpInTime(float, float, float) + /// <remarks>Wrappes static method and exposes it as Extension.</remarks> + /// <param name="iotta">Ignored. Here to expose Extension.</param> + public static IEnumerator<float> LerpInTime(this float iotta, float start, float end, float time) + => LerpInTime(start, end, time); + +} diff --git a/Assets/Scripts/Extensions/MathfExtensions.cs.meta b/Assets/Scripts/Extensions/MathfExtensions.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..9a5e1c8e92628e024c8713be33c5431375049fd0 --- /dev/null +++ b/Assets/Scripts/Extensions/MathfExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 634d033901bea8e4f97e5d743273c7ac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/InteractionEngine/RendererExtensions.cs b/Assets/Scripts/Extensions/RendererExtensions.cs similarity index 71% rename from Assets/Scripts/InteractionEngine/RendererExtensions.cs rename to Assets/Scripts/Extensions/RendererExtensions.cs index d2b633e1d61acb75a6c4e7cb6a33de84712dcc5b..a5802005b89227a26bf4196139a55e4669f04bd4 100644 --- a/Assets/Scripts/InteractionEngine/RendererExtensions.cs +++ b/Assets/Scripts/Extensions/RendererExtensions.cs @@ -7,25 +7,19 @@ public static class RendererExtensions public static IEnumerator ProgrammMaterialChange(this Renderer renderer, IEnumerable<(float delay, float lerp_time, Material new_material)> instructions, bool loop = false) { Material last_material; - float start_time, end_time; do foreach (var (delay, lerp_time, new_material) in instructions) { - last_material = renderer.material; - start_time = Time.time; - end_time = start_time + lerp_time; - yield return new WaitForSeconds(delay); - while (end_time >= Time.time) + last_material = renderer.material; + for (IEnumerator<float> lerper = MathfExtensions.LerpInTime(0, 1, lerp_time) + ; lerper.MoveNext();) { - renderer.material.Lerp(last_material, new_material - , (Time.time - start_time) / lerp_time); + renderer.material.Lerp(last_material, new_material , lerper.Current); yield return null; } - renderer.material = new_material; - } while (loop); } diff --git a/Assets/Scripts/InteractionEngine/RendererExtensions.cs.meta b/Assets/Scripts/Extensions/RendererExtensions.cs.meta similarity index 100% rename from Assets/Scripts/InteractionEngine/RendererExtensions.cs.meta rename to Assets/Scripts/Extensions/RendererExtensions.cs.meta diff --git a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs index da933c97fc4da7bf67b4b93c2dce94db3bf210ca..0e3326a1017336ac3007af4bf09fb69371ad8f48 100644 --- a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs +++ b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs @@ -32,7 +32,6 @@ public static class CommunicationEvents public static bool ServerAutoStart = true; public static bool ServerRunning = true; - public static bool ServerRunning_test = true; //CHANGE HERE PORT OF SERVER public static string ServerPortDefault = "8085"; //used for Local @@ -103,7 +102,6 @@ public static string CreateHierarchiePath(List<Directories> hierarchie, string p public static string CreatePathToFile(out bool file_exists, string name, string format = null, List<Directories> hierarchie = null, bool use_install_folder = false) { string ending = ""; - string path; if (!string.IsNullOrEmpty(format)) switch (format) { @@ -114,18 +112,11 @@ public static string CreatePathToFile(out bool file_exists, string name, string break; } - //OperationSystem Opsys is set above; - switch (Opsys) + string path = Opsys switch { - default: - case OperationSystem.Windows: - path = use_install_folder ? Application.dataPath : Application.persistentDataPath; - break; - - case OperationSystem.Android: - path = Application.persistentDataPath; - break; - } + OperationSystem.Android => Application.persistentDataPath, + OperationSystem.Windows or _ => use_install_folder ? Application.dataPath : Application.persistentDataPath, + }; if (hierarchie != null) { diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactManager.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactManager.cs index 234273d9e758e4104a635ac4e70a98060aa677e7..45c260ccfa78105e108a55797d7a58df864e97d5 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactManager.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactManager.cs @@ -51,8 +51,18 @@ public static PointFact AddPointFact(Vector3 point, Vector3 normal, bool sameste /// <param name="pid"><see cref="Fact.Id"/> of <see cref="PointFact"/> which lies on <paramref name="lid"/></param> /// <param name="lid"><see cref="Fact.Id"/> of <see cref="LineFact"/> on which <paramref name="pid"/> lies</param> /// \copydetails FactManager - public static OnLineFact AddOnLineFact(string pid, string lid, bool samestep = false, Gadget gadget = null, string scroll_label = null) + public static OnLineFact AddOnLineFact(string pid, string lid, bool samestep = false, Gadget gadget = null, string scroll_label = null, bool is_certain = false) { + if (!is_certain) + { + AbstractLineFact line = (AbstractLineFact)StageStatic.stage.factState[lid]; + PointFact line_point = (PointFact)StageStatic.stage.factState[line.Pid1]; + PointFact point = (PointFact)StageStatic.stage.factState[pid]; + + if (!Math3d.IsPointApproximatelyOnLine(line_point.Point, line.Dir, point.Point)) + return null; + } + return (OnLineFact)AddFactIfNotFound( new OnLineFact(pid, lid, StageStatic.stage.factState) , out _, samestep, gadget, scroll_label); @@ -97,7 +107,7 @@ void AddHitIfOnLine(RaycastHit hit) if (Math3d.IsPointApproximatelyOnLine(rayP1.Point, rayFact.Dir, hit.transform.position)) { AddOnLineFact( - hit.transform.gameObject.GetComponent<FactObject>().URI, rayFact.Id, true, gadget, scroll_label); + hit.transform.gameObject.GetComponent<FactObject>().URI, rayFact.Id, true, gadget, scroll_label, true); } } @@ -108,8 +118,8 @@ void AddHitIfOnLine(RaycastHit hit) AddHitIfOnLine(hit); // for good measure - AddOnLineFact(rayFact.Pid1, rayFact.Id, true, gadget, scroll_label); - AddOnLineFact(rayFact.Pid2, rayFact.Id, true, gadget, scroll_label); + AddOnLineFact(rayFact.Pid1, rayFact.Id, true, gadget, scroll_label, true); + AddOnLineFact(rayFact.Pid2, rayFact.Id, true, gadget, scroll_label, true); return rayFact; } diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs index 759aafdd1004cec8629decd9ee1efb7a853c8fe0..08b5358b29cbd40f0626d0e0845a65a76a1094ec 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactOrganizer.cs @@ -172,7 +172,7 @@ public stepnote(FactOrganizer that, string Id, bool samestep, bool creation, Gad this.scroll_label = scroll_label; this.GadgetTime = StageStatic.stage_time; - stepnote prev = default(stepnote); + stepnote prev = default; if (samestep) { prev = that.Workflow[that.marker - 1]; @@ -201,7 +201,7 @@ public stepnote(FactOrganizer that, string Id, bool samestep, bool creation, Gad bool set_workflow = !samestep || new_gadget || prev.gadget_rank != this.gadget_rank || gadget_entree.last_occurrence >= that.marker; - stepnote gadget_prev = set_workflow ? default(stepnote) /*unused then*/ + stepnote gadget_prev = set_workflow ? default /*unused then*/ : that.Workflow[gadget_entree.last_occurrence]; if ( set_workflow || gadget_prev.GadgetFlow == null diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs index 7d242f0b32e0fc404036f78e1406ee15c23fd693..780cb4a902976c6898238ff88549dad026e7875f 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs @@ -13,51 +13,36 @@ public GameObject Ray, Angle; - private GameObject FactRepresentation; - //private Camera camera; - void Start() { - - AddFactEvent.AddListener(FactAction); + AddFactEvent.AddListener(SpawnFactRepresentation_Wrapped); RemoveFactEvent.AddListener(DeleteObject); AnimateNonExistingFactEvent.AddListener(animateNonExistingFactTrigger); - - //Default FactRepresenation = Sphere-Prefab for Points - this.FactRepresentation = Sphere; - - //camera = Camera.main; - } - public void FactAction(Fact fact) { - getAction(fact)?.Invoke(fact); - } + private void SpawnFactRepresentation_Wrapped(Fact fact) => SpawnFactRepresentation(fact); - public Func<Fact, Fact> getAction(Fact fact) + public Fact SpawnFactRepresentation(Fact fact) { - return fact switch + Func<Fact, Fact> func = fact switch { - PointFact pointFact - => SpawnPoint, - LineFact lineFact - => SpawnLine, - AngleFact angleFact - => SpawnAngle, - RayFact rayFact - => SpawnRay, + PointFact => SpawnPoint, + LineFact => SpawnLine, + AngleFact => SpawnAngle, + RayFact => SpawnRay, _ => null, }; + + return func?.Invoke(fact); } public Fact SpawnPoint(Fact pointFact) { PointFact fact = ((PointFact)pointFact); - this.FactRepresentation = Sphere; - GameObject point = GameObject.Instantiate(FactRepresentation); + GameObject point = GameObject.Instantiate(Sphere); point.transform.position = fact.Point; point.transform.up = fact.Normal; point.GetComponentInChildren<TextMeshPro>().text = fact.Label; @@ -75,8 +60,7 @@ public Fact SpawnLine(Fact fact) Vector3 point1 = pointFact1.Point; Vector3 point2 = pointFact2.Point; //Change FactRepresentation to Line - this.FactRepresentation = Line; - GameObject line = GameObject.Instantiate(FactRepresentation); + GameObject line = GameObject.Instantiate(Line); //Place the Line in the centre of the two points line.transform.position = Vector3.Lerp(point1, point2, 0.5f); //Change scale and rotation, so that the two points are connected by the line @@ -117,8 +101,7 @@ public Fact SpawnRay(Fact fact) point2 += dir * 100; //Change FactRepresentation to Line - this.FactRepresentation = Ray; - GameObject line = GameObject.Instantiate(FactRepresentation); + GameObject line = GameObject.Instantiate(Ray); //Place the Line in the centre of the two points line.transform.position = Vector3.Lerp(point1, point2, 0.5f); //Change scale and rotation, so that the two points are connected by the line @@ -159,8 +142,7 @@ public Fact SpawnAngle(Fact fact) length = lengthFactor * (point1 - point2).magnitude; //Change FactRepresentation to Angle - this.FactRepresentation = Angle; - GameObject angle = GameObject.Instantiate(FactRepresentation); + GameObject angle = GameObject.Instantiate(Angle); //Calculate Angle: Vector3 from = (point3 - point2).normalized; @@ -204,7 +186,7 @@ public void animateNonExistingFactTrigger(Fact fact) { } public IEnumerator animateNonExistingFact(Fact fact) { - Fact returnedFact = getAction(fact).Invoke(fact); + Fact returnedFact = SpawnFactRepresentation(fact); ShinyThings.HighlightFact(returnedFact, FactObject.FactMaterials.Hint); diff --git a/Assets/Scripts/InteractionEngine/Gadgets/LotTool.cs b/Assets/Scripts/InteractionEngine/Gadgets/LotTool.cs index 6c3a2b5f9eda3901c6f2f9ae1e3fa17556429de6..3bbe9476aa4a2653fa451ee101754c95f953595c 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/LotTool.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/LotTool.cs @@ -68,7 +68,7 @@ void CreateRayAndAngles(string IntersectionId, string LotPointId, bool samestep) var intersectionId = FactManager.AddPointFact(IntersectionPoint, normal, gadget: this).Id; if (BaseLine is RayFact) // Add OnLineFact only on Ray not Line - FactManager.AddOnLineFact(intersectionId, Workflow[0], true, gadget: this); + FactManager.AddOnLineFact(intersectionId, Workflow[0], true, gadget: this, is_certain: true); CreateRayAndAngles(intersectionId, tempFactId, true); ResetGadget(); diff --git a/Assets/Scripts/InteractionEngine/Gadgets/Pointer.cs b/Assets/Scripts/InteractionEngine/Gadgets/Pointer.cs index 229752c0e71bbb190566f7f6e35f1db927ecce25..8e84f00dade73a1cc6e6c462ddaba076d241dc2d 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/Pointer.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/Pointer.cs @@ -20,7 +20,8 @@ public override void _Hit(RaycastHit hit) (pid , Workflow[0] , samestep: true - , gadget: this); + , gadget: this + , is_certain: false); } ResetGadget(); diff --git a/Assets/Scripts/InteractionEngine/ImageHintAnimation.cs b/Assets/Scripts/InteractionEngine/ImageHintAnimation.cs index 58abeea84e39b68622aa267ebd42d83406c21982..f56f135f43b46da1395120aba5f43b62ebe5d5dd 100644 --- a/Assets/Scripts/InteractionEngine/ImageHintAnimation.cs +++ b/Assets/Scripts/InteractionEngine/ImageHintAnimation.cs @@ -1,79 +1,47 @@ -using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; using UnityEngine.UI; using static GlobalBehaviour; public class ImageHintAnimation : MonoBehaviour { public Image imageToChange; - public Color imageToChangeDefaultColor { get; set; } - private Color animationStartColor; - private Color animationEndColor; - - private float animateDuration; - private bool animating = false; - private float timer = 0; + [System.NonSerialized] + public Color imageToChangeDefaultColor; + private IEnumerator routine; // Start is called before the first frame update - void Start() + void Awake() { if (imageToChange != null) imageToChangeDefaultColor = imageToChange.color; - - updateAnimationParameters(); - } - - // Update is called once per frame - void Update() - { - if (animating) - { - this.timer += Time.deltaTime; - Animate(); - } } public void AnimationTrigger() { - if (imageToChange != null) - { - updateAnimationParameters(); - animating = true; - } - } - - public void ResetAnimation() - { - if (imageToChange != null) - { - Reset(); - } - } + routine = Animation(); + StartCoroutine(routine); - private void Animate() - { - if (timer >= animateDuration) + IEnumerator Animation() { - Reset(); - } - else - { - imageToChange.color = Color.Lerp(animationStartColor, animationEndColor, Mathf.PingPong(Time.time, 1)); - } + for ( var track = 0f.LerpInTime(0, 0, GlobalBehaviour.hintAnimationDuration) + ; track.MoveNext();) - } + yield return imageToChange.color = + Color.Lerp + ( GlobalBehaviour.hintAnimationStartColor + , GlobalBehaviour.hintAnimationEndColor + , Mathf.PingPong(Time.time, 1)); - private void Reset() - { - animating = false; - timer = 0; - imageToChange.color = imageToChangeDefaultColor; + imageToChange.color = imageToChangeDefaultColor; + } } - private void updateAnimationParameters() + public void ResetAnimation() { - animationStartColor = GlobalBehaviour.hintAnimationStartColor; - animationEndColor = GlobalBehaviour.hintAnimationEndColor; - animateDuration = GlobalBehaviour.hintAnimationDuration; + if (routine != null) + StopCoroutine(routine); } } diff --git a/Assets/Scripts/InteractionEngine/ShinyThings.cs b/Assets/Scripts/InteractionEngine/ShinyThings.cs index 211f7b6f3f60b09d1167b55c7b8da23625292dd9..87f0dd1b071fdb74fa1e806942b1f9c3fba0a9dd 100644 --- a/Assets/Scripts/InteractionEngine/ShinyThings.cs +++ b/Assets/Scripts/InteractionEngine/ShinyThings.cs @@ -11,27 +11,39 @@ public class ShinyThings : MonoBehaviour //Variables for Pushout-Highlighting private static float timerDuration = 2.5f; + private static float lerpTime = 1f; + + private IEnumerator rain_wait; + private IEnumerator rain; + + public Light directionalLight; + private Color darkColor = new (0.2f, 0.2f, 0.2f); + private Color light_colour; + private GameObject active_rainwork; - public GameObject directionalLight; - private Color darkColor = new (0.3f, 0.3f, 0.3f); - public Material pushoutMaterial; public GameObject Fireworks_Animation, RainPrefab; - // Start is called before the first frame update + private void Awake() + { + CommunicationEvents.PushoutFactEvent.AddListener(HighlightFact); + CommunicationEvents.PushoutFactFailEvent.AddListener(LetItRain); + CommunicationEvents.AnimateExistingFactEvent.AddListener(HighlightWithFireworks); + + rain = rain_wait = 0f.LerpInTime(0, 0, -1); // yield return break + } + public void Start() { - if (Cursor == null) + if (Cursor == null) Cursor = GetComponent<WorldCursor>(); if (directionalLight == null) - directionalLight = FindObjectOfType<Light>().gameObject; + directionalLight = FindObjectOfType<Light>(); - CommunicationEvents.PushoutFactEvent.AddListener(HighlightFact); - CommunicationEvents.PushoutFactFailEvent.AddListener(StartPushoutFactFailHighlighting); - CommunicationEvents.AnimateExistingFactEvent.AddListener(HighlightWithFireworks); + light_colour = directionalLight.color; } // Update is called once per frame @@ -65,7 +77,7 @@ void ApplyMaterial(FactObject root, Material new_mat) => root.CoroutineCascadeForChildrenAllRenderer( (_, renderer) => renderer.ProgrammMaterialChange(new[] { - (0f, 1f, new_mat), + (0f, lerpTime, new_mat), }) ); } @@ -77,21 +89,25 @@ public static void HighlightFact(Fact startFact, FactObject.FactMaterials tmp_ma selected_fact_obj.CoroutineCascadeForChildrenAllRenderer( (fact_obj, renderer) => renderer.ProgrammMaterialChange(new[] { - (0f, 1f, fact_obj.materials[(int) tmp_mat]), - (timerDuration, 1f, fact_obj.Default), + (0f, lerpTime, fact_obj.materials[(int) tmp_mat]), + (GlobalBehaviour.hintAnimationDuration, lerpTime, fact_obj.Default), }) ); } public void HighlightWithFireworks(Fact fact) { + while (rain_wait.MoveNext()) ; //stop rain + StartCoroutine(BlossomAndDie()); HighlightFact(fact, FactObject.FactMaterials.Solution); IEnumerator BlossomAndDie() { - GameObject firework = GameObject.Instantiate(Fireworks_Animation); - firework.transform.position = fact.Representation.transform.position; + GameObject firework = GameObject.Instantiate + ( Fireworks_Animation + , fact.Representation.transform + ); yield return new WaitForSeconds(timerDuration); @@ -109,39 +125,40 @@ IEnumerator BlossomAndDie() } } - public void StartPushoutFactFailHighlighting(Fact startFact) + public void LetItRain(Fact startFact) { - StartCoroutine(BlossomAndDie()); + bool restart = !rain_wait.MoveNext(); + + if (restart) { + StopCoroutine(rain); + StartCoroutine(rain = BlossomAndDie()); + } + rain_wait = 0f.LerpInTime(0, 0, timerDuration); IEnumerator BlossomAndDie() { - Color start = directionalLight.GetComponent<Light>().color; - IEnumerator<float> num = LerpfTime(0, 1, 1); - while (num.MoveNext()) { - directionalLight.GetComponent<Light>().color = Color.Lerp(start, darkColor, num.Current); + Destroy(active_rainwork); + active_rainwork = GameObject.Instantiate(RainPrefab, new Vector3(0, 40, 0), Quaternion.identity); + + Color start = directionalLight.color; + for (IEnumerator<float> lerper = MathfExtensions.LerpInTime(0, 1, lerpTime) + ; lerper.MoveNext();) + { + directionalLight.color = Color.Lerp(start, darkColor, lerper.Current); yield return null; } - GameObject rainwork = GameObject.Instantiate(RainPrefab, new Vector3(0, 40, 0), Quaternion.identity); - yield return new WaitForSeconds(2*timerDuration); - GameObject.Destroy(rainwork); + while (rain_wait.MoveNext()) + yield return null; - num = LerpfTime(0, 1, 1); - while (num.MoveNext()) + for (IEnumerator<float> lerper = MathfExtensions.LerpInTime(0, 1, lerpTime) + ; lerper.MoveNext();) { - directionalLight.GetComponent<Light>().color = Color.Lerp(darkColor, start, num.Current); + directionalLight.color = Color.Lerp(darkColor, light_colour, lerper.Current); yield return null; } - } - - IEnumerator<float> LerpfTime(float start, float end, float time) - { - float - start_time = Time.time, - end_time = start_time + time; - while(end_time >= Time.time) - yield return Mathf.Lerp(start, end, (Time.time - start_time) / time); + GameObject.Destroy(active_rainwork); } } } diff --git a/Assets/Scripts/InteractionEngine/WorldCursor.cs b/Assets/Scripts/InteractionEngine/WorldCursor.cs index 520e006ac99d74f96b9934ed49879e0ee6006852..ab79abbd80a6cea41ecb8f5ed9eb643aaf42283f 100644 --- a/Assets/Scripts/InteractionEngine/WorldCursor.cs +++ b/Assets/Scripts/InteractionEngine/WorldCursor.cs @@ -14,7 +14,7 @@ public class WorldCursor : MonoBehaviour public string deactivateSnapKey; private Camera Cam; private int layerMask; - public LayerMask snapLayerMask; + public float MaxRange = 10f; private float MaxRange_ = 10f; public bool useCamCurser = false; @@ -58,19 +58,16 @@ void Update() transform.position = ray.GetPoint(GlobalBehaviour.GadgetPhysicalDistance); //************************************************ - int rayCastMask = this.layerMask; - - if (Input.GetButton(this.deactivateSnapKey) - && UIconfig.InputManagerVersion >= 1 && UIconfig.InputManagerVersion <= 3) - rayCastMask &= ~this.snapLayerMask.value; + bool deactSnapKey = + Input.GetButton(this.deactivateSnapKey) + && UIconfig.InputManagerVersion >= 1 + && UIconfig.InputManagerVersion <= 3; //************************************************ - if (Physics.Raycast(ray, out Hit, MaxRange_, rayCastMask) + if (Physics.Raycast(ray, out Hit, MaxRange_, layerMask) || (MaxRange_ <= GlobalBehaviour.GadgetPhysicalDistance - && Physics.Raycast(transform.position, Vector3.down, out Hit, GlobalBehaviour.GadgetPhysicalDistance, rayCastMask))) + && Physics.Raycast(transform.position, Vector3.down, out Hit, GlobalBehaviour.GadgetPhysicalDistance, layerMask))) { - bool deactSnapKey = false; - if (UIconfig.InputManagerVersion == 1) Input.GetButton(this.deactivateSnapKey); diff --git a/Assets/Scripts/Loading/StreamingAssetLoader.cs b/Assets/Scripts/Loading/StreamingAssetLoader.cs index 105a54be6543f5dea375fd3bb0fb9b13c7f7dc47..8f4ba9f5206888025e44c4a0aa4b102dc70ca082 100644 --- a/Assets/Scripts/Loading/StreamingAssetLoader.cs +++ b/Assets/Scripts/Loading/StreamingAssetLoader.cs @@ -23,48 +23,15 @@ public static class StreamingAssetLoader public static string PersDataPathToPlayerSaveGame_Path = "stages/SaveGames"; - //"" - public static string file_1_path = ""; - public static string file_1 = "scrolls.json"; - - //Stages - public static string file_2_path = "Stages"; - public static string file_2 = "TechDemo A.JSON"; - - public static string file_3_path = "Stages"; - public static string file_3 = "TechDemo B.JSON"; - - - //ValidationSets - public static string file_4_path = "Stages/ValidationSets"; - public static string file_4 = "TechDemo A_val.JSON"; - - public static string file_5_path = "Stages/ValidationSets"; - public static string file_5 = "TechDemo B_val.JSON"; - - //FactStateMachines - public static string file_6_path = "Stages/ValidationSets/FactStateMachines"; - public static string file_6 = "TechDemo A_sol.JSON"; - - public static string file_7_path = "Stages/ValidationSets/FactStateMachines"; - public static string file_7 = "TechDemo B_sol.JSON"; - - + //Config public static string file_8_path = "Config"; public static string file_8 = "Network.JSON"; - public static string file_9_path = ""; - public static string file_9 = ""; - - public static string file_10_path = ""; - public static string file_10 = ""; - //public static ID_toPath toPath = ID_toPath.DataPath; public enum ID_toPath { DataPath = 0, PersistentDataPath = 1, - } @@ -220,15 +187,6 @@ public static void RereadFiles_DataPath() public static void RereadFiles_DataPath_withHandler() { - //RereadFileUWR(StreamingAssetLoader.file_2_path, StreamingAssetLoader.file_2, ID_toPath.DataPath); - //RereadFileUWR(StreamingAssetLoader.file_3_path, StreamingAssetLoader.file_3, ID_toPath.DataPath); - //RereadFileUWR(StreamingAssetLoader.file_4_path, StreamingAssetLoader.file_4, ID_toPath.DataPath); - //RereadFileUWR(StreamingAssetLoader.file_5_path, StreamingAssetLoader.file_5, ID_toPath.DataPath); - //RereadFileUWR(StreamingAssetLoader.file_6_path, StreamingAssetLoader.file_6, ID_toPath.DataPath); - //RereadFileUWR(StreamingAssetLoader.file_7_path, StreamingAssetLoader.file_7, ID_toPath.DataPath); - //RereadFileUWR(StreamingAssetLoader.file_9_path, StreamingAssetLoader.file_9, ID_toPath.DataPath); - //RereadFileUWR(StreamingAssetLoader.file_10_path, StreamingAssetLoader.file_10, ID_toPath.DataPath); - string rootPath = Path.Combine(Application.streamingAssetsPath, StreamToDataPath_withHandler_Folder); string targetFolder = Application.dataPath; if (CommunicationEvents.Opsys == OperationSystem.Android) @@ -236,7 +194,7 @@ public static void RereadFiles_DataPath_withHandler() targetFolder = Application.persistentDataPath; } - ReReadFiles(rootPath, targetFolder); + ReReadFiles(rootPath, targetFolder); } public static void ReReadFiles(string rootPath, string targetFolder)//ID_toPath PathHandler) @@ -618,24 +576,6 @@ public static void Score_Save(string Directory_path, string date) Writer.Write(json); Writer.Flush(); Writer.Close(); - - - - //RereadFileUW("", "scrolls.json", "test3", "test6.json"); - //RereadFileUW("Stages", "TechDemo A.JSON", "test3", "test7.json"); - - /* - RereadFileUWR("", "scrolls.json"); - RereadFileUWR("Stages", "TechDemo A.JSON"); - RereadFileUWR("Stages", "TechDemo B.JSON"); - RereadFileUWR("Stages/ValidationSets", "TechDemo A_val.JSON"); - RereadFileUWR("Stages/ValidationSets", "TechDemo B_val.JSON"); - RereadFileUWR("Stages/ValidationSets/FactStateMachines", "TechDemo A_val.JSON"); - RereadFileUWR("Stages/ValidationSets/FactStateMachines", "TechDemo B_val.JSON"); - */ - - - } @@ -643,12 +583,6 @@ public static void Score_Save(string Directory_path, string date) public static string Score_Load(string Directory_path) { //Data acquisition - //var reader = new StreamReader(Application.persistentDataPath + "/" + Directory_path + "/date.json"); - //var reader = new StreamReader(Application.persistentDataPath + "/scrolls.json"); - //var reader = new StreamReader(Application.persistentDataPath + "/1/scrolls.json"); - //var reader = new StreamReader(Application.persistentDataPath + "/test3/test7.json"); - //var reader = new StreamReader(Application.persistentDataPath + "Stages/factStateMAchines/TechDemo B_val.JSON"); - //var reader = new StreamReader(Application.persistentDataPath + "/Stages/TechDemo B.JSON"); var reader = new StreamReader(Application.persistentDataPath + "/Config/Network.JSON"); string json = reader.ReadToEnd(); reader.Close();