Exemplo n.º 1
0
        public void OnDragPointView(PointView pointView, PointerEventData eventData)
        {
            var point  = pointView.point;
            var bridge = pointView.bridge;

            var position = GetPointOnBuildPlane(eventData);

            if (!position.HasValue)
            {
                Debug.LogWarning("No point on build plane");
                return;
            }

            if (selectedTool == Tool.Move)
            {
                point.Move(position.Value);
            }

            if (selectedTool == Tool.Build)
            {
                var startPoint = point.StartPosition;
                var stress     = Vector2.Distance(startPoint, position.Value) > bridge.maxLengths[selectedType] ? 1 : 0;
                ghostConnectionView.Setposition(startPoint, position.Value, stress);
            }
        }
Exemplo n.º 2
0
 public void OnClickPointView(PointView pointView, PointerEventData eventData)
 {
     if (selectedTool == Tool.Delete)
     {
         pointView.bridge.RemovePoint(pointView.point);
     }
 }
Exemplo n.º 3
0
        public void OnEndDragPointView(PointView pointView, PointerEventData eventData)
        {
            var point  = pointView.point;
            var bridge = pointView.bridge;

            ghostConnectionView.transform.position = new Vector3(0, 0, -1000);
            if (selectedTool == Tool.Build)
            {
                var hit = GetPointViewAt(eventData, pointView);
                if (hit != null)
                {
                    bridge.AddConnection(point, hit.point, selectedType);
                }
                else
                {
                    var position = GetPointOnBuildPlane(eventData);

                    if (position.HasValue)
                    {
                        if (Vector2.Distance(point.StartPosition, position.Value) > bridge.maxLengths[selectedType])
                        {
                            return;
                        }

                        var newPoint = bridge.AddPoint(position.Value);
                        bridge.AddConnection(point, newPoint, selectedType);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private PointView GetPointViewAt(PointerEventData eventData, PointView ignore)
        {
            var position = GetPointOnBuildPlane(eventData);

            if (!position.HasValue)
            {
                return(null);
            }

            foreach (var point in FindObjectsOfType <PointView>())
            {
                if (point == ignore)
                {
                    continue;
                }

                if (Vector2.Distance(position.Value, point.transform.position) <= 0.1)
                {
                    return(point);
                }
            }

            return(null);
        }