Select Git revision
FactSpawner.cs
FactSpawner.cs 12.49 KiB
using System;
using System.Collections;
using TMPro;
using UnityEngine;
using static CommunicationEvents;
using static GlobalBehaviour;
public class FactSpawner : MonoBehaviour
{
public GameObject
Sphere,
Line,
Ray,
Angle,
Ring,
Circle;
void Start()
{
AddFactEvent.AddListener(SpawnFactRepresentation_Wrapped);
RemoveFactEvent.AddListener(DeleteObject);
AnimateNonExistingFactEvent.AddListener(animateNonExistingFactTrigger);
}
private void SpawnFactRepresentation_Wrapped(Fact fact) => SpawnFactRepresentation(fact);
public Fact SpawnFactRepresentation(Fact fact)
{
Func<Fact, Fact> func = fact switch
{
PointFact => SpawnPoint,
LineFact => SpawnLine,
RightAngleFact => SpawnAngle, //needed for Hint System
AngleFact => SpawnAngle,
RayFact => SpawnRay,
CircleFact => SpawnRingAndCircle,
_ => null,
};
return func?.Invoke(fact);
//TODO check if the above breaks anything
//return fact switch
//{
// PointFact pointFact => SpawnPoint,
// LineFact lineFact => SpawnLine,
// AngleFact angleFact => SpawnAngle,
// RayFact rayFact => SpawnRay,
// CircleFact circleFact => SpawnRingAndCircle,
// _ => null,
//};
}
public Fact SpawnPoint(Fact pointFact)
{
PointFact fact = ((PointFact)pointFact);
GameObject point = GameObject.Instantiate(Sphere);
point.transform.position = fact.Point;
point.transform.up = fact.Normal;
point.GetComponentInChildren<TextMeshPro>().text = fact.Label;
point.GetComponent<FactObject>().URI = fact.Id;
fact.Representation = point;
return fact;
}
public Fact SpawnLine(Fact fact)