Beispiel #1
0
        public TileDragHandler(TileManager tileManager, TileMapEditor mapEditor, Engine.Tiles.TileMap map, int subLayerIndex, TileObjectSo tileObjectSO, Direction selectedDir, Vector3Int snappedPosition)
        {
            this.tileManager   = tileManager;
            this.mapEditor     = mapEditor;
            this.map           = map;
            this.subLayerIndex = subLayerIndex;
            this.tileObjectSO  = tileObjectSO;
            this.selectedDir   = selectedDir;
            startPosition      = snappedPosition;
            curPosition        = snappedPosition;

            var tile = CreateGhost();

            tile.transform.position = new Vector3(snappedPosition.x, 0, snappedPosition.y);
            dragTiles.Insert(0, tile);
        }
Beispiel #2
0
        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);
                }
            }
        }