Select Git revision
FactSpawner.cs
-
John Schihada authoredJohn Schihada authored
FactSpawner.cs 9.72 KiB
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using static CommunicationEvents;
public class FactSpawner : MonoBehaviour
{
private GameObject FactRepresentation;
void Start()
{
AddFactEvent.AddListener(FactAction);
RemoveFactEvent.AddListener(DeleteObject);
//Default FactRepresenation = Sphere-Prefab for Points
this.FactRepresentation = (GameObject) Resources.Load("Prefabs/Sphere", typeof(GameObject));
}
public void FactAction(Fact fact)
{
switch (fact)
{
case PointFact pointFact:
SpawnPoint(pointFact);
break;
case LineFact lineFact:
SpawnLine(lineFact);
break;
case AngleFact angleFact:
SpawnAngle(angleFact);
break;
}
}
public void SpawnPoint(PointFact fact)
{
this.FactRepresentation = (GameObject)Resources.Load("Prefabs/Sphere", typeof(GameObject));
GameObject point = GameObject.Instantiate(FactRepresentation);
point.transform.position = fact.Point;
point.transform.up = fact.Normal;
string letter = ((Char)(64+fact.Id+1)).ToString();
point.GetComponentInChildren<TextMeshPro>().text = letter;
point.GetComponent<FactObject>().Id = fact.Id;
fact.Representation = point;
//If a new Point was spawned -> We are in MarkPointMode -> Then we want the collider to be disabled
//Hint: Thats why by now, if we mark a Point in an other mode than MarkPointMode, the
//Collider will be set disabled
if(CommunicationEvents.ActiveToolMode != ToolMode.ExtraMode)
point.GetComponentInChildren<SphereCollider>().enabled = false;
}
public void SpawnLine(LineFact lineFact)
{
Vector3 point1 = (Facts[lineFact.Pid1] as PointFact).Point;
Vector3 point2 = (Facts[lineFact.Pid2] as PointFact).Point;
//Change FactRepresentation to Line
this.FactRepresentation = (GameObject)Resources.Load("Prefabs/Line", typeof(GameObject));