public static CVAngle Create(CMAngle model, Transform parent, CVLineSegment segment1, CVLineSegment segment2) { var name = string.Format("angle {0}: {1} <-> {2}", model.Id, segment1.Model.Id, segment2.Model.Id); return(new GameObject(name).AddComponent <CVAngle>().Init(model, parent, segment1, segment2)); }
public CBuildLineAction(CVShape owner, CVPoint point, CVLineSegment segment, Vector3 hitPos) : base(owner) { point1 = new CVPointWrap(owner, point); this.segment = new CVSegmentWrap(owner, segment); this.hitPos = segment.Owner.CalcHitPosition(this.segment.Index, hitPos); divideAction = new CDivideLineAction(Owner, segment.Owner, this.segment.Index, this.hitPos); }
private CVAngle Init(CMAngle model, Transform parent, CVLineSegment segment1, CVLineSegment segment2) { CVPoint point = segment1.GetCommonPoint(segment2); // функция вычисления направлений линий, образующих угол Func <CVLineSegment, Vector3> getDir = segment => segment.RealDirection.normalized * (point == segment.FirstPoint ? 1 : -1); // создание обозначения угла const float radius = 0.2f; Vector3[] positions = null; if (model.IsRightAngle) { positions = CalcRightAngleContour(radius, getDir(segment1), getDir(segment2)); } else { positions = CalcAngleContour(radius, getDir(segment1), getDir(segment2)); } CreateLineRenderer(transform, positions); // привязка обозначения угла к месту угла transform.parent = parent; transform.localPosition = point.RealPosition; transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; Model = model; return(this); }
private void CreateSegment(Vector3 startPos, Vector3 endPos, int index) { var segment = CVLineSegment.Create(this, SegmentsOwner, startPos, endPos); segment.MouseDown += Segment_MouseDown; segments.Insert(index, segment); }
public CVPoint GetCommonPoint(CVLineSegment segment) { if (FirstPoint == segment.FirstPoint || FirstPoint == segment.LastPoint) { return(FirstPoint); } if (LastPoint == segment.FirstPoint || LastPoint == segment.LastPoint) { return(LastPoint); } return(null); }
// отложенная обработка события выбора отрезка private IEnumerator LineView_Selected_Coroutine(CVLine view, CVLineSegment segment) { switch (CurState) { case State.SetAngle: if (activeSegments.Count != 0 && segment.GetCommonPoint(activeSegments.Top) == null) { activeSegments.Clear(); } activeSegments.ToXor(segment); break; case State.BuildLine: Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (curAction != null && curAction.IsDone) { curAction.Undo(); yield return(null); } RaycastHit raycastHit = new RaycastHit(); if (activePoints.Top != null && Physics.Raycast(ray, out raycastHit)) { CVLineSegment correctSegment = raycastHit.transform.gameObject.GetComponent <CVLineSegment>(); curAction = new CBuildLineAction(this, activePoints.Top, correctSegment, raycastHit.point); curAction.Do(); } break; case State.DivideLine: activeSegments.ToXor(segment); break; case State.Static: break; } yield return(null); }
// обработчик события выбора отрезка private void LineView_Selected(CVLine view, CVLineSegment segment) { StartCoroutine(LineView_Selected_Coroutine(view, segment)); }
public CAngleSettingAction(CVShape owner, CVLineSegment segment1, CVLineSegment segment2, int?angle = null) : base(owner) { this.segment1 = new CVSegmentWrap(Owner, segment1); this.segment2 = new CVSegmentWrap(Owner, segment2); this.angle = angle; }
public CDivideLineAction(CVShape owner, CVLineSegment segment, Vector3 pointPosition) : this(owner, segment.Owner, segment.IndexInLine, pointPosition) { }
public CDivideLineAction(CVShape owner, CVLineSegment segment, float ratio) : this(owner, segment.Owner, segment.IndexInLine, ratio) { }
public CVSegmentWrap(CVShape owner, CVLineSegment segment) : this(owner, segment.Model.Id, segment.IndexInLine) { }
public int SegmentIndex(CVLineSegment lineSegment) { return(segments.IndexOf(lineSegment)); }