Skip to content
Snippets Groups Projects
DisplayFacts.cs 4.65 KiB
Newer Older
  • Learn to ignore specific revisions
  • BenniHome's avatar
    BenniHome committed
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    using TMPro;
    
    BenniHome's avatar
    BenniHome committed
    
    public class DisplayFacts : MonoBehaviour
    {
    
        public HashSet<int> displayedFacts = new HashSet<int>();
    
    BenniHome's avatar
    BenniHome committed
    
    
        public GameObject prefab_Point;
        public GameObject prefab_Distance;
        public GameObject prefab_Angle;
        public GameObject prefab_Default;
    
        public GameObject prefab_OnLine;
        public GameObject prefab_Line;
    
    BenniHome's avatar
    BenniHome committed
    
        public int x_Start;
        public int y_Start;
        public int X_Pacece_Between_Items;
        public int y_Pacece_Between_Items;
        public int number_of_Column;
        // Start is called before the first frame update
        void Start()
        {
            //CreateDisplay();
        }
    
        // Update is called once per frame
        void Update()
        {
    
    BenniHome's avatar
    BenniHome committed
        }
    
    
        public void UpdateDisplay2()
        {
            List<Fact>.Enumerator enumerator = CommunicationEvents.Facts.GetEnumerator();
            while (enumerator.MoveNext())
            {
                int fid = enumerator.Current.Id;
                if (displayedFacts.Contains(fid))
                {
                    continue;
    
    BenniHome's avatar
    BenniHome committed
                }
    
                var obj = CreateDisplay(transform, enumerator.Current);
                obj.GetComponent<RectTransform>().localPosition = GetPosition(fid);
                displayedFacts.Add(fid);
    
    BenniHome's avatar
    BenniHome committed
            }
    
    BenniHome's avatar
    BenniHome committed
        }
    
    Benjamin Bösl's avatar
    Benjamin Bösl committed
        string getLetter(int Id) {
            return ((Char)(64 + Id + 1)).ToString();
        }
    
    BenniHome's avatar
    BenniHome committed
    
    
        private GameObject CreateDisplay(Transform transform, Fact fact)
    
    BenniHome's avatar
    BenniHome committed
        {
    
            switch (fact)
            {
                case LineFact f:
                    {
                        var obj = Instantiate(prefab_Distance, Vector3.zero, Quaternion.identity, transform);
    
    Benjamin Bösl's avatar
    Benjamin Bösl committed
                        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(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:
                    {
                        var obj = Instantiate(prefab_Angle, Vector3.zero, Quaternion.identity, transform);
    
    Benjamin Bösl's avatar
    Benjamin Bösl committed
                        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);
    
    Benjamin Bösl's avatar
    Benjamin Bösl committed
                        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.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);
                        return obj;
                    }
    
    
        public Vector3 GetPosition(int i)
        {
            return new Vector3(x_Start + (X_Pacece_Between_Items * (i % number_of_Column)), y_Start + (-y_Pacece_Between_Items * (i / number_of_Column)), 0f);
        }
    
    
    BenniHome's avatar
    BenniHome committed
    }