Skip to content
Snippets Groups Projects
Commit b057f217 authored by Richard Marcus's avatar Richard Marcus
Browse files

snapzone spanws 90degree angle to the sky

parent 9baedaf6
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ void Start()
{
CommunicationEvents.ToolModeChangedEvent.AddListener(OnToolModeChanged);
CommunicationEvents.TriggerEvent.AddListener(OnHit);
CommunicationEvents.SnapEvent.AddListener(Rocket);
//We dont want to have this here anymore...
//CommunicationEvents.RemoveFactEvent.AddListener(DeleteFact);
......@@ -175,6 +176,42 @@ public void OnToolModeChanged(ToolMode ActiveToolMode)
}
}
//automatic 90 degree angle construction
public void Rocket(RaycastHit hit)
{
int idA, idB, idC;
//usual point
idA = this.GetFirstEmptyID();
CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(hit, idA));
//second point
idB = this.GetFirstEmptyID();
var shiftedHit = hit;
var playerPos = Camera.main.transform.position;
playerPos.y = hit.point.y;
shiftedHit.point = playerPos;
CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(shiftedHit, idB));
//third point with unknown height
idC = this.GetFirstEmptyID();
var skyHit = hit;
skyHit.point += Vector3.up * 20;
CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(skyHit, idC));
//lines
CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(idA, idB, this.GetFirstEmptyID()));
//lines
CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(idA, idC, this.GetFirstEmptyID()));
//90degree angle
CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(idB,idA,idC, GetFirstEmptyID()));
}
public void OnHit(RaycastHit hit)
{
......@@ -210,6 +247,22 @@ public void OnHit(RaycastHit hit)
}
}
//If no Point was hit
else if(Input.GetKey(KeyCode.LeftShift))
{
if (this.lineModeIsFirstPointSelected)
{
//Event for end of line-drawing in "ShinyThings"
int id = this.GetFirstEmptyID();
CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(hit,id ));
CommunicationEvents.StopLineDrawingEvent.Invoke(null);
//Create LineFact
CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(this.lineModeFirstPointSelected.Id,id, this.GetFirstEmptyID()));
this.lineModeIsFirstPointSelected = false;
this.lineModeFirstPointSelected = null;
}
}
else
{
if (this.lineModeIsFirstPointSelected)
......
......@@ -44,7 +44,7 @@ public class ShinyEvent : UnityEvent<Fact> {
public static HitEvent SnapEvent = new HitEvent();
public static HitEvent TriggerEvent = new HitEvent();
public static ToolModeEvent ToolModeChangedEvent = new ToolModeEvent();
......
......@@ -72,9 +72,18 @@ void CheckMouseButtons(bool OnSnap=false)
if (Input.GetMouseButtonDown(0))
{
if (EventSystem.current.IsPointerOverGameObject()) return; //this prevents rays from shooting through ui
CommunicationEvents.TriggerEvent.Invoke(Hit);
if(OnSnap) Hit.collider.enabled = false;
if (!OnSnap)
{
CommunicationEvents.TriggerEvent.Invoke(Hit);
}
else {
Hit.collider.enabled = false;
CommunicationEvents.SnapEvent.Invoke(Hit);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment