diff --git a/Assets/Scripts/InteractionEngine/Fact.cs b/Assets/Scripts/InteractionEngine/Fact.cs index 76b8e463ac19af3741da62a2e383d302fc324b7f..13e47deead6f7ed1d32281ccb6373be8f7007b73 100644 --- a/Assets/Scripts/InteractionEngine/Fact.cs +++ b/Assets/Scripts/InteractionEngine/Fact.cs @@ -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. diff --git a/Assets/Scripts/InventoryStuff/DisplayFacts.cs b/Assets/Scripts/InventoryStuff/DisplayFacts.cs index e97508f4c196283f87b373b6a8cb03db4d0a6082..3fbc3814b13eddb14aef7b3a7bca93e98e4d5807 100644 --- a/Assets/Scripts/InventoryStuff/DisplayFacts.cs +++ b/Assets/Scripts/InventoryStuff/DisplayFacts.cs @@ -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)