public override void OnHit(RaycastHit hit) { if (!this.isActiveAndEnabled) { return; } if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point")) { Fact tempFact = StageStatic.stage.factState[hit.transform.GetComponent <FactObject>().URI]; //If first point was already selected AND second point != first point if (this.LineModeIsFirstPointSelected && this.LineModeFirstPointSelected.Id != tempFact.Id) { //Create LineFact FactManager.AddRayFact(this.LineModeFirstPointSelected.Id, tempFact.Id); this.ResetGadget(); } else { //Activate LineDrawing for preview this.LineModeIsFirstPointSelected = true; this.LineModeFirstPointSelected = tempFact; this.ActivateLineDrawing(); } } //if we hit the top snap zone //TODO: check behaviour else if (hit.transform.gameObject.CompareTag("SnapZone")) { if (this.LineModeIsFirstPointSelected) { RaycastHit downHit; if (Physics.Raycast(hit.transform.gameObject.transform.position - Vector3.down * 2, Vector3.down, out downHit)) { //Create LineFact var idA = downHit.transform.gameObject.GetComponent <FactObject>().URI; var idB = this.LineModeFirstPointSelected.Id; FactManager.AddAngleFact(idA, idB, FactManager.AddPointFact(hit).Id); this.ResetGadget(); } } } //If no Point was hit else { if (this.LineModeIsFirstPointSelected) { //Deactivate LineDrawing and first point selection this.ResetGadget(); } //TODO: Hint that only a line can be drawn between already existing points } }
public override void OnHit(RaycastHit hit) { if (!this.isActiveAndEnabled) { return; } if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point")) { PointFact tempFact = (PointFact)StageStatic.stage.factState[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.Id == tempFact.Id || this.angleModeSecondPointSelected.Id == tempFact.Id)) { FactManager.AddAngleFact(((PointFact)this.angleModeFirstPointSelected).Id, ((PointFact)this.angleModeSecondPointSelected).Id, ((PointFact)tempFact).Id); } 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.Id != tempFact.Id) { this.angleModeIsSecondPointSelected = true; this.angleModeSecondPointSelected = tempFact; ActivateCurveDrawing(); } else { this.angleModeFirstPointSelected = null; this.angleModeIsFirstPointSelected = false; } } //If no point was selected before else { //Save the first point selected this.angleModeIsFirstPointSelected = true; this.angleModeFirstPointSelected = tempFact; } } //No point was hit else { ResetGadget(); //TODO: Hint that only an angle can be created between 3 already existing points } }
public override void OnHit(RaycastHit hit) { void CreateRayAndAngles(string pidIntersectionPoint, string pidLotPoint, bool samestep) { FactManager.AddRayFact(pidIntersectionPoint, pidLotPoint, samestep); //TODO: create at all? / for all points on basline? FactManager.AddAngleFact( this.LotModeLineSelected.Pid1 == pidIntersectionPoint ? this.LotModeLineSelected.Pid2 : this.LotModeLineSelected.Pid1, pidIntersectionPoint, pidLotPoint, true); } if (!this.isActiveAndEnabled) { return; } //If LotPoint is on baseLine if (this.LotModeIsPointSelected && (hit.transform.gameObject.layer == LayerMask.NameToLayer("Default") || hit.transform.gameObject.layer == LayerMask.NameToLayer("Tree"))) { Vector3 LotPoint = Math3d.ProjectPointOnLine(hit.point, this.LotModeLineSelected.Dir, this.LotModeIntersectionPoint.Point); //TODO: which normal? CreateRayAndAngles(this.LotModeIntersectionPoint.Id, FactManager.AddPointFact(LotPoint, hit.normal).Id, true); this.ResetGadget(); } //If baseline already selected and point selected else if (this.LotModeIsLineSelected && !this.LotModeIsPointSelected && hit.transform.gameObject.layer == LayerMask.NameToLayer("Point")) { PointFact tempFact = StageStatic.stage.factState[hit.transform.GetComponent <FactObject>().URI] as PointFact; Vector3 intersectionPoint = Math3d.ProjectPointOnLine(this.LotModeLinePointA.Point, this.LotModeLineSelected.Dir, tempFact.Point); if (intersectionPoint == tempFact.Point) // Vector3.operator== tests for almost Equal() { //TempFact is on baseLine this.LotModeIsPointSelected = true; this.LotModeIntersectionPoint = tempFact; return; } //TODO: test Facts existance //add Facts var intersectionId = FactManager.AddPointFact(intersectionPoint, this.LotModeLineHit.normal).Id; if (this.LotModeLineSelected is RayFact) //Add OnLineFact only on Ray not Line { FactManager.AddOnLineFact(intersectionId, this.LotModeLineSelected.Id, true); } CreateRayAndAngles(intersectionId, tempFact.Id, true); this.ResetGadget(); } //If nothing yet selected else if (!this.LotModeIsLineSelected && (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ray") || hit.transform.gameObject.layer == LayerMask.NameToLayer("Line"))) { Fact tempFact = StageStatic.stage.factState[hit.transform.GetComponent <FactObject>().URI]; //Activate LineDrawing for preview this.LotModeIsLineSelected = true; this.LotModeLineSelected = tempFact as AbstractLineFact; this.LotModeLinePointA = (PointFact)StageStatic.stage.factState[this.LotModeLineSelected.Pid1]; this.LotModeLineHit = hit; this.ActivateLineDrawing(); } //unexpected usage else { if (this.LotModeIsLineSelected) { //Deactivate LineDrawing and first point selection this.ResetGadget(); } } }