Example #1
0
        /// <summary>
        ///  Handle new point users place
        /// </summary>
        public void AddPoint()
        {
            if (CurrentPolygon == null || CurrentPolygon.IsFinished)
            {
                CurrentPolygon = CreateNewPolygon();
            }
            var hitPoint = GazeManager.Instance.HitPosition;
            var point    = Instantiate(PointPrefab, hitPoint, Quaternion.identity);

            point.SetRootPolygon(CurrentPolygon);
            CurrentPolygon.Points.Add(point);
            // create a line when we have more than one point
            if (CurrentPolygon.Points.Count > 1)
            {
                // determine the position and direction of the line
                var index = CurrentPolygon.Points.Count - 1;
                var line  = Instantiate(LinePrefab);
                line.SetPoints(CurrentPolygon.Points[index - 1], CurrentPolygon.Points[index]);
                line.SetRootPolygon(CurrentPolygon);
                // connect the line from the previous point to the current point
                CurrentPolygon.Points[index - 1].OutgoingEdge = line;
                point.IngoingEdge = line;
                //disable gazeObject component on last point so it is always only on last point
                GazeScaler pointGazeScaler = CurrentPolygon.Points[index - 1].GetComponent <GazeScaler>();
                if (pointGazeScaler)
                {
                    pointGazeScaler.enabled = false;
                }
            }
        }
Example #2
0
        private void deletePoint()
        {
            // if the polygon is in edit mode and this point is the last point created
            if (PolygonManager.Instance.CurrentPolygon == m_RootPolygon && !m_RootPolygon.IsFinished && m_RootPolygon.Points[m_RootPolygon.Points.Count - 1] == this)
            {
                if (m_RootPolygon.Points.Count == 1)
                {
                    Destroy(gameObject);
                    return;
                }
                // first clear the references in the polygon
                PolygonPoint previousPoint;
                if (IngoingEdge.From == this)
                {
                    previousPoint = IngoingEdge.To;
                }
                else
                {
                    previousPoint = IngoingEdge.From;
                }
                previousPoint.OutgoingEdge = null;
                m_RootPolygon.Points.Remove(this);

                // then destroy the actual gameObjects
                if (IngoingEdge)
                {
                    Destroy(IngoingEdge.gameObject);
                }
                if (OutgoingEdge)
                {
                    Destroy(OutgoingEdge.gameObject);
                }

                // enable gazeObject component on previous point again, as this is the new last point
                GazeScaler pointGazeScaler = previousPoint.GetComponent <GazeScaler>();
                if (pointGazeScaler)
                {
                    pointGazeScaler.enabled = true;
                }
                base.OnFocusExit();
                Destroy(gameObject);
            }
        }