Skip to content
Snippets Groups Projects
Commit bfa9a3c4 authored by John Schihada's avatar John Schihada
Browse files

Refactored DisplayFacts

parent 6ad5caa4
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using TMPro;
using static JSONManager;
public class ParsingDictionary {
......@@ -45,9 +46,16 @@ public string format(float t)
public abstract int[] getDependentFactIds();
public abstract GameObject instantiateRepresentation(GameObject prefab, Transform transform);
public abstract override bool Equals(System.Object obj);
public abstract override int GetHashCode();
public static string getLetter(int Id)
{
return ((Char)(64 + Id + 1)).ToString();
}
}
public abstract class DirectedFact : Fact
......@@ -155,6 +163,13 @@ public override int[] getDependentFactIds() {
return null;
}
public override GameObject instantiateRepresentation(GameObject prefab, Transform transform) {
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(this.Id);
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
public override bool Equals(System.Object obj)
{
//Check for null and compare run-time types.
......@@ -254,6 +269,15 @@ public override int[] getDependentFactIds()
return new int[] { Pid1, Pid2 };
}
public override GameObject instantiateRepresentation(GameObject prefab, Transform transform)
{
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[this.Pid1].Id);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[this.Pid2].Id);
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
public override bool Equals(System.Object obj)
{
//Check for null and compare run-time types.
......@@ -356,6 +380,14 @@ public override int[] getDependentFactIds()
return new int[] { Pid1, Pid2 };
}
public override GameObject instantiateRepresentation(GameObject prefab, Transform transform) {
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(this.Id);
//obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid2].Id);
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
public override bool Equals(System.Object obj)
{
//Check for null and compare run-time types.
......@@ -454,6 +486,15 @@ public override int[] getDependentFactIds()
return new int[] { Pid, Rid };
}
public override GameObject instantiateRepresentation(GameObject prefab, Transform transform)
{
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[this.Pid].Id);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[this.Rid].Id);
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
public override bool Equals(System.Object obj)
{
//Check for null and compare run-time types.
......@@ -637,6 +678,15 @@ public override int[] getDependentFactIds()
return new int[] { Pid1, Pid2, Pid3 };
}
public override GameObject instantiateRepresentation(GameObject prefab, Transform transform) {
var obj = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[this.Pid1].Id);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[this.Pid2].Id);
obj.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[this.Pid3].Id);
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
public override bool Equals(System.Object obj)
{
//Check for null and compare run-time types.
......
......@@ -15,6 +15,8 @@ public class DisplayFacts : MonoBehaviour
public GameObject prefab_OnLine;
public GameObject prefab_Line;
public Dictionary<string, GameObject> prefabDictionary;
public int x_Start;
public int y_Start;
public int X_Pacece_Between_Items;
......@@ -31,6 +33,14 @@ void Start()
AddFactEvent.AddListener(AddFact);
AnimateExistingFactEvent.AddListener(AnimateFact);
prefabDictionary = new Dictionary<string, GameObject>() {
{"PointFact", prefab_Point},
{"LineFact", prefab_Distance},
{"RayFact", prefab_Line},
{"AngleFact", prefab_Angle},
{"OnLineFact", prefab_OnLine}
};
}
public void AddFact(Fact fact) {
......@@ -51,60 +61,7 @@ string getLetter(int Id) {
private GameObject CreateDisplay(Transform transform, Fact fact)
{
switch (fact)
{
case LineFact 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 RayFact f:
{
var obj = Instantiate(prefab_Line, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(f.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:
{
var obj = Instantiate(prefab_Angle, 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.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Pid3].Id);
obj.GetComponent<FactWrapper>().fact = f;
return obj;
}
case PointFact f:
{
var obj = Instantiate(prefab_Point, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(f.Id );
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.Pid].Id);
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + getLetter(CommunicationEvents.Facts[f.Rid].Id);
obj.GetComponent<FactWrapper>().fact = f;
return obj;
}
default:
{
var obj = Instantiate(prefab_Default, Vector3.zero, Quaternion.identity, transform);
return obj;
}
}
return fact.instantiateRepresentation(prefabDictionary[fact.GetType().Name], transform);
}
public Vector3 GetPosition(int i)
......
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