You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Feel/MMTools/Tools/MMTilemaps/MMTilemapBoolean.cs

49 lines
1.2 KiB
C#

1 month ago
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using MoreMountains.Tools;
using System;
using System.Collections.Generic;
using UnityEngine.Tilemaps;
namespace MoreMountains.Tools
{
[AddComponentMenu("More Mountains/Tools/Tilemaps/MMTilemapBoolean")]
public class MMTilemapBoolean : MonoBehaviour
{
public Tilemap TilemapToClean;
[MMInspectorButton("BooleanClean")]
public bool BooleanCleanButton;
protected Tilemap _tilemap;
/// <summary>
/// This method will copy the reference tilemap into the one on this gameobject
/// </summary>
protected virtual void BooleanClean()
{
if (TilemapToClean == null)
{
return;
}
_tilemap = this.gameObject.GetComponent<Tilemap>();
// we grab all filled positions from the ref tilemap
foreach (Vector3Int pos in _tilemap.cellBounds.allPositionsWithin)
{
Vector3Int localPlace = new Vector3Int(pos.x, pos.y, pos.z);
if (_tilemap.HasTile(localPlace))
{
if (TilemapToClean.HasTile(localPlace))
{
TilemapToClean.SetTile(localPlace, null);
}
}
}
// we clear our tilemap and resize it
_tilemap.RefreshAllTiles();
}
}
}