private void AddZoneTriggers(MapPropertiesBrush brush, MapProperties properties) { brush.Selection.HasDifferentHasZoneTrigger = false; if (!brush.ActiveTileInfo.HasZoneTrigger) { brush.ActiveTileInfo.HasZoneTrigger = true; brush.ActiveTileInfo.HasZoneTrigger = true; brush.ActiveTileInfo.Zone = new ZoneTrigger() { TargetZone = brush.ActiveTileInfo.Zone.TargetZone, Transition = brush.ActiveTileInfo.Zone.Transition, TargetSpawn = brush.ActiveTileInfo.Zone.TargetSpawn }; } foreach (var position in brush.Selection.Bounds.allPositionsWithin) { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); if (!tile.HasZoneTrigger) { tile.HasZoneTrigger = true; tile.Zone = new ZoneTrigger() { TargetZone = brush.ActiveTileInfo.Zone.TargetZone, Transition = brush.ActiveTileInfo.Zone.Transition, TargetSpawn = brush.ActiveTileInfo.Zone.TargetSpawn }; } } properties.UpdateBounds(); }
private void DrawCollisionLayer(MapPropertiesBrush brush, MapProperties properties) { // COLLISION LAYER var collisionLayer = brush.ActiveTileInfo.CollisionLayer; var collisionLayerIndex = _collisionLayerOptions.Count - 1; var selectedCollisionLayer = collisionLayer; var selectedCollisionLayerIndex = collisionLayerIndex; if (brush.Selection.HasDifferentCollisionLayer) { selectedCollisionLayerIndex = EditorGUILayout.Popup(_collisionLayerContent, collisionLayerIndex, _collisionLayerOptions.ToArray()); } else { selectedCollisionLayer = (CollisionLayer)EditorGUILayout.EnumFlagsField(_collisionLayerContent, collisionLayer); } if (collisionLayer != selectedCollisionLayer) { ChangeCollisionLayers(brush, properties, selectedCollisionLayer); } if (collisionLayerIndex != selectedCollisionLayerIndex && selectedCollisionLayerIndex < _collisionLayerOptions.Count - 1) { ChangeCollisionLayers(brush, properties, selectedCollisionLayerIndex); } }
private void AddSpawnPoints(MapPropertiesBrush brush, MapProperties properties) { brush.Selection.HasDifferentHasSpawnPoint = false; if (!brush.ActiveTileInfo.HasSpawnPoint) { brush.ActiveTileInfo.HasSpawnPoint = true; brush.ActiveTileInfo.SpawnPoint = new SpawnPoint() { Name = brush.ActiveTileInfo.SpawnPoint.Name, Direction = brush.ActiveTileInfo.SpawnPoint.Direction, Position = brush.ActiveTileInfo.Position, Layer = CollisionLayer.One }; } foreach (var position in brush.Selection.Bounds.allPositionsWithin) { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); if (!tile.HasSpawnPoint) { tile.HasSpawnPoint = true; tile.SpawnPoint = new SpawnPoint() { Name = brush.ActiveTileInfo.SpawnPoint.Name, Direction = brush.ActiveTileInfo.SpawnPoint.Direction, Position = tile.Position, Layer = CollisionLayer.One }; } } properties.UpdateBounds(); }
private void DrawEncounter(MapPropertiesBrush brush, MapProperties properties) { using (new EditorGUILayout.HorizontalScope()) { // HAS ENCOUNTER _encounterContent.text = brush.Selection.HasDifferentHasEncounter ? "Encounter (different values)" : "Encounter"; var hasEncounter = brush.Selection.HasDifferentHasEncounter ? false : brush.ActiveTileInfo.HasEncounter; var selectedHasEncounter = EditorGUILayout.Toggle(_encounterContent, hasEncounter); if (brush.ActiveTileInfo.HasEncounter && !brush.Selection.HasDifferentHasEncounter) { // ENCOUNTER OBJECT _targetEncounterContent.text = brush.Selection.HasDifferentEncounters ? "(different values)" : ""; var encounter = brush.Selection.HasDifferentEncounters ? null : brush.ActiveTileInfo.Encounter; var selectedEncounter = EditorGUILayout.ObjectField(_targetEncounterContent, encounter, typeof(Encounter), true) as Encounter; if (encounter != selectedEncounter) { SetTargetEncounters(brush, properties, selectedEncounter); } } if (!hasEncounter && selectedHasEncounter) { AddEncounterTriggers(brush, properties); } if (hasEncounter && !selectedHasEncounter) { RemoveEncounterTriggers(brush, properties); } } }
private void DrawInstructions(MapPropertiesBrush brush, MapProperties properties) { using (new EditorGUILayout.HorizontalScope()) { // HAS INSTRUCTIONS _instructionsContent.text = brush.Selection.HasDifferentHasInstructions ? "Instructions (different values)" : "Instructions"; var hasInstruction = brush.Selection.HasDifferentHasInstructions ? false : brush.ActiveTileInfo.HasInstructions; var selectedHasInstruction = EditorGUILayout.Toggle(_instructionsContent, hasInstruction); if (brush.ActiveTileInfo.HasInstructions && !brush.Selection.HasDifferentHasInstructions) { // INSTRUCTION OBJECT _targetInstructionsContent.text = brush.Selection.HasDifferentInstructions ? "(different values)" : ""; var instruction = brush.Selection.HasDifferentInstructions ? null : brush.ActiveTileInfo.Instructions; var selectedInstruction = InstructionDrawer.Draw(null, instruction, _targetInstructionsContent); if (instruction != selectedInstruction) { SetInstructions(brush, properties, selectedInstruction); } } if (!hasInstruction && selectedHasInstruction) { AddInstructions(brush, properties); } if (hasInstruction && !selectedHasInstruction) { RemoveInstructions(brush, properties); } } }
private void DrawSpawnPoint(MapPropertiesBrush brush, MapProperties properties) { using (new EditorGUILayout.HorizontalScope()) { // HAS SPAWN _spawnPointContent.text = brush.Selection.HasDifferentHasSpawnPoint ? "Spawn Point (different values)" : "Spawn Point"; var hasSpawnPoint = brush.Selection.HasDifferentHasSpawnPoint ? false : brush.ActiveTileInfo.HasSpawnPoint; var selectedHasSpawnPoint = EditorGUILayout.Toggle(_spawnPointContent, hasSpawnPoint); if (!hasSpawnPoint && selectedHasSpawnPoint) { AddSpawnPoints(brush, properties); } if (hasSpawnPoint && !selectedHasSpawnPoint) { RemoveSpawnPoints(brush, properties); } if (brush.ActiveTileInfo.HasSpawnPoint && !brush.Selection.HasDifferentHasSpawnPoint) { // NAME var name = brush.Selection.HasDifferentSpawnPointNames ? "different values" : brush.ActiveTileInfo.SpawnPoint.Name; var selectedName = EditorGUILayout.DelayedTextField(_spawnNameContent, name); if (name != selectedName) { SetSpawnPointNames(brush, properties, selectedName); } } } if (brush.ActiveTileInfo.HasSpawnPoint && !brush.Selection.HasDifferentHasSpawnPoint) { using (new EditorGUI.IndentLevelScope()) { // DIRECTION _spawnDirectionContent.text = brush.Selection.HasDifferentSpawnPointDirections ? "Direction (different values)" : "Direction"; var direction = brush.Selection.HasDifferentSpawnPointDirections ? Vector2.down : brush.ActiveTileInfo.SpawnPoint.Direction; var selectedDirection = EditorGUILayout.Vector2Field(_spawnDirectionContent, direction); // LAYER var layerOptions = brush.Selection.HasDifferentSpawnPointLayers ? _collisionLayerOptions.GetRange(1, _collisionLayerOptions.Count - 1).ToArray() : _collisionLayerOptions.GetRange(1, _collisionLayerOptions.Count - 2).ToArray(); var layer = brush.Selection.HasDifferentSpawnPointLayers ? _collisionLayerOptions.Count - 1 : MathHelper.LogBase2((int)brush.ActiveTileInfo.SpawnPoint.Layer); var selectedLayer = EditorGUILayout.Popup(_spawnLayerContent, layer, layerOptions); if (direction != selectedDirection) { SetSpawnPointDirections(brush, properties, selectedDirection); } if (layer != selectedLayer) { SetSpawnPointLayers(brush, properties, selectedLayer); } } } }
private void SetZoneTransitions(MapPropertiesBrush brush, MapProperties properties) { brush.Selection.HasDifferentZoneTransitions = false; foreach (var position in brush.Selection.Bounds.allPositionsWithin) { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); tile.Zone.Transition = brush.ActiveTileInfo.Zone.Transition; } properties.UpdateBounds(); }
private void DrawCollisionIncrement(MapPropertiesBrush brush, MapProperties properties) { // COLLISION INCREMENT var collisionIncrementOptions = brush.Selection.HasDifferentCollisionIncrement ? _collisionLayerOptions.ToArray() : _collisionLayerOptions.GetRange(0, _collisionLayerOptions.Count - 1).ToArray(); var collisionIncrement = brush.Selection.HasDifferentCollisionIncrement ? _collisionLayerOptions.Count - 1 : brush.ActiveTileInfo.CollisionLayerIncrement == CollisionLayer.None ? 0 : MathHelper.LogBase2((int)brush.ActiveTileInfo.CollisionLayerIncrement) + 1; var selectedCollisionIncrement = EditorGUILayout.Popup(_collisionIncrementContent, collisionIncrement, collisionIncrementOptions); if (collisionIncrement != selectedCollisionIncrement) { SetCollisionIncrements(brush, properties, selectedCollisionIncrement); } }
private void SetSpawnPointDirections(MapPropertiesBrush brush, MapProperties properties, Vector2 direction) { brush.Selection.HasDifferentSpawnPointDirections = false; brush.ActiveTileInfo.SpawnPoint.Direction = direction; foreach (var position in brush.Selection.Bounds.allPositionsWithin) { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); tile.SpawnPoint.Direction = direction; } properties.UpdateBounds(); }
private void SetTargetEncounters(MapPropertiesBrush brush, MapProperties properties, Encounter encounter) { brush.Selection.HasDifferentEncounters = false; brush.ActiveTileInfo.Encounter = encounter; foreach (var position in brush.Selection.Bounds.allPositionsWithin) { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); tile.Encounter = encounter; } properties.UpdateBounds(); }
private void SetInstructions(MapPropertiesBrush brush, MapProperties properties, Instruction instructions) { brush.Selection.HasDifferentInstructions = false; brush.ActiveTileInfo.Instructions = instructions; foreach (var position in brush.Selection.Bounds.allPositionsWithin) { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); tile.Instructions = instructions; } properties.UpdateBounds(); }
private void SetSpawnPointLayers(MapPropertiesBrush brush, MapProperties properties, int index) { var layer = (CollisionLayer)MathHelper.IntExponent(2, index); brush.Selection.HasDifferentSpawnPointLayers = false; brush.ActiveTileInfo.SpawnPoint.Layer = layer; foreach (var position in brush.Selection.Bounds.allPositionsWithin) { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); tile.SpawnPoint.Layer = layer; } properties.UpdateBounds(); }
private void RemoveInstructions(MapPropertiesBrush brush, MapProperties properties) { brush.Selection.HasDifferentHasInstructions = false; brush.ActiveTileInfo.HasInstructions = false; foreach (var position in brush.Selection.Bounds.allPositionsWithin) { var tile = properties.GetTile(new Vector2Int(position.x, position.y)); if (tile != null) { tile.HasInstructions = false; } } properties.UpdateBounds(); }
private void ChangeCollisionLayers(MapPropertiesBrush brush, MapProperties properties, CollisionLayer layer) { brush.Selection.HasDifferentCollisionLayer = false; brush.ActiveTileInfo.CollisionLayer = layer; foreach (var position in brush.Selection.Bounds.allPositionsWithin) { if (layer == CollisionLayer.None) { var tile = properties.GetTile(new Vector2Int(position.x, position.y)); if (tile != null) { tile.CollisionLayer = CollisionLayer.None; } } else { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); tile.CollisionLayer = layer; } } var size = brush.Selection.Bounds.size.x * brush.Selection.Bounds.size.y; var tileArray = Enumerable.Repeat(brush.CollisionTile, size).ToArray(); var nullArray = new TileBase[size]; for (int index = 0, value = 1; index < CollisionLayerData.LayerCount; index++, value *= 2) { if ((value & (int)layer) > 0) { var tilemap = properties.AddOrGetCollisionLayer(index); tilemap.SetTilesBlock(brush.Selection.Bounds, tileArray); } else { var tilemap = properties.GetCollisionLayer(index); if (tilemap) { tilemap.SetTilesBlock(brush.Selection.Bounds, nullArray); properties.CheckForCollisionRemoval(tilemap, index); } } } properties.UpdateBounds(); }
private void AddEncounterTriggers(MapPropertiesBrush brush, MapProperties properties) { brush.Selection.HasDifferentHasEncounter = false; brush.ActiveTileInfo.HasEncounter = true; foreach (var position in brush.Selection.Bounds.allPositionsWithin) { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); if (!tile.HasEncounter) { tile.HasEncounter = true; tile.Encounter = brush.ActiveTileInfo.Encounter; } } properties.UpdateBounds(); }
public void SetTilemap(MapProperties tilemap) { Tilemap = tilemap; if (Tilemap) { Pathfinding = Tilemap.GetComponent <Pathfinding>(); Tilemap.AddConnections(Connections); Tilemap.AddSpawnPoints(SpawnPoints); } else { Pathfinding = null; Connections.Clear(); SpawnPoints.Clear(); } }
private void SetCollisionIncrements(MapPropertiesBrush brush, MapProperties properties, int index) { var layer = index == 0 ? CollisionLayer.None : (CollisionLayer)MathHelper.IntExponent(2, index - 1); brush.Selection.HasDifferentCollisionIncrement = false; brush.ActiveTileInfo.CollisionLayerIncrement = layer; foreach (var position in brush.Selection.Bounds.allPositionsWithin) { if (layer == CollisionLayer.None) { var tile = properties.GetTile(new Vector2Int(position.x, position.y)); tile.CollisionLayerIncrement = CollisionLayer.None; } else { var tile = properties.AddOrGetTile(new Vector2Int(position.x, position.y)); tile.CollisionLayerIncrement = layer; } } properties.UpdateBounds(); }
private void DrawZone(MapPropertiesBrush brush, MapProperties properties) { using (new EditorGUILayout.HorizontalScope()) { // HAS ZONE _zoneTriggerContent.text = brush.Selection.HasDifferentHasZoneTrigger ? "Zone Trigger (different values)" : "Zone Trigger"; var hasZone = brush.Selection.HasDifferentHasZoneTrigger ? false : brush.ActiveTileInfo.HasZoneTrigger; var selectedHasZone = EditorGUILayout.Toggle(_zoneTriggerContent, hasZone); if (!hasZone && selectedHasZone) { AddZoneTriggers(brush, properties); } if (hasZone && !selectedHasZone) { RemoveZoneTriggers(brush, properties); } if (brush.ActiveTileInfo.HasZoneTrigger && !brush.Selection.HasDifferentHasZoneTrigger) { // TARGET ZONE if (_zonePicker.DrawDropDownList(ref brush.ActiveTileInfo.Zone.TargetZone, brush.Selection.HasDifferentTargetZones)) { SetTargetZones(brush, properties); } if (brush.ActiveTileInfo.Zone.TargetZone != null && !brush.Selection.HasDifferentTargetZones) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Load")) { var path = SceneUtility.GetScenePathByBuildIndex(brush.ActiveTileInfo.Zone.TargetZone.Scene.Index); EditorSceneManager.OpenScene(path, OpenSceneMode.Additive); } } } } if (brush.ActiveTileInfo.HasZoneTrigger && !brush.Selection.HasDifferentHasZoneTrigger) { using (new EditorGUI.IndentLevelScope()) { using (new EditorGUILayout.HorizontalScope()) { // HAS TRANSITION _transitionContent.text = brush.Selection.HasDifferentHasZoneTransitions ? "Transition (different values)" : "Transition"; var hasTransition = brush.Selection.HasDifferentHasZoneTransitions ? false : brush.ActiveTileInfo.Zone.HasTransition; var selectedHasTransition = EditorGUILayout.Toggle(_transitionContent, hasTransition); if (!hasTransition && selectedHasTransition) { AddZoneTransitions(brush, properties); } if (hasTransition && !selectedHasTransition) { RemoveZoneTransitions(brush, properties); } if (brush.ActiveTileInfo.Zone.HasTransition && !brush.Selection.HasDifferentHasZoneTransitions) { // TRANSITION TYPE if (_transitionPicker.DrawDropDownList(ref brush.ActiveTileInfo.Zone.Transition, brush.Selection.HasDifferentZoneTransitions)) { SetZoneTransitions(brush, properties); } GUILayout.FlexibleSpace(); } } if (brush.ActiveTileInfo.Zone.HasTransition && !brush.Selection.HasDifferentHasZoneTransitions) { using (new EditorGUI.IndentLevelScope()) { // TARGET SPAWN var spawn = brush.Selection.HasDifferentZoneTargetSpwans ? "different values" : brush.ActiveTileInfo.Zone.TargetSpawn; var selectedSpawn = EditorGUILayout.DelayedTextField(_targetSpwanContent, spawn); if (spawn != selectedSpawn) { SetTargetSpawns(brush, properties, selectedSpawn); } } } } } }
private void ChangeCollisionLayers(MapPropertiesBrush brush, MapProperties properties, int index) { var layer = index == 0 ? CollisionLayer.None : (CollisionLayer)MathHelper.IntExponent(2, index - 1); ChangeCollisionLayers(brush, properties, layer); }