/// <summary>
        /// Ensures that the object is properly initialized.
        /// </summary>
        private void EnsureInit()
        {
            if (!this)
            {
                return;
            }

            if (adjacencyMap == null)
            {
                adjacencyMap = new AdjacencyMap();
            }

            if (!filter)
            {
                filter = GetComponent <MeshFilter>();
            }

            PlacedTileObject placedTileObject = GetComponent <PlacedTileObject>();

            if (placedTileObject == null)
            {
                genericType  = TileObjectGenericType.None;
                specificType = TileObjectSpecificType.None;
            }
            else
            {
                genericType  = placedTileObject.GetGenericType();
                specificType = placedTileObject.GetSpecificType();
            }
        }
Example #2
0
        /// <summary>
        /// Update a single direction.
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="placedObject"></param>
        /// <returns></returns>
        private bool UpdateSingleConnection(Direction dir, PlacedTileObject placedObject)
        {
            // For some reason called before OnAwake()
            EnsureInit();
            UpdateBlockedFromEditor();

            bool isConnected = false;

            if (placedObject)
            {
                isConnected = (placedObject && placedObject.HasAdjacencyConnector());

                // If cross connect is allowed, we only allow it to connect when the object type matches the connector type
                if (CrossConnectAllowed)
                {
                    isConnected &= (placedObject.GetGenericType() == genericType && genericType != "");
                }
                else
                {
                    isConnected &= (placedObject.GetGenericType() == genericType || genericType == null);
                }

                // Check for specific
                isConnected &= (placedObject.GetSpecificType() == specificType || specificType == "");

                isConnected &= (AdjacencyBitmap.Adjacent(blockedConnections, dir) == 0);
            }
            bool isUpdated = adjacents.UpdateDirection(dir, isConnected, true);

            SyncAdjacentConnections(adjacents.Connections, adjacents.Connections);

            // Cross connect will override adjacents for other layers, so return isConnected instead.
            if (CrossConnectAllowed)
            {
                return(isConnected);
            }
            else
            {
                return(isUpdated);
            }
        }
        /// <summary>
        /// Update a single direction.
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="placedObject"></param>
        /// <returns></returns>
        private bool UpdateSingleConnection(Direction dir, PlacedTileObject placedObject)
        {
            // For some reason called before OnAwake()
            EnsureInit();
            UpdateBlockedFromEditor();

            bool isConnected = false;

            if (placedObject)
            {
                isConnected = (placedObject && placedObject.HasAdjacencyConnector());

                // If cross connect is allowed, we only allow it to connect when the object type matches the connector type
                if (CrossConnectAllowed)
                {
                    isConnected &= placedObject.GetGenericType() == genericType && genericType != TileObjectGenericType.None;
                }
                else
                {
                    isConnected &= placedObject.GetGenericType() == genericType || genericType == TileObjectGenericType.None;
                }

                // Check for specific
                isConnected &= placedObject.GetSpecificType() == specificType || specificType == TileObjectSpecificType.None;


                isConnected &= ((blockedConnections >> (int)dir) & 0x1) == 0;
            }
            bool isUpdated   = adjacencyMap.SetConnection(dir, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, isConnected));
            byte connections = adjacencyMap.SerializeToByte();

            SyncAdjacentConnections(connections, connections);

            // Cross connect will override adjacents for other layers, so return isConnected instead.
            return(CrossConnectAllowed ? isConnected : isUpdated);
        }