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

finalized online prototype

parent d92d4c43
No related branches found
No related tags found
No related merge requests found
......@@ -61,8 +61,52 @@ RayFact AddRayFact(int pid1, int pid2, int id)
oLid = GetFirstEmptyID();
Facts.Insert(oLid, new OnLineFact(oLid, pid2, id));
//TODO: check for more points, question: should MMT do this instead?
var p1 = Facts.Find(x => x.Id == pid1);
var p2 = Facts.Find(x => x.Id == pid2);
Vector3 dir = p2.Representation.transform.position - p1.Representation.transform.position;
// Bit shift the index of the layer Point to get a bit mask
int layerMask = 1 << LayerMask.NameToLayer("Point");
// This casts rays only against colliders in layer 8
RaycastHit[] hits;
hits = Physics.RaycastAll(p1.Representation.transform.position - dir * 1000, dir, Mathf.Infinity, layerMask);
Debug.Log(hits.Length + " hits");
for (int i = 0; i < hits.Length; i++)
{
RaycastHit hit = hits[i];
bool exists = false;
foreach (Fact fact in Facts)
{
if (typeof(OnLineFact).IsInstanceOfType(fact))
{
OnLineFact oLFact = (OnLineFact)fact;
if ((oLFact.Lid == id && oLFact.Pid == hit.transform.gameObject.GetComponent<FactObject>().Id))
{
exists = true;
break;
}
}
}
if (!exists)
{
oLid = GetFirstEmptyID();
var olF = new OnLineFact(oLid, hit.transform.gameObject.GetComponent<FactObject>().Id, id);
Facts.Insert(oLid, olF);
}
}
return Facts.Find(x => x.Id == id) as RayFact;
}
......@@ -122,7 +166,8 @@ public void OnToolModeChanged(ToolMode ActiveToolMode)
{
GameObject gO = fact.Representation;
if ((gO.layer == LayerMask.NameToLayer("Line")))
if (gO == null) continue;
if ((gO.layer == LayerMask.NameToLayer("Ray")))
gO.GetComponentInChildren<Collider>().enabled = true;
}
break;
......@@ -136,7 +181,8 @@ public void OnToolModeChanged(ToolMode ActiveToolMode)
foreach (Fact fact in Facts)
{
GameObject gO = fact.Representation;
if (gO.layer == LayerMask.NameToLayer("Line") || gO.layer == LayerMask.NameToLayer("Angle"))
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;
}
......@@ -155,6 +201,7 @@ public void OnToolModeChanged(ToolMode ActiveToolMode)
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;
......@@ -291,7 +338,16 @@ public void OnHit(RaycastHit hit)
{
//If Left-Mouse-Button was pressed in MarkPointMode
case ToolMode.MarkPointMode:
CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(hit, this.GetFirstEmptyID()));
var pid = this.GetFirstEmptyID();
CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(hit,pid ));
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ray")){
var oLid = GetFirstEmptyID();
Facts.Insert(oLid, new OnLineFact(oLid, pid, hit.transform.GetComponent<FactObject>().Id));
}
break;
//same as for linemode atm
......@@ -313,7 +369,11 @@ public void OnHit(RaycastHit hit)
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;
......
......@@ -116,7 +116,7 @@ public void SpawnRay(RayFact lineFact)
point2 += dir * 100;
//Change FactRepresentation to Line
this.FactRepresentation = (GameObject)Resources.Load("Prefabs/Line", typeof(GameObject));
this.FactRepresentation = (GameObject)Resources.Load("Prefabs/Ray", typeof(GameObject));
GameObject line = GameObject.Instantiate(FactRepresentation);
//Place the Line in the centre of the two points
line.transform.position = Vector3.Lerp(point1, point2, 0.5f);
......
......@@ -68,10 +68,10 @@ void Update()
// Debug.Log(Hit.transform.tag);
if (Hit.collider.transform.CompareTag("SnapZone"))
{
if(Hit.collider.gameObject.layer == LayerMask.NameToLayer("Line")){
if(Hit.collider.gameObject.layer == LayerMask.NameToLayer("Ray")){
int id = Hit.collider.gameObject.GetComponent<FactObject>().Id;
LineFact lineFact = CommunicationEvents.Facts.Find((x => x.Id == id)) as LineFact;
RayFact lineFact = CommunicationEvents.Facts.Find((x => x.Id == id)) as RayFact;
PointFact p1 = CommunicationEvents.Facts.Find((x => x.Id == lineFact.Pid1)) as PointFact;
PointFact p2 = CommunicationEvents.Facts.Find((x => x.Id == lineFact.Pid2)) as PointFact;
......
......@@ -13,6 +13,8 @@ public class DisplayFacts : MonoBehaviour
public GameObject prefab_Distance;
public GameObject prefab_Angle;
public GameObject prefab_Default;
public GameObject prefab_OnLine;
public GameObject prefab_Line;
public int x_Start;
public int y_Start;
......@@ -65,7 +67,7 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
}
case RayFact f:
{
var obj = Instantiate(prefab_Distance, Vector3.zero, Quaternion.identity, transform);
var obj = Instantiate(prefab_Line, 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;
......@@ -89,6 +91,17 @@ private GameObject CreateDisplay(Transform transform, Fact fact)
obj.GetComponent<FactWrapper>().fact = f;
return obj;
}
case OnLineFact f:
{
var obj = Instantiate(prefab_OnLine, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Lid].Id);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid].Id);
obj.GetComponent<FactWrapper>().fact = f;
return obj;
}
default:
{
var obj = Instantiate(prefab_Default, Vector3.zero, Quaternion.identity, transform);
......
......@@ -41807,6 +41807,10 @@ MonoBehaviour:
type: 3}
prefab_Default: {fileID: 858001163752551619, guid: f019e9f67e8dab947bc60028223b6cec,
type: 3}
prefab_OnLine: {fileID: 6050914136827205310, guid: 496d04605465c7f4dba7638cc6e2dc6e,
type: 3}
prefab_Line: {fileID: 7510387096843212865, guid: d6ee990520a44954fb494468665d19e9,
type: 3}
x_Start: -125
y_Start: 475
X_Pacece_Between_Items: 105
......@@ -21,7 +21,7 @@ TagManager:
- Point
- Line
- Angle
-
- Ray
-
-
-
......
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