public void AdvancedShapeShouldReturnLSingleWhenHasThreeConsecutiveConnections() { AdjacencyMap adjacencyMapNorthEast = new AdjacencyMap(); adjacencyMapNorthEast.SetConnection(Direction.North, existingConnection); adjacencyMapNorthEast.SetConnection(Direction.NorthEast, existingConnection); adjacencyMapNorthEast.SetConnection(Direction.East, existingConnection); AdjacencyMap adjacencyMapSouthEast = new AdjacencyMap(); adjacencyMapSouthEast.SetConnection(Direction.South, existingConnection); adjacencyMapSouthEast.SetConnection(Direction.SouthEast, existingConnection); adjacencyMapSouthEast.SetConnection(Direction.East, existingConnection); AdjacencyMap adjacencyMapSouthWest = new AdjacencyMap(); adjacencyMapSouthWest.SetConnection(Direction.South, existingConnection); adjacencyMapSouthWest.SetConnection(Direction.SouthWest, existingConnection); adjacencyMapSouthWest.SetConnection(Direction.West, existingConnection); AdjacencyMap adjacencyMapNorthWest = new AdjacencyMap(); adjacencyMapNorthWest.SetConnection(Direction.North, existingConnection); adjacencyMapNorthWest.SetConnection(Direction.NorthWest, existingConnection); adjacencyMapNorthWest.SetConnection(Direction.West, existingConnection); AdjacencyShape resultNorthEast = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapNorthEast); AdjacencyShape resultSouthEast = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapSouthEast); AdjacencyShape resultSouthWest = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapSouthWest); AdjacencyShape resultNorthWest = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapNorthWest); Assert.IsTrue(resultNorthEast == AdjacencyShape.LSingle); Assert.IsTrue(resultSouthEast == AdjacencyShape.LSingle); Assert.IsTrue(resultSouthWest == AdjacencyShape.LSingle); Assert.IsTrue(resultNorthWest == AdjacencyShape.LSingle); }
public void AdvancedShapeShouldReturnXOppositeWhenHasFourOrthogonalAndTwoOppositeDiagonalConnections() { AdjacencyMap adjacencyMap1 = new AdjacencyMap(); adjacencyMap1.SetConnection(Direction.North, existingConnection); adjacencyMap1.SetConnection(Direction.East, existingConnection); adjacencyMap1.SetConnection(Direction.South, existingConnection); adjacencyMap1.SetConnection(Direction.West, existingConnection); adjacencyMap1.SetConnection(Direction.NorthEast, existingConnection); adjacencyMap1.SetConnection(Direction.SouthWest, existingConnection); AdjacencyMap adjacencyMap2 = new AdjacencyMap(); adjacencyMap2.SetConnection(Direction.North, existingConnection); adjacencyMap2.SetConnection(Direction.East, existingConnection); adjacencyMap2.SetConnection(Direction.South, existingConnection); adjacencyMap2.SetConnection(Direction.West, existingConnection); adjacencyMap2.SetConnection(Direction.NorthWest, existingConnection); adjacencyMap2.SetConnection(Direction.SouthEast, existingConnection); AdjacencyShape result1 = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap1); AdjacencyShape result2 = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap2); Assert.IsTrue(result1 == AdjacencyShape.XOpposite); Assert.IsTrue(result2 == AdjacencyShape.XOpposite); }
public void SimpleShapeShouldReturnLWhenHasTwoAdjacentOrthogonalConnections() { AdjacencyMap adjacencyMapNorthEast = new AdjacencyMap(); adjacencyMapNorthEast.SetConnection(Direction.North, existingConnection); adjacencyMapNorthEast.SetConnection(Direction.East, existingConnection); AdjacencyMap adjacencyMapSouthEast = new AdjacencyMap(); adjacencyMapSouthEast.SetConnection(Direction.South, existingConnection); adjacencyMapSouthEast.SetConnection(Direction.East, existingConnection); AdjacencyMap adjacencyMapSouthWest = new AdjacencyMap(); adjacencyMapSouthWest.SetConnection(Direction.South, existingConnection); adjacencyMapSouthWest.SetConnection(Direction.West, existingConnection); AdjacencyMap adjacencyMapNorthWest = new AdjacencyMap(); adjacencyMapNorthWest.SetConnection(Direction.North, existingConnection); adjacencyMapNorthWest.SetConnection(Direction.West, existingConnection); AdjacencyShape resultNorthEast = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapNorthEast); AdjacencyShape resultSouthEast = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapSouthEast); AdjacencyShape resultSouthWest = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapSouthWest); AdjacencyShape resultNorthWest = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapNorthWest); Assert.IsTrue(resultNorthEast == AdjacencyShape.L); Assert.IsTrue(resultSouthEast == AdjacencyShape.L); Assert.IsTrue(resultSouthWest == AdjacencyShape.L); Assert.IsTrue(resultNorthWest == AdjacencyShape.L); }
public Dictionary <string, bool> ResolveWords(PrefixTree dictionary, DieFace[] currentBoard) { int[,] nodes = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 0xA, 0xB, 0xC }, { 0xD, 0xE, 0xF, 0x10 } }; var letters = new char[4, 4]; int x = 0; int y = 0; foreach (var dieFace in currentBoard) { letters[x, y++] = dieFace.FaceCharacter[0]; if (y == 4) { y = 0; x++; } } wordList = new Dictionary <string, bool>(); dict = dictionary; graph = BuildGraph <char>(nodes, letters); foreach (var t in nodes) { AdjacencyNode node = graph.map[t]; node.Visted = 1; Debug.Assert(index == 0); word[index] = node.NodeContent; BuildCombinations(node, word); node.Visted = 0; word[index + 1] = (char)0; } return(wordList); }
public void OffsetShapeShouldReturn0WhenNoConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); AdjacencyShape result = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.O); }
//Initializes the Map. public void InitMap() { Global.MapFlyWeight = this; Dictionary <Vector3Int, GameObject> HeavyMap = new Dictionary <Vector3Int, GameObject>(new MapEqualityComparer()); Vector3 Q = new Vector3(Mathf.PI / 3.0f, 0, 0.5f); // 60* axis Vector3 R = new Vector3(-Mathf.PI / 3.0f, 0, 0.5f); // 120* axis Vector3 S = new Vector3(0, 0, -1); // 180* axis Quaternion rotation = Quaternion.Euler(-90, 0, 0); // Because the model is 90 degrees rotated. for (int i = -radius; i <= radius; i++) { for (int j = -radius; j <= radius; j++) { for (int k = -radius; k <= radius; k++) { float gapChance = 0.125f; if (i + j + k == 0 && Random.value < 1.0f - gapChance) { Vector3Int key = new Vector3Int(i, j, k); // Beware order of operations. Vector3 position = ((Q * i) + (R * j) + (S * k)); position = new Vector3(position.x * 0.85f, 0, position.z); GameObject Hex = Instantiate(hexPrefab, position, rotation); // Subscribes HexEntity's updateTurn function to GM's NextTurn event. Global.GM.HexUpdate += Hex.GetComponent <HexEntity>().updateTurn; Hex.AddComponent <TextMesh>(); if (LabelHexes) { TextMesh text = Hex.GetComponent <TextMesh>(); text.text = "" + key; text.characterSize = 0.1f; text.fontSize = 32; text.color = new Color(0, 0, 0); text.offsetZ = 0.1f; text.anchor = TextAnchor.MiddleCenter; } Hex.GetComponent <HexEntity>().Position = key; HeavyMap.Add(key, Hex); } } } } hexMap = HeavyMap; adjacencyMap = new AdjacencyMap(); foreach (GameObject hex in hexMap.Values) { adjacencyMap.AddVertex(hex); } }
private byte SetBitmap(bool[] items) { AdjacencyMap adjacencyMap = new AdjacencyMap(); for (Direction direction = Direction.North; direction <= Direction.NorthWest; direction++) { adjacencyMap.SetConnection(direction, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, blocked[(int)direction])); } return(adjacencyMap.SerializeToByte()); }
public void OffsetShapeShouldReturn0WhenHasOnlyDiagonalConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.NorthEast, existingConnection); adjacencyMap.SetConnection(Direction.SouthWest, existingConnection); AdjacencyShape result = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.O); }
public void OffsetShapeShouldReturnLSouthEastWhenHasAllSouthWestConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.West, existingConnection); adjacencyMap.SetConnection(Direction.SouthWest, existingConnection); adjacencyMap.SetConnection(Direction.South, existingConnection); AdjacencyShape result = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.LSouthEast); }
public void SimpleShapeShouldReturnTWhenHasThreeOrthogonalConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.North, existingConnection); adjacencyMap.SetConnection(Direction.East, existingConnection); adjacencyMap.SetConnection(Direction.South, existingConnection); AdjacencyShape result = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.T); }
public void OffsetShapeShouldReturnTNorthEastWestWhenMissingWestConnection() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.North, existingConnection); adjacencyMap.SetConnection(Direction.East, existingConnection); adjacencyMap.SetConnection(Direction.South, existingConnection); AdjacencyShape result = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.TNorthEastWest); }
public void AdvancedShapeShouldReturnTNoneWhenHasThreeOrthogonalConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.North, existingConnection); adjacencyMap.SetConnection(Direction.East, existingConnection); adjacencyMap.SetConnection(Direction.West, existingConnection); AdjacencyShape result = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.TNone); }
private AdjacencyMap BuildGraph <T>(int[,] array, char[,] arrayOfContent) { #region NEIGHBORS_ARRAY // neighbors to each node in a 4x4 matrix moving clockwise int[,] neighbors = { { 01, 11, 10, -01, -01, -01, -01, -01 }, // 0,0 { 02, 12, 11, 10, 00, -01, -01, -01 }, // 0,1 { 03, 13, 12, 11, 01, -01, -01 - 01, -01 }, // 0,2 { 13, 12, 02, -01, -01, -01, -01, -01 }, // 0,3 { 11, 21, 20, 00, 01, -01, -01, -01 }, // 1,0 { 12, 22, 21, 20, 10, 00, 01, 02 }, // 1,1 { 13, 23, 22, 21, 11, 01, 02, 03 }, // 1,2 { 23, 22, 12, 02, 03, -01, -01, -01 }, // 1,3 { 21, 31, 30, 10, 11, -01, -01, -01 }, // 2,0 { 22, 32, 31, 30, 20, 10, 11, 12 }, // 2,1 { 23, 33, 32, 31, 21, 11, 12, 13 }, // 2,2 { 33, 32, 22, 12, 13, -01, -01, -01 }, // 2,3 { 31, 20, 21, -01, -01, -01, -01, -01 }, // 3,0 { 32, 30, 20, 21, 22, -01, -01, -01 }, // 3,1 { 33, 31, 21, 22, 23, -01, -01, -01 }, // 3,2 { 32, 22, 23, -01, -01, -01, -01, -01 } // 3,3 }; #endregion var map = new AdjacencyMap(); int xx = 0; int yy = 0; int x; int y; for (x = 0; x < 4; x++) { for (y = 0; y < 4; y++) { var node = new AdjacencyNode { NodeNumber = array[x, y], Adjacency = new List <int>(), NodeContent = arrayOfContent[x, y] }; while (yy < 8 && neighbors[xx, yy] != -1) { var m = neighbors[xx, yy] / 10; var n = neighbors[xx, yy] % 10; node.Adjacency.Add(array[m, n]); ++yy; } ++xx; yy = 0; map.AddNode(node); } } return(map); }
public void SimpleShapeShouldReturnUWhenHasSingleOrthogonalAndManyDiagonalConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.North, existingConnection); adjacencyMap.SetConnection(Direction.NorthEast, existingConnection); adjacencyMap.SetConnection(Direction.SouthEast, existingConnection); adjacencyMap.SetConnection(Direction.SouthWest, existingConnection); adjacencyMap.SetConnection(Direction.NorthWest, existingConnection); AdjacencyShape result = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.U); }
public void OffsetShapeShouldReturnUSouthWhenHasSingleConnectionSouthOrWest() { AdjacencyMap adjacencyMapSouth = new AdjacencyMap(); adjacencyMapSouth.SetConnection(Direction.South, existingConnection); AdjacencyMap adjacencyMapWest = new AdjacencyMap(); adjacencyMapWest.SetConnection(Direction.West, existingConnection); AdjacencyShape resultSouth = AdjacencyShapeResolver.GetOffsetShape(adjacencyMapSouth); AdjacencyShape resultWest = AdjacencyShapeResolver.GetOffsetShape(adjacencyMapWest); Assert.IsTrue(resultSouth == AdjacencyShape.USouth); Assert.IsTrue(resultWest == AdjacencyShape.USouth); }
public void OffsetShapeShouldReturnUNorthWhenHasSingleConnectionNorthOrEast() { AdjacencyMap adjacencyMapNorth = new AdjacencyMap(); adjacencyMapNorth.SetConnection(Direction.North, existingConnection); AdjacencyMap adjacencyMapEast = new AdjacencyMap(); adjacencyMapEast.SetConnection(Direction.East, existingConnection); AdjacencyShape resultNorth = AdjacencyShapeResolver.GetOffsetShape(adjacencyMapNorth); AdjacencyShape resultEast = AdjacencyShapeResolver.GetOffsetShape(adjacencyMapEast); Assert.IsTrue(resultNorth == AdjacencyShape.UNorth); Assert.IsTrue(resultEast == AdjacencyShape.UNorth); }
public MeshDirectionInfo GetMeshAndDirection(AdjacencyMap adjacencyMap) { // Determine rotation and mesh specially for every single case. float rotation = 0.0f; Mesh mesh; AdjacencyShape shape = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap); switch (shape) { case AdjacencyShape.O: mesh = o; break; case AdjacencyShape.U: mesh = u; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleConnection()); break; case AdjacencyShape.I: mesh = i; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.HasConnection(Direction.North) ? Direction.North : Direction.East); break; case AdjacencyShape.L: mesh = l; rotation = TileHelper.AngleBetween(Direction.NorthEast, adjacencyMap.GetDirectionBetweenTwoConnections()); break; case AdjacencyShape.T: mesh = t; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.X: mesh = x; break; default: Debug.LogError($"Received unexpected shape from simple shape resolver: {shape}"); mesh = o; break; } return(new MeshDirectionInfo { Mesh = mesh, Rotation = rotation }); }
public void SimpleShapeShouldReturnIWhenHasTwoOppositeOrthogonalConnections() { AdjacencyMap adjacencyMapNorthSouth = new AdjacencyMap(); adjacencyMapNorthSouth.SetConnection(Direction.North, existingConnection); adjacencyMapNorthSouth.SetConnection(Direction.South, existingConnection); AdjacencyMap adjacencyMapEastWest = new AdjacencyMap(); adjacencyMapEastWest.SetConnection(Direction.East, existingConnection); adjacencyMapEastWest.SetConnection(Direction.West, existingConnection); AdjacencyShape resultNorthSouth = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapNorthSouth); AdjacencyShape resultEastWest = AdjacencyShapeResolver.GetSimpleShape(adjacencyMapEastWest); Assert.IsTrue(resultNorthSouth == AdjacencyShape.I); Assert.IsTrue(resultEastWest == AdjacencyShape.I); }
public void AdvancedShapeShouldReturnXQuadWhenHasFourOrthogonalAndDiagonalConnections() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.North, existingConnection); adjacencyMap.SetConnection(Direction.East, existingConnection); adjacencyMap.SetConnection(Direction.South, existingConnection); adjacencyMap.SetConnection(Direction.West, existingConnection); adjacencyMap.SetConnection(Direction.NorthEast, existingConnection); adjacencyMap.SetConnection(Direction.SouthEast, existingConnection); adjacencyMap.SetConnection(Direction.SouthWest, existingConnection); adjacencyMap.SetConnection(Direction.NorthWest, existingConnection); AdjacencyShape result = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); Assert.IsTrue(result == AdjacencyShape.XQuad); }
public void TransferHexOwner(GameObject hexObject, Player transferTo) { HexEntity hex = hexObject.GetComponent <HexEntity>(); Player transferFrom = hex.Controller; hex.Controller = transferTo; if (transferFrom != null && playerAdjacencyMaps.ContainsKey(transferFrom)) { transferFrom.UnregisterAllMatchedOrders(hex); playerAdjacencyMaps[transferFrom].RemoveVertex(hexObject); } if (!playerAdjacencyMaps.ContainsKey(transferTo)) { playerAdjacencyMaps[transferTo] = new AdjacencyMap(); } playerAdjacencyMaps[transferTo].AddVertex(hexObject); transferFrom.RefreshAllArmies(); }
public void AdvancedShapeShouldReturnXSingleWhenHasFourOrthogonalAndOneDiagonalConnection() { AdjacencyMap adjacencyMapNorthEast = new AdjacencyMap(); adjacencyMapNorthEast.SetConnection(Direction.North, existingConnection); adjacencyMapNorthEast.SetConnection(Direction.East, existingConnection); adjacencyMapNorthEast.SetConnection(Direction.South, existingConnection); adjacencyMapNorthEast.SetConnection(Direction.West, existingConnection); adjacencyMapNorthEast.SetConnection(Direction.NorthEast, existingConnection); AdjacencyMap adjacencyMapNorthWest = new AdjacencyMap(); adjacencyMapNorthWest.SetConnection(Direction.North, existingConnection); adjacencyMapNorthWest.SetConnection(Direction.East, existingConnection); adjacencyMapNorthWest.SetConnection(Direction.South, existingConnection); adjacencyMapNorthWest.SetConnection(Direction.West, existingConnection); adjacencyMapNorthWest.SetConnection(Direction.NorthWest, existingConnection); AdjacencyMap adjacencyMapSouthEast = new AdjacencyMap(); adjacencyMapSouthEast.SetConnection(Direction.North, existingConnection); adjacencyMapSouthEast.SetConnection(Direction.East, existingConnection); adjacencyMapSouthEast.SetConnection(Direction.South, existingConnection); adjacencyMapSouthEast.SetConnection(Direction.West, existingConnection); adjacencyMapSouthEast.SetConnection(Direction.SouthEast, existingConnection); AdjacencyMap adjacencyMapSouthWest = new AdjacencyMap(); adjacencyMapSouthWest.SetConnection(Direction.North, existingConnection); adjacencyMapSouthWest.SetConnection(Direction.East, existingConnection); adjacencyMapSouthWest.SetConnection(Direction.South, existingConnection); adjacencyMapSouthWest.SetConnection(Direction.West, existingConnection); adjacencyMapSouthWest.SetConnection(Direction.SouthWest, existingConnection); AdjacencyShape resultNorthEast = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapNorthEast); AdjacencyShape resultNorthWest = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapNorthWest); AdjacencyShape resultSouthEast = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapSouthEast); AdjacencyShape resultSouthWest = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapSouthWest); Assert.IsTrue(resultNorthEast == AdjacencyShape.XSingle); Assert.IsTrue(resultNorthWest == AdjacencyShape.XSingle); Assert.IsTrue(resultSouthEast == AdjacencyShape.XSingle); Assert.IsTrue(resultSouthWest == AdjacencyShape.XSingle); }
public void AdvancedShapeShouldReturnTNoneWhenHasThreeOrthogonalAndOneOppositeDiagonalConnection() { AdjacencyMap adjacencyMapL = new AdjacencyMap(); adjacencyMapL.SetConnection(Direction.North, existingConnection); adjacencyMapL.SetConnection(Direction.East, existingConnection); adjacencyMapL.SetConnection(Direction.West, existingConnection); adjacencyMapL.SetConnection(Direction.SouthWest, existingConnection); AdjacencyMap adjacencyMapR = new AdjacencyMap(); adjacencyMapR.SetConnection(Direction.North, existingConnection); adjacencyMapR.SetConnection(Direction.East, existingConnection); adjacencyMapR.SetConnection(Direction.West, existingConnection); adjacencyMapR.SetConnection(Direction.SouthEast, existingConnection); AdjacencyShape resultL = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapL); AdjacencyShape resultR = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMapR); Assert.IsTrue(resultL == AdjacencyShape.TNone); Assert.IsTrue(resultR == AdjacencyShape.TNone); }
public void SimpleShapeShouldReturnUWhenSingleOrthogonalConnection() { AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.SetConnection(Direction.North, existingConnection); AdjacencyShape resultN = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap); adjacencyMap.SetConnection(Direction.North, missingConnection); adjacencyMap.SetConnection(Direction.East, existingConnection); AdjacencyShape resultE = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap); adjacencyMap.SetConnection(Direction.East, missingConnection); adjacencyMap.SetConnection(Direction.South, existingConnection); AdjacencyShape resultS = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap); adjacencyMap.SetConnection(Direction.South, missingConnection); adjacencyMap.SetConnection(Direction.West, existingConnection); AdjacencyShape resultW = AdjacencyShapeResolver.GetSimpleShape(adjacencyMap); Assert.IsTrue(resultN == AdjacencyShape.U); Assert.IsTrue(resultE == AdjacencyShape.U); Assert.IsTrue(resultS == AdjacencyShape.U); Assert.IsTrue(resultW == AdjacencyShape.U); }
public MeshDirectionInfo GetMeshAndDirection(AdjacencyMap adjacencyMap) { float rotation = 0.0f; Mesh mesh; AdjacencyShape shape = AdjacencyShapeResolver.GetAdvancedShape(adjacencyMap); switch (shape) { case AdjacencyShape.O: mesh = o; break; case AdjacencyShape.U: mesh = u; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleConnection()); break; case AdjacencyShape.I: mesh = i; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.HasConnection(Direction.North) ? Direction.North : Direction.East); break; case AdjacencyShape.LNone: mesh = lNone; rotation = TileHelper.AngleBetween(Direction.NorthEast, adjacencyMap.GetDirectionBetweenTwoConnections()); break; case AdjacencyShape.LSingle: mesh = lSingle; rotation = TileHelper.AngleBetween(Direction.NorthEast, adjacencyMap.GetDirectionBetweenTwoConnections()); break; case AdjacencyShape.TNone: mesh = tNone; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.TSingleLeft: mesh = tSingleLeft; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.TSingleRight: mesh = tSingleRight; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.TDouble: mesh = tDouble; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.XNone: mesh = xNone; break; case AdjacencyShape.XSingle: mesh = xSingle; Direction connectingDiagonal = adjacencyMap.GetSingleConnection(false); rotation = connectingDiagonal == Direction.NorthEast ? 0f : connectingDiagonal == Direction.SouthEast ? 90f : connectingDiagonal == Direction.SouthWest ? 180f : -90f; break; case AdjacencyShape.XOpposite: mesh = xOpposite; rotation = adjacencyMap.HasConnection(Direction.NorthEast) ? 0f : 90f; break; case AdjacencyShape.XSide: mesh = xSide; rotation = TileHelper.AngleBetween(Direction.NorthWest, adjacencyMap.GetDirectionBetweenTwoConnections(false)) - 45f; break; case AdjacencyShape.XTriple: mesh = xTriple; Direction nonConnectingDiagonal = adjacencyMap.GetSingleNonConnection(false); rotation = nonConnectingDiagonal == Direction.NorthEast ? -90f : nonConnectingDiagonal == Direction.SouthEast ? 0f : nonConnectingDiagonal == Direction.SouthWest ? 90f : 180f; break; case AdjacencyShape.XQuad: mesh = xQuad; break; default: Debug.LogError($"Received unexpected shape from advanced shape resolver: {shape}"); mesh = o; break; } //If someone knows of a more elegant way to do the same without switching the same variable twice, I'd like to hear it :) if (opaque) { switch (shape) { case AdjacencyShape.U: viewObstacles[0].SetActive(false); viewObstacles[1].SetActive(false); viewObstacles[2].SetActive(true); viewObstacles[3].SetActive(false); break; case AdjacencyShape.I: viewObstacles[0].SetActive(false); viewObstacles[1].SetActive(false); viewObstacles[2].SetActive(true); viewObstacles[3].SetActive(true); break; case AdjacencyShape.LNone: case AdjacencyShape.LSingle: viewObstacles[0].SetActive(false); viewObstacles[1].SetActive(true); viewObstacles[2].SetActive(true); viewObstacles[3].SetActive(false); break; case AdjacencyShape.TNone: case AdjacencyShape.TSingleLeft: case AdjacencyShape.TSingleRight: viewObstacles[0].SetActive(true); viewObstacles[1].SetActive(true); viewObstacles[2].SetActive(false); viewObstacles[3].SetActive(true); break; case AdjacencyShape.TDouble: case AdjacencyShape.XNone: case AdjacencyShape.XSingle: case AdjacencyShape.XOpposite: case AdjacencyShape.XSide: case AdjacencyShape.XTriple: case AdjacencyShape.XQuad: viewObstacles[0].SetActive(true); viewObstacles[1].SetActive(true); viewObstacles[2].SetActive(true); viewObstacles[3].SetActive(true); break; } } return(new MeshDirectionInfo { Mesh = mesh, Rotation = rotation }); }
public override void OnInspectorGUI() { DrawDefaultInspector(); // Serialize the object as this is the prefered way to change objects in the editor MultiAdjacencyConnector connector = (MultiAdjacencyConnector)target; SerializedObject serializedConnector = new SerializedObject(connector); SerializedProperty property = serializedConnector.FindProperty("EditorblockedConnections"); blocked = ParseBitmap((byte)property.intValue); showAdjacencyOptions = EditorGUILayout.BeginFoldoutHeaderGroup(showAdjacencyOptions, "Blocked connections"); if (showAdjacencyOptions) { EditorGUILayout.BeginVertical(); // Top line EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(20)); blocked[7] = EditorGUILayout.Toggle(blocked[7]); blocked[0] = EditorGUILayout.Toggle(blocked[0]); blocked[1] = EditorGUILayout.Toggle(blocked[1]); EditorGUILayout.EndHorizontal(); // Middle line EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(20)); blocked[6] = EditorGUILayout.Toggle(blocked[6]); EditorGUILayout.Space(14); blocked[2] = EditorGUILayout.Toggle(blocked[2]); EditorGUILayout.EndHorizontal(); // Last line EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(20)); blocked[5] = EditorGUILayout.Toggle(blocked[5]); blocked[4] = EditorGUILayout.Toggle(blocked[4]); blocked[3] = EditorGUILayout.Toggle(blocked[3]); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } EditorGUILayout.EndFoldoutHeaderGroup(); if (GUI.changed && connector != null) { bool changed = false; serializedConnector.Update(); property.intValue = SetBitmap(blocked); changed = serializedConnector.ApplyModifiedProperties(); if (changed) { // Get the PlacedTileObject and map var placedObject = connector.gameObject.GetComponent <PlacedTileObject>(); Engine.Tiles.TileMap map = connector.gameObject.GetComponentInParent <Engine.Tiles.TileMap>(); // Get all neighbours var neighbourObjects = map.GetNeighbourObjects(placedObject.GetLayer(), 0, placedObject.transform.position); for (int i = 0; i < neighbourObjects.Length; i++) { MultiAdjacencyConnector adjacencyNeighbour = neighbourObjects[i]?.gameObject.GetComponent <MultiAdjacencyConnector>(); if (adjacencyNeighbour) { // Serialize their object SerializedObject serializedNeighbourConnector = new SerializedObject(adjacencyNeighbour); serializedNeighbourConnector.Update(); SerializedProperty neighbourProperty = serializedNeighbourConnector.FindProperty("EditorblockedConnections"); // Set their opposite side blocked AdjacencyMap adjacencyMap = new AdjacencyMap(); adjacencyMap.DeserializeFromByte((byte)neighbourProperty.intValue); adjacencyMap.SetConnection(TileHelper.GetOpposite((Direction)i), new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, blocked[i])); neighbourProperty.intValue = adjacencyMap.SerializeToByte(); // Apply the changes serializedNeighbourConnector.ApplyModifiedProperties(); adjacencyNeighbour.UpdateBlockedFromEditor(); adjacencyNeighbour.UpdateSingle(TileHelper.GetOpposite((Direction)i), placedObject); } } // Set their adjacency connector connector.UpdateBlockedFromEditor(); placedObject.UpdateAllAdjacencies(neighbourObjects); } } }
public MeshDirectionInfo GetMeshAndDirection(AdjacencyMap adjacencyMap) { // Determine rotation and mesh specially for every single case. float rotation = 0.0f; Mesh mesh; AdjacencyShape shape = AdjacencyShapeResolver.GetOffsetShape(adjacencyMap); switch (shape) { case AdjacencyShape.O: mesh = o; orientation = OffsetOrientation.o; break; case AdjacencyShape.UNorth: mesh = uNorth; orientation = OffsetOrientation.uNorth; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.GetSingleConnection()); break; case AdjacencyShape.USouth: mesh = uSouth; orientation = OffsetOrientation.uSouth; rotation = TileHelper.AngleBetween(Direction.South, adjacencyMap.GetSingleNonConnection()); break; case AdjacencyShape.I: mesh = i; orientation = OffsetOrientation.i; rotation = TileHelper.AngleBetween(Direction.North, adjacencyMap.HasConnection(Direction.North) ? Direction.North : Direction.East); break; case AdjacencyShape.LNorthWest: mesh = lNW; orientation = OffsetOrientation.lNW; rotation = 90; break; case AdjacencyShape.LNorthEast: mesh = lNE; orientation = OffsetOrientation.lSE; rotation = 90; break; case AdjacencyShape.LSouthEast: mesh = lSE; orientation = OffsetOrientation.lSW; rotation = 90; break; case AdjacencyShape.LSouthWest: mesh = lSW; orientation = OffsetOrientation.lNW; rotation = 90; break; case AdjacencyShape.TNorthSouthEast: mesh = tNSE; orientation = OffsetOrientation.tSWE; rotation = 90; break; case AdjacencyShape.TSouthWestEast: mesh = tSWE; orientation = OffsetOrientation.tNSW; rotation = 90; break; case AdjacencyShape.TNorthSouthWest: mesh = tNSW; orientation = OffsetOrientation.tNEW; rotation = 90; break; case AdjacencyShape.TNorthEastWest: mesh = tNEW; orientation = OffsetOrientation.tNSE; rotation = 90; break; case AdjacencyShape.X: mesh = x; orientation = OffsetOrientation.x; rotation = 90; break; default: Debug.LogError($"Received unexpected shape from offset shape resolver: {shape}"); mesh = o; break; } return(new MeshDirectionInfo { Mesh = mesh, Rotation = rotation }); }