From fcabc55f5f663307fa83156f2630a9745603faf0 Mon Sep 17 00:00:00 2001
From: Richard Marcus <richard.marcus@fau.de>
Date: Fri, 7 Feb 2020 02:24:35 +0100
Subject: [PATCH] fixed ray line prototype

---
 Assets/FactManager.cs                   | 13 ++++++++++++-
 Assets/InteractionEngine/FactSpawner.cs |  8 ++++----
 Assets/InventoryStuff/DisplayFacts.cs   |  9 +++++++++
 Assets/TreeWorld.unity                  |  2 +-
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/Assets/FactManager.cs b/Assets/FactManager.cs
index 7e388e76..ad5ff06c 100644
--- a/Assets/FactManager.cs
+++ b/Assets/FactManager.cs
@@ -51,6 +51,13 @@ LineFact AddLineFact(int pid1, int pid2, int id)
 
         return Facts.Find(x => x.Id == id) as LineFact;
     }
+    RayFact AddRayFact(int pid1, int pid2, int id)
+    {
+        Facts.Insert(id, new RayFact(id, pid1, pid2));
+
+        return Facts.Find(x => x.Id == id) as RayFact;
+    }
+
 
     AngleFact AddAngleFact(int pid1, int pid2, int pid3, int id)
     {
@@ -292,7 +299,11 @@ public void OnHit(RaycastHit hit)
                         //Create LineFact
                         //Check if exactle the same line/distance already exists
                         if(!factAlreadyExists(new int[] { this.lineModeFirstPointSelected.Id, tempFact.Id }))
-                            CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(this.lineModeFirstPointSelected.Id, tempFact.Id, this.GetFirstEmptyID()));
+                            if(ActiveToolMode==ToolMode.CreateLineMode)
+                                CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(this.lineModeFirstPointSelected.Id, tempFact.Id, this.GetFirstEmptyID()));
+                            else
+                                CommunicationEvents.AddFactEvent.Invoke(this.AddRayFact(this.lineModeFirstPointSelected.Id, tempFact.Id, this.GetFirstEmptyID()));
+
                         this.lineModeIsFirstPointSelected = false;
                         this.lineModeFirstPointSelected = null;
                     }
diff --git a/Assets/InteractionEngine/FactSpawner.cs b/Assets/InteractionEngine/FactSpawner.cs
index 9dd2ca5c..5797a466 100644
--- a/Assets/InteractionEngine/FactSpawner.cs
+++ b/Assets/InteractionEngine/FactSpawner.cs
@@ -124,6 +124,7 @@ public void SpawnRay(RayFact lineFact)
         //Get the Line-GameObject as the first Child of the Line-Prefab -> That's the Collider
         var v3T = line.transform.GetChild(0).localScale;
         v3T.x = (point2 - point1).magnitude;
+        Debug.Log(v3T.x);
         //For every Coordinate x,y,z we have to devide it by the LocalScale of the Child,
         //because actually the Child should be of this length and not the parent, which is only the Collider
         v3T.x = v3T.x / line.transform.GetChild(0).GetChild(0).localScale.x;
@@ -134,10 +135,9 @@ public void SpawnRay(RayFact lineFact)
         line.transform.GetChild(0).localScale = v3T;
         line.transform.GetChild(0).rotation = Quaternion.FromToRotation(Vector3.right, point2 - point1);
 
-        //string letter = ((Char)(64 + lineFact.Id + 1)).ToString();
-        //line.GetComponentInChildren<TextMeshPro>().text = letter;
-        line.GetComponentInChildren<TextMeshPro>().text = ((Char)(64 + pointFact1.Id + 1)).ToString() + ((Char)(64 + pointFact2.Id + 1)).ToString();
-        line.GetComponentInChildren<TextMeshPro>().text += " = " + Math.Round((point1 - point2).magnitude, 2).ToString() + " m";
+        string letter = ((Char)(64 + lineFact.Id + 1)).ToString();
+        line.GetComponentInChildren<TextMeshPro>().text = letter;
+     
         line.GetComponentInChildren<FactObject>().Id = lineFact.Id;
         //If a new Line was spawned -> We are in CreateLineMode -> Then we want the collider to be disabled
         if (CommunicationEvents.ActiveToolMode != ToolMode.ExtraMode)
diff --git a/Assets/InventoryStuff/DisplayFacts.cs b/Assets/InventoryStuff/DisplayFacts.cs
index ef5e9c45..c683ecd8 100644
--- a/Assets/InventoryStuff/DisplayFacts.cs
+++ b/Assets/InventoryStuff/DisplayFacts.cs
@@ -63,6 +63,14 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
                     obj.GetComponent<FactWrapper>().fact = f;
                     return obj;
                 }
+            case RayFact f:
+                {
+                    var obj = Instantiate(prefab_Distance, Vector3.zero, Quaternion.identity, transform);
+                    obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid1].Id);
+                    obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid2].Id);
+                    obj.GetComponent<FactWrapper>().fact = f;
+                    return obj;
+                }
 
             case AngleFact f:
                 {
@@ -86,6 +94,7 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
                     var obj = Instantiate(prefab_Default, Vector3.zero, Quaternion.identity, transform);
                     return obj;
                 }
+           
         }
     }
 
diff --git a/Assets/TreeWorld.unity b/Assets/TreeWorld.unity
index 3837c442..4e29164a 100644
--- a/Assets/TreeWorld.unity
+++ b/Assets/TreeWorld.unity
@@ -2089,7 +2089,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 1, y: 1}
   m_AnchorMax: {x: 1, y: 1}
-  m_AnchoredPosition: {x: 606.5377, y: 469.0689}
+  m_AnchoredPosition: {x: 74, y: 514}
   m_SizeDelta: {x: 250, y: 60}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &1143784615
-- 
GitLab