Пример #1
0
    /// <summary>
    /// Adds a new vertex to the current shape at the given position,
    /// or creates a new shape if it doesn't exist
    /// </summary>
    void AddShapeVertex(Vector2 position)
    {
        if (CurrentShapeToDraw == null)
        {
            // No current shape -> instantiate a new shape and add two vertices:
            // one for the initial position, and the other for the current cursor
            var prefab = _drawModeToPrefab[Mode];
            CurrentShapeToDraw      = Instantiate(prefab);
            CurrentShapeToDraw.name = "Shape " + _allShapes.Count;

            CurrentShapeToDraw.AddVertex(position);
            CurrentShapeToDraw.AddVertex(position);

            IsDrawingShape = true;

            _allShapes.Add(CurrentShapeToDraw);
        }
        else
        {
            // Current shape exists -> add vertex if finished,
            // otherwise start physics simulation and reset reference
            IsDrawingShape = !CurrentShapeToDraw.ShapeFinished;

            if (IsDrawingShape)
            {
                CurrentShapeToDraw.AddVertex(position);
            }
            else
            {
                CurrentShapeToDraw.SimulatingPhysics = true;
                CurrentShapeToDraw = null;
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Updates the current shape's latest vertex position to allow
    /// a shape to be updated with the mouse cursor and redrawn
    /// </summary>
    private void UpdateShapeVertex(Vector2 position)
    {
        if (CurrentShapeToDraw == null)
        {
            return;
        }

        CurrentShapeToDraw.UpdateShape(position);
    }
Пример #3
0
    /// <summary>
    /// Updates the current shape's latest vertex position to allow
    /// a shape to be updated with the mouse cursor and redrawn
    /// </summary>
    private void UpdateShapeVertex(Vector2 position)
    {
        if (CurrentShapeToDraw == null)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            CurrentShapeToDraw.Remove();
        }

        CurrentShapeToDraw.UpdateShape(position);
    }
Пример #4
0
    /// <summary>
    /// Adds a new vertex to the current shape at the given position,
    /// or creates a new shape if it doesn't exist
    /// </summary>
    private void AddShapeVertex(Vector2 position)
    {
        if (CurrentShapeToDraw == null)
        {
            lastPlayerTransform.position = playerVcam.transform.position;
            // No current shape -> instantiate a new shape and add two vertices:
            // one for the initial position, and the other for the current cursor
            var prefab = _drawModeToPrefab[Mode];
            CurrentShapeToDraw      = Instantiate(prefab);
            CurrentShapeToDraw.name = "Shape " + _allShapes.Count;

            CurrentShapeToDraw.AddVertex(position);
            CurrentShapeToDraw.AddVertex(position);

            CurrentShapeToDraw.SimulatingPhysics = false;

            IsDrawingShape = true;

            _allShapes.Add(CurrentShapeToDraw);
            vcam.gameObject.SetActive(true);
            playerVcam.gameObject.SetActive(false);
        }
        else
        {
            // Current shape exists -> add vertex if finished,
            // otherwise start physics simulation and reset reference
            IsDrawingShape = !CurrentShapeToDraw.ShapeFinished;

            if (IsDrawingShape)
            {
                CurrentShapeToDraw.AddVertex(position);
            }
            else
            {
                CurrentShapeToDraw.Validate();
                CurrentShapeToDraw.SimulatingPhysics = true;
                CurrentShapeToDraw = null;
                vcam.gameObject.SetActive(false);
                playerVcam.gameObject.SetActive(true);
            }
        }
    }