void AddWaypoint(int x, int y, ref Waypoint waypointCurrent, ref Waypoint waypointPrevious) { GameObject gameObject = Instantiate(waypointObject, MapToUnityPosition(MapPositionToGridPosition(x, y)), Quaternion.identity); waypointCurrent = gameObject.GetComponent <Waypoint>(); if (waypointPrevious != null) { waypointPrevious.AddNextWaypoint(waypointCurrent); waypointCurrent.AddPreviousWaypoint(waypointPrevious); } walkableFields.Add(waypointCurrent); waypointPrevious = waypointCurrent; waypointCurrent.transform.parent = transform; }
void BuildBoardWaypoints() { Waypoint waypointPrev = null; Waypoint waypointCurrent = null; // Predefined walkable fields for current map // // top: left -> right for (int i = 3; i < 14; ++i) { AddWaypoint(i, 1, ref waypointCurrent, ref waypointPrev); } // right: top -> bottom for (int i = 1; i < 4; ++i) { AddWaypoint(14, i, ref waypointCurrent, ref waypointPrev); } // Save waypoint for later Waypoint waypointPrevTemp = waypointPrev; Waypoint waypointCurrentTemp = waypointCurrent; // build Violet home path for (int i = 13; i > 8; --i) { AddWaypoint(i, 3, ref waypointCurrent, ref waypointPrev); waypointCurrent.UseBy(Player.Type.Violet); } // Restore waypoints waypointPrev = waypointPrevTemp; waypointCurrent = waypointCurrentTemp; // right: top -> bottom for (int i = 4; i < 5; ++i) { AddWaypoint(14, i, ref waypointCurrent, ref waypointPrev); } for (int i = 14; i > 12; --i) { AddWaypoint(i, 5, ref waypointCurrent, ref waypointPrev); } violetPlayer.entry = waypointCurrent; for (int i = 5; i < 7; ++i) { AddWaypoint(12, i, ref waypointCurrent, ref waypointPrev); } // bottom: right -> left for (int i = 12; i > 1; --i) { AddWaypoint(i, 7, ref waypointCurrent, ref waypointPrev); } // left: bottom -> top for (int i = 7; i > 4; --i) { AddWaypoint(1, i, ref waypointCurrent, ref waypointPrev); } // Save waypoint for later waypointPrevTemp = waypointPrev; waypointCurrentTemp = waypointCurrent; // build Violet home path for (int i = 2; i < 7; ++i) { AddWaypoint(i, 5, ref waypointCurrent, ref waypointPrev); waypointCurrent.UseBy(Board.Player.Type.Mint); } // Restore waypoints waypointPrev = waypointPrevTemp; waypointCurrent = waypointCurrentTemp; AddWaypoint(1, 4, ref waypointCurrent, ref waypointPrev); for (int i = 1; i < 3; ++i) { AddWaypoint(i, 3, ref waypointCurrent, ref waypointPrev); } mintPlayer.entry = waypointCurrent; for (int i = 3; i > 1; --i) { AddWaypoint(3, i, ref waypointCurrent, ref waypointPrev); } // Connect with begine waypointCurrent.AddNextWaypoint(walkableFields[0]); walkableFields[0].AddPreviousWaypoint(waypointCurrent); }