Initial Commit
This commit is contained in:
commit
ee5c2f922d
2255 changed files with 547750 additions and 0 deletions
10
Assets/Scripts/UI/Tilemap/Brushes/Prefab Brush/Scripts.meta
Normal file
10
Assets/Scripts/UI/Tilemap/Brushes/Prefab Brush/Scripts.meta
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 090e78558c17f064eae502998e2f22fb
|
||||
folderAsset: yes
|
||||
timeCreated: 1501789849
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 642e946f97259c640b3a047a57944ed9
|
||||
folderAsset: yes
|
||||
timeCreated: 1501789995
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor
|
||||
{
|
||||
[CreateAssetMenu]
|
||||
[CustomGridBrush(false, true, false, "Prefab Brush")]
|
||||
public class PrefabBrush : GridBrushBase
|
||||
{
|
||||
private const float k_PerlinOffset = 100000f;
|
||||
public GameObject[] m_Prefabs;
|
||||
public float m_PerlinScale = 0.5f;
|
||||
public int m_Z;
|
||||
|
||||
public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position)
|
||||
{
|
||||
// Do not allow editing palettes
|
||||
if (brushTarget.layer == 31)
|
||||
return;
|
||||
|
||||
int index = Mathf.Clamp(Mathf.FloorToInt(GetPerlinValue(position, m_PerlinScale, k_PerlinOffset)*m_Prefabs.Length), 0, m_Prefabs.Length - 1);
|
||||
GameObject prefab = m_Prefabs[index];
|
||||
GameObject instance = (GameObject) PrefabUtility.InstantiatePrefab(prefab);
|
||||
if (instance != null)
|
||||
{
|
||||
Undo.MoveGameObjectToScene(instance, brushTarget.scene, "Paint Prefabs");
|
||||
Undo.RegisterCreatedObjectUndo((Object)instance, "Paint Prefabs");
|
||||
instance.transform.SetParent(brushTarget.transform);
|
||||
instance.transform.position = grid.LocalToWorld(grid.CellToLocalInterpolated(new Vector3Int(position.x, position.y, m_Z) + new Vector3(.5f, .5f, .5f)));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Erase(GridLayout grid, GameObject brushTarget, Vector3Int position)
|
||||
{
|
||||
// Do not allow editing palettes
|
||||
if (brushTarget.layer == 31)
|
||||
return;
|
||||
|
||||
Transform erased = GetObjectInCell(grid, brushTarget.transform, new Vector3Int(position.x, position.y, m_Z));
|
||||
if (erased != null)
|
||||
Undo.DestroyObjectImmediate(erased.gameObject);
|
||||
}
|
||||
|
||||
private static Transform GetObjectInCell(GridLayout grid, Transform parent, Vector3Int position)
|
||||
{
|
||||
int childCount = parent.childCount;
|
||||
Vector3 min = grid.LocalToWorld(grid.CellToLocalInterpolated(position));
|
||||
Vector3 max = grid.LocalToWorld(grid.CellToLocalInterpolated(position + Vector3Int.one));
|
||||
Bounds bounds = new Bounds((max + min)*.5f, max - min);
|
||||
|
||||
for (int i = 0; i < childCount; i++)
|
||||
{
|
||||
Transform child = parent.GetChild(i);
|
||||
if (bounds.Contains(child.position))
|
||||
return child;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static float GetPerlinValue(Vector3Int position, float scale, float offset)
|
||||
{
|
||||
return Mathf.PerlinNoise((position.x + offset)*scale, (position.y + offset)*scale);
|
||||
}
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(PrefabBrush))]
|
||||
public class PrefabBrushEditor : UnityEditor.Tilemaps.GridBrushEditorBase
|
||||
{
|
||||
private PrefabBrush prefabBrush { get { return target as PrefabBrush; } }
|
||||
|
||||
private SerializedProperty m_Prefabs;
|
||||
private SerializedObject m_SerializedObject;
|
||||
|
||||
protected void OnEnable()
|
||||
{
|
||||
m_SerializedObject = new SerializedObject(target);
|
||||
m_Prefabs = m_SerializedObject.FindProperty("m_Prefabs");
|
||||
}
|
||||
|
||||
public override void OnPaintInspectorGUI()
|
||||
{
|
||||
m_SerializedObject.UpdateIfRequiredOrScript();
|
||||
prefabBrush.m_PerlinScale = EditorGUILayout.Slider("Perlin Scale", prefabBrush.m_PerlinScale, 0.001f, 0.999f);
|
||||
prefabBrush.m_Z = EditorGUILayout.IntField("Position Z", prefabBrush.m_Z);
|
||||
|
||||
EditorGUILayout.PropertyField(m_Prefabs, true);
|
||||
m_SerializedObject.ApplyModifiedPropertiesWithoutUndo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2d5751a2c961df945a34295ccf5e576d
|
||||
timeCreated: 1501681786
|
||||
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