Initial Commit
This commit is contained in:
commit
ee5c2f922d
2255 changed files with 547750 additions and 0 deletions
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3d5759c37f6ead941b87383dcb19bff3
|
||||
folderAsset: yes
|
||||
timeCreated: 1502798569
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7402f20de7e8fc34c9cfcbc965122710
|
||||
folderAsset: yes
|
||||
timeCreated: 1502800377
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Tilemaps;
|
||||
|
||||
namespace UnityEditor
|
||||
{
|
||||
[CustomGridBrush(false, false, false, "Tint Brush (Smooth)")]
|
||||
public class TintBrushSmooth : GridBrushBase
|
||||
{
|
||||
private TintTextureGenerator generator
|
||||
{
|
||||
get
|
||||
{
|
||||
TintTextureGenerator generator = FindObjectOfType<TintTextureGenerator>();
|
||||
if (generator == null)
|
||||
{
|
||||
// Note: Code assumes only one grid in scene
|
||||
Grid grid = FindObjectOfType<Grid>();
|
||||
if (grid != null)
|
||||
{
|
||||
generator = grid.gameObject.AddComponent<TintTextureGenerator>();
|
||||
}
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
}
|
||||
|
||||
public Color m_Color = Color.white;
|
||||
|
||||
public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position)
|
||||
{
|
||||
// Do not allow editing palettes
|
||||
if (brushTarget.layer == 31)
|
||||
return;
|
||||
|
||||
TintTextureGenerator generator = GetGenerator(grid);
|
||||
if (generator != null)
|
||||
{
|
||||
generator.SetColor(grid as Grid, position, m_Color);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Erase(GridLayout grid, GameObject brushTarget, Vector3Int position)
|
||||
{
|
||||
// Do not allow editing palettes
|
||||
if (brushTarget.layer == 31)
|
||||
return;
|
||||
|
||||
TintTextureGenerator generator = GetGenerator(grid);
|
||||
if (generator != null)
|
||||
{
|
||||
generator.SetColor(grid as Grid, position, Color.white);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Pick(GridLayout grid, GameObject brushTarget, BoundsInt position, Vector3Int pivot)
|
||||
{
|
||||
// Do not allow editing palettes
|
||||
if (brushTarget.layer == 31)
|
||||
return;
|
||||
|
||||
TintTextureGenerator generator = GetGenerator(grid);
|
||||
if (generator != null)
|
||||
{
|
||||
m_Color = generator.GetColor(grid as Grid, position.min);
|
||||
}
|
||||
}
|
||||
|
||||
private TintTextureGenerator GetGenerator(GridLayout grid)
|
||||
{
|
||||
TintTextureGenerator generator = FindObjectOfType<TintTextureGenerator>();
|
||||
if (generator == null)
|
||||
{
|
||||
if (grid != null)
|
||||
{
|
||||
generator = grid.gameObject.AddComponent<TintTextureGenerator>();
|
||||
}
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(TintBrushSmooth))]
|
||||
public class TintBrushSmoothEditor : UnityEditor.Tilemaps.GridBrushEditorBase
|
||||
{
|
||||
public override GameObject[] validTargets
|
||||
{
|
||||
get
|
||||
{
|
||||
return GameObject.FindObjectsOfType<Tilemap>().Select(x => x.gameObject).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnPaintInspectorGUI()
|
||||
{
|
||||
base.OnPaintInspectorGUI();
|
||||
GUILayout.Label("Note: Tilemap needs to use TintedTilemap.shader!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ed363ce3b4856fa408111529bc784318
|
||||
timeCreated: 1502800385
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Tilemaps;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class TintTextureGenerator : MonoBehaviour
|
||||
{
|
||||
public int k_TintMapSize = 256;
|
||||
|
||||
private Texture2D m_TintTexture;
|
||||
|
||||
private Texture2D tintTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_TintTexture == null)
|
||||
{
|
||||
m_TintTexture = new Texture2D(k_TintMapSize, k_TintMapSize, TextureFormat.ARGB32, false);
|
||||
m_TintTexture.hideFlags = HideFlags.HideAndDontSave;
|
||||
m_TintTexture.wrapMode = TextureWrapMode.Clamp;
|
||||
m_TintTexture.filterMode = FilterMode.Bilinear;
|
||||
RefreshGlobalShaderValues();
|
||||
}
|
||||
|
||||
return m_TintTexture;
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Refresh(GetComponent<Grid>());
|
||||
}
|
||||
|
||||
public void Refresh(Grid grid)
|
||||
{
|
||||
if (grid == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var w = tintTexture.width;
|
||||
var h = tintTexture.height;
|
||||
for (var y = 0; y < h; y++)
|
||||
for (var x = 0; x < w; x++)
|
||||
{
|
||||
var world = TextureToWorld(new Vector3Int(x, y, 0));
|
||||
tintTexture.SetPixel(x, y, GetGridInformation(grid).GetPositionProperty(world, "Tint", Color.white));
|
||||
}
|
||||
|
||||
tintTexture.Apply();
|
||||
}
|
||||
|
||||
public void Refresh(Grid grid, Vector3Int position)
|
||||
{
|
||||
if (grid == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshGlobalShaderValues();
|
||||
var texPosition = WorldToTexture(position);
|
||||
tintTexture.SetPixel(texPosition.x, texPosition.y, GetGridInformation(grid).GetPositionProperty(position, "Tint", Color.white));
|
||||
tintTexture.Apply();
|
||||
}
|
||||
|
||||
public Color GetColor(Grid grid, Vector3Int position)
|
||||
{
|
||||
if (grid == null)
|
||||
{
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
return GetGridInformation(grid).GetPositionProperty(position, "Tint", Color.white);
|
||||
}
|
||||
|
||||
public void SetColor(Grid grid, Vector3Int position, Color color)
|
||||
{
|
||||
if (grid == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GetGridInformation(grid).SetPositionProperty(position, "Tint", color);
|
||||
Refresh(grid, position);
|
||||
}
|
||||
|
||||
private Vector3Int WorldToTexture(Vector3Int world)
|
||||
{
|
||||
return new Vector3Int(world.x + tintTexture.width / 2, world.y + tintTexture.height / 2, 0);
|
||||
}
|
||||
|
||||
private Vector3Int TextureToWorld(Vector3Int texpos)
|
||||
{
|
||||
return new Vector3Int(texpos.x - tintTexture.width / 2, texpos.y - tintTexture.height / 2, 0);
|
||||
}
|
||||
|
||||
private GridInformation GetGridInformation(Grid grid)
|
||||
{
|
||||
var gridInformation = grid.GetComponent<GridInformation>();
|
||||
|
||||
if (gridInformation == null)
|
||||
{
|
||||
gridInformation = grid.gameObject.AddComponent<GridInformation>();
|
||||
}
|
||||
|
||||
return gridInformation;
|
||||
}
|
||||
|
||||
private void RefreshGlobalShaderValues()
|
||||
{
|
||||
Shader.SetGlobalTexture("_TintMap", m_TintTexture);
|
||||
Shader.SetGlobalFloat("_TintMapSize", k_TintMapSize);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b41bf0cc11b1c8f419f96e8eb0adea40
|
||||
timeCreated: 1502798706
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f9a74a0ba597dbd4ebbdc09df032a31c
|
||||
folderAsset: yes
|
||||
timeCreated: 1502798946
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
Shader "Custom/TintedTilemap"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[PerRendererData]_MainTex ("Albedo (RGB)", 2D) = "white" {}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags { "Queue"="Transparent" "Render"="Transparent" "IgnoreProjector"="True"}
|
||||
LOD 200
|
||||
|
||||
ZWrite Off
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
Pass{
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata {
|
||||
float4 vertex : POSITION;
|
||||
float4 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _TintMap;
|
||||
float _TintMapSize;
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
float4 uv : TEXCOORD0;
|
||||
float3 worldPos : float3;
|
||||
};
|
||||
|
||||
v2f vert(appdata v) {
|
||||
v2f o;
|
||||
|
||||
o.worldPos = mul (unity_ObjectToWorld, v.vertex);
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = float4(v.texcoord.xy, 0, 0);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target {
|
||||
fixed4 col = tex2D (_MainTex, i.uv);
|
||||
fixed4 tint = tex2D(_TintMap, (i.worldPos.xy / _TintMapSize) + .5);
|
||||
return tint * col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9fcc3b710e7f7ae44bcf65125a08d5ef
|
||||
timeCreated: 1502805334
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue