Select Git revision
AngleTool.cs
AngleTool.cs 7.57 KiB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static CommunicationEvents;
public class AngleTool : Gadget
{
//Variables for AngleMode distinction
private bool angleModeIsFirstPointSelected = false;
private PointFact angleModeFirstPointSelected = null;
private bool angleModeIsSecondPointSelected = false;
private PointFact angleModeSecondPointSelected = null;
//Attributes for simulating the drawing of a curve
private bool curveDrawingActivated;
public WorldCursor Cursor;
public LineRenderer lineRenderer;
private List<Vector3> linePositions = new List<Vector3>();
public Material anglePreviewMaterial;
//Vertices for the Curve
private int curveDrawingVertexCount = 36;
private Vector3 curveEndPoint;
private Vector3 angleMiddlePoint;
private float curveRadius;
void Awake()
{
if (FactManager == null)
FactManager = GameObject.FindObjectOfType<FactManager>();
if (this.Cursor == null)
this.Cursor = GameObject.FindObjectOfType<WorldCursor>();
this.UiName = "Angle Mode";
CommunicationEvents.TriggerEvent.AddListener(OnHit);
}
//Initialize Gadget when enabled AND activated
void OnEnable()
{
this.Cursor.setLayerMask(~this.ignoreLayerMask.value);
this.ResetGadget();
}
public override void OnHit(RaycastHit hit)
{
if (!this.isActiveAndEnabled) return;
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point"))
{
PointFact tempFact = (PointFact)LevelFacts[hit.transform.GetComponent<FactObject>().URI];
//If two points were already selected and now the third point got selected
if (this.angleModeIsFirstPointSelected && this.angleModeIsSecondPointSelected)
{
//Create AngleFact
//Check if new Point is equal to one of the previous points -> if true -> cancel
if (!(this.angleModeFirstPointSelected.URI == tempFact.URI || this.angleModeSecondPointSelected.URI == tempFact.URI))
{
FactManager.AddAngleFact(((PointFact)this.angleModeFirstPointSelected).URI, ((PointFact)this.angleModeSecondPointSelected).URI, ((PointFact)tempFact).URI);
}
ResetGadget();
}
//If only one point was already selected
else if (this.angleModeIsFirstPointSelected && !this.angleModeIsSecondPointSelected)
{
//Check if the 2 selected points are the same: If not
if (this.angleModeFirstPointSelected.URI != tempFact.URI)