Exemplo n.º 1
0
    void Update()
    {
        _ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Input.GetMouseButtonDown(0))
        {
            SwitchBeam();
        }

        // switcht between build and simulation mode
        if (Input.GetButtonDown("Turn"))
        {
            if (!Physics.autoSimulation)
            {
                //Enter into simulation mode
                foreach (Beam beam in _triGrid._beams)
                {
                    if (!beam._exists)
                    {
                        beam.Destruct();
                    }
                    else
                    {
                        beam.ResetCollider();
                    }
                }
                for (int j = 0; j < _triGrid._nodes.Count; j++)
                {
                    for (int i = 0; i < _triGrid._nodes[i].Count; i++)
                    {
                        if (_triGrid._nodes[j][i]._connectedBeams == 0 &&
                            !_triGrid._nodes[j][i]._hasForce &&
                            !_triGrid._nodes[j][i]._kinematic)
                        {
                            _triGrid._nodes[j][i].Destruct();
                        }
                    }
                }

                Physics.autoSimulation = true;
            }
            else
            {
                //re-enter into building mode
                foreach (Beam beam in _triGrid._beams)
                {
                    beam.Destruct();
                }
                foreach (var list in _triGrid._nodes)
                {
                    foreach (var node in list)
                    {
                        node.Destruct();
                    }
                }
                _triGrid.Clear();
                _triGrid.MakeGrid();

                Physics.autoSimulation = false;
            }
        }
        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }

        _triGrid.Update();
    }