Initial Commit
This commit is contained in:
commit
ee5c2f922d
2255 changed files with 547750 additions and 0 deletions
10
Assets/Scripts/UI/Tilemap/Brushes/Random Brush/Scripts.meta
Normal file
10
Assets/Scripts/UI/Tilemap/Brushes/Random Brush/Scripts.meta
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d352e5b4c56a76e4d99fc48256bbc67e
|
||||
folderAsset: yes
|
||||
timeCreated: 1499223198
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 762d145b6139de6478fcc2998702d839
|
||||
folderAsset: yes
|
||||
timeCreated: 1499223228
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Tilemaps;
|
||||
|
||||
namespace UnityEditor
|
||||
{
|
||||
[CustomGridBrush(false, true, false, "Random Brush")]
|
||||
public class RandomBrush : UnityEditor.Tilemaps.GridBrush
|
||||
{
|
||||
public TileBase[] randomTiles;
|
||||
|
||||
public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position)
|
||||
{
|
||||
if (randomTiles != null && randomTiles.Length > 0)
|
||||
{
|
||||
if (brushTarget == null)
|
||||
return;
|
||||
|
||||
var tilemap = brushTarget.GetComponent<Tilemap>();
|
||||
if (tilemap == null)
|
||||
return;
|
||||
|
||||
Vector3Int min = position - pivot;
|
||||
BoundsInt bounds = new BoundsInt(min, size);
|
||||
foreach (Vector3Int location in bounds.allPositionsWithin)
|
||||
{
|
||||
var randomTile = randomTiles[(int) (randomTiles.Length * UnityEngine.Random.value)];
|
||||
tilemap.SetTile(location, randomTile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Paint(grid, brushTarget, position);
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/Random Brush")]
|
||||
public static void CreateBrush()
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanelInProject("Save Random Brush", "New Random Brush", "asset", "Save Random Brush", "Assets");
|
||||
|
||||
if (path == "")
|
||||
return;
|
||||
|
||||
AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<RandomBrush>(), path);
|
||||
}
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(RandomBrush))]
|
||||
public class RandomBrushEditor : UnityEditor.Tilemaps.GridBrushEditor
|
||||
{
|
||||
private RandomBrush randomBrush { get { return target as RandomBrush; } }
|
||||
private GameObject lastBrushTarget;
|
||||
|
||||
public override void PaintPreview(GridLayout grid, GameObject brushTarget, Vector3Int position)
|
||||
{
|
||||
if (randomBrush.randomTiles != null && randomBrush.randomTiles.Length > 0)
|
||||
{
|
||||
base.PaintPreview(grid, null, position);
|
||||
|
||||
if (brushTarget == null)
|
||||
return;
|
||||
|
||||
var tilemap = brushTarget.GetComponent<Tilemap>();
|
||||
if (tilemap == null)
|
||||
return;
|
||||
|
||||
Vector3Int min = position - randomBrush.pivot;
|
||||
BoundsInt bounds = new BoundsInt(min, randomBrush.size);
|
||||
foreach (Vector3Int location in bounds.allPositionsWithin)
|
||||
{
|
||||
var randomTile = randomBrush.randomTiles[(int) (randomBrush.randomTiles.Length * UnityEngine.Random.value)];
|
||||
tilemap.SetEditorPreviewTile(location, randomTile);
|
||||
}
|
||||
|
||||
lastBrushTarget = brushTarget;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.PaintPreview(grid, brushTarget, position);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ClearPreview()
|
||||
{
|
||||
if (lastBrushTarget != null)
|
||||
{
|
||||
var tilemap = lastBrushTarget.GetComponent<Tilemap>();
|
||||
if (tilemap == null)
|
||||
return;
|
||||
|
||||
tilemap.ClearAllEditorPreviewTiles();
|
||||
|
||||
lastBrushTarget = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ClearPreview();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnPaintInspectorGUI()
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
int count = EditorGUILayout.IntField("Number of Tiles", randomBrush.randomTiles != null ? randomBrush.randomTiles.Length : 0);
|
||||
if (count < 0)
|
||||
count = 0;
|
||||
if (randomBrush.randomTiles == null || randomBrush.randomTiles.Length != count)
|
||||
{
|
||||
Array.Resize<TileBase>(ref randomBrush.randomTiles, count);
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
return;
|
||||
|
||||
EditorGUILayout.LabelField("Place random tiles.");
|
||||
EditorGUILayout.Space();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
randomBrush.randomTiles[i] = (TileBase) EditorGUILayout.ObjectField("Tile " + (i+1), randomBrush.randomTiles[i], typeof(TileBase), false, null);
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
EditorUtility.SetDirty(randomBrush);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d80edd6caba93514eb01722041fe50b4
|
||||
timeCreated: 1499223220
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue