예제 #1
0
    private void Update()
    {
        if (currentBorder != null)
        {
            TileGenerator.DrawBorder(currentBorder, Color.green);
        }

        SolveToggle.interactable = currentTile != null && currentBorder != null;
        if (solve)
        {
            if (!solutionProcessing)
            {
                Solve();
            }
        }

        if (tileSolutionAvailable)
        {
            displaySolution();

            // see if we should compute a new test path
            if (Input.GetMouseButton(0))
            {
                // raycast to find tap point
                RaycastHit hit;
                var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                // ensure raycast hits terrain
                if (Physics.Raycast(ray, out hit))
                {
                    computeNewTestPathFromSolution(hit.point);
                }
            }
            // see if we should draw the test path
            if (testPath.Count > 0)
            {
                drawTestPath();
            }
        }

        if (unitA)
        {
            // create a test unit
            if (TestUnitA == null)
            {
                TestUnitA      = GameObject.CreatePrimitive(PrimitiveType.Cube);
                TestUnitA.name = "Unit A";
                TestUnitA.AddComponent <CCTestUnit>();
                NavSystem.TrackUnit(new CC_Unit(
                                        () => TestUnitA.GetComponent <CCTestUnit>().speed,
                                        () => TestUnitA.transform.eulerAngles.y,
                                        () => TestUnitA.transform.position.XYZtoXZ(),
                                        () => TestUnitA.GetComponent <CCTestUnit>().dimensions,
                                        () => TestUnitA.GetComponent <CCTestUnit>().falloff
                                        ));
            }
            TestUnitA.SoftSetActive(true);
        }
        else
        {
            // disable the test unit
            TestUnitA.SoftSetActive(false);
        }

        if (unitB)
        {
            // create a test unit
            if (TestUnitB == null)
            {
                TestUnitB      = GameObject.CreatePrimitive(PrimitiveType.Cube);
                TestUnitB.name = "Unit B";
                TestUnitB.AddComponent <CCTestUnit>();
                NavSystem.TrackUnit(new CC_Unit(
                                        () => TestUnitB.GetComponent <CCTestUnit>().speed,
                                        () => TestUnitB.transform.eulerAngles.y,
                                        () => TestUnitB.transform.position.XYZtoXZ(),
                                        () => TestUnitB.GetComponent <CCTestUnit>().dimensions,
                                        () => TestUnitB.GetComponent <CCTestUnit>().falloff
                                        ));
            }
            TestUnitB.SoftSetActive(true);
        }
        else
        {
            // disable the test unit
            TestUnitB.SoftSetActive(false);
        }

        if (density)
        {
            NavSystem.ForceTileUpdate();
            var tile = NavSystem.GetCCTile(currentTile.Corner);
            tilemap.BuildTexture(TextureGenerator.TextureFromMatrix(tile.rho, Color.clear, Color.blue));
            tilemap.BuildMesh(tile.h);
        }

        if (velocity)
        {
            NavSystem.ForceTileUpdate();
            displayVelocityField();
        }
    }