// 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(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (GUILayout.Button("Draw Flow Field")) { gridDebug.DrawFlowField(); } }
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(); } }
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(); }