Ejemplo n.º 1
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))         // left click
        {
            BuildCurFlowField();
        }
        if (Input.GetMouseButtonDown(2)) // middle click
        {
            InitializeFlowField2();

            centerDiffVector = new Vector2Int(0, 0);

            Vector3 mousePos      = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f);
            Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(mousePos);
            center2DestinationIndex = curFlowField2.GetCellFromWorldPos(worldMousePos).gridIndex;
        }
        if (center != null)
        {
            // rebuild the flow field to the center
            InitializeCenterFlowField();
            centerFlowField.CreateCostField();

            Cell destinationCell = centerFlowField.GetCellFromWorldPos(center.transform.position);
            centerFlowField.CreateIntegrationField(destinationCell);

            centerFlowField.CreateFlowField();

            // for other center
            InitializeFlowField2();

            curFlowField2.CreateCostField();

            Cell destinationCell2 = MaskDestination(curFlowField2.GetCellFromWorldPos(center.transform.position));

            curFlowField2.CreateIntegrationField(destinationCell2);

            curFlowField2.CreateFlowField();
        }
        if (center2 != null)
        {
            // rebuild the flow field to the center
            InitializeCenterFlowField2();
            centerFlowField2.CreateCostField();

            Cell destinationCell = centerFlowField2.GetCellFromWorldPos(center2.transform.position);
            centerFlowField2.CreateIntegrationField(destinationCell);

            centerFlowField2.CreateFlowField();
        }
    }
Ejemplo n.º 2
0
    // flow field building for the center to follow it
    public void BuildCurFlowField()
    {
        InitializeFlowField();

        curFlowField.CreateCostField();

        Vector3 mousePos      = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f);
        Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(mousePos);

        Cell destinationCell = curFlowField.GetCellFromWorldPos(worldMousePos);

        curFlowField.CreateIntegrationField(destinationCell);

        curFlowField.CreateFlowField();

        gridDebug.DrawFlowField();

        // for other center
        InitializeFlowField2();

        curFlowField2.CreateCostField();

        Cell destinationCell2 = MaskDestination(destinationCell);

        curFlowField2.CreateIntegrationField(destinationCell2);

        curFlowField2.CreateFlowField();
    }
    void Update()
    {
        if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetMouseButtonDown(0))
        {
            //Debug.Log("Ctrl + Click");
            Vector3 mousePos      = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
            Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(mousePos);
            Cell    curCell       = curFlowField.GetCellFromWorldPos(worldMousePos);
            curCell.MakeImpassible();
        }

        else if ((Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) && Input.GetMouseButtonDown(0))
        {
            //Debug.Log("Alt + Click");
            Vector3 mousePos      = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
            Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(mousePos);
            Cell    curCell       = curFlowField.GetCellFromWorldPos(worldMousePos);
            curCell.IncreaseCost(10);
        }

        else if (Input.GetMouseButtonDown(0))
        {
            if (curFlowField == null || curFlowField.gridSize != gridSize)
            {
                InitializeFlowField();
            }
            else
            {
                curFlowField.Reset();
            }

            Stopwatch st = new Stopwatch();
            st.Start();

            curFlowField.CreateCostField();

            Vector3 mousePos      = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
            Vector3 worldMousePos = Camera.main.ScreenToWorldPoint(mousePos);
            destinationCell = curFlowField.GetCellFromWorldPos(worldMousePos);
            curFlowField.CreateIntegrationField(destinationCell);
            destinationCell.SetAsDestination();

            curFlowField.CreateFlowField();

            st.Stop();
            Debug.Log($"FFTime: {st.ElapsedMilliseconds}");

            gridDebug.DrawFlowField();
        }
    }
Ejemplo n.º 4
0
    public FlowField InitializeFlowField(Vector3 destination)
    {
        curFlowField = new FlowField(cellRadius, gridSize);
        CreateGrid();
        curFlowField.grid = grid;

        curFlowField.CreateCostField();

        Cell desti = curFlowField.GetCellFromWorldPos(destination);

        curFlowField.CreateIntegrationField(desti);
        curFlowField.CreateFlowField();

        return(curFlowField);
        //gridDebug.SetFlowField(curFlowField);
    }
Ejemplo n.º 5
0
    public void updateDirection()
    {
        InitializeFlowField();
        team1_flowfield.CreateCostField();
        team2_flowfield.CreateCostField();

        Cell destinationCell_team1 = team1_flowfield.grid[69, 10];

        team1_flowfield.CreateIntegrationField(destinationCell_team1);

        Cell destinationCell_team2 = team2_flowfield.grid[8, 10];

        team2_flowfield.CreateIntegrationField(destinationCell_team2);

        team1_flowfield.CreateFlowField();
        team2_flowfield.CreateFlowField();

        gridDebug.DrawFlowField();
    }