Beispiel #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;
            }
        }
    }
    /// <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);
            }
        }
    }