add games
This commit is contained in:
1670
assignment10final/Assets/ProCore/ProGrids/Editor/pg_Editor.cs
Normal file
1670
assignment10final/Assets/ProCore/ProGrids/Editor/pg_Editor.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ab80081d3e2f274ba76a692cdcfa8d9
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,451 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ProGrids
|
||||
{
|
||||
public class pg_GridRenderer
|
||||
{
|
||||
static readonly HideFlags PG_HIDE_FLAGS = HideFlags.HideAndDontSave;
|
||||
|
||||
const string PREVIEW_OBJECT_NAME = "ProGridsGridObject";
|
||||
const string MATERIAL_OBJECT_NAME = "ProGridsMaterialObject";
|
||||
const string MESH_OBJECT_NAME = "ProGridsMeshObject";
|
||||
const string GRID_SHADER = "Hidden/ProGrids/pg_GridShader";
|
||||
const int MAX_LINES = 256;
|
||||
|
||||
static GameObject gridObject;
|
||||
static Mesh gridMesh;
|
||||
static Material gridMaterial;
|
||||
|
||||
public static int majorLineIncrement = 10;
|
||||
|
||||
/**
|
||||
* Destroy any existing render objects, then initialize new ones.
|
||||
*/
|
||||
public static void Init()
|
||||
{
|
||||
Destroy();
|
||||
|
||||
gridObject = EditorUtility.CreateGameObjectWithHideFlags(PREVIEW_OBJECT_NAME, PG_HIDE_FLAGS, new System.Type[2]{typeof(MeshFilter), typeof(MeshRenderer)});
|
||||
majorLineIncrement = EditorPrefs.GetInt(pg_Constant.MajorLineIncrement, 10);
|
||||
if(majorLineIncrement < 2)
|
||||
majorLineIncrement = 2;
|
||||
|
||||
// Force the mesh to only render in SceneView
|
||||
pg_SceneMeshRender renderer = gridObject.AddComponent<pg_SceneMeshRender>();
|
||||
|
||||
gridMesh = new Mesh();
|
||||
gridMesh.name = MESH_OBJECT_NAME;
|
||||
gridMesh.hideFlags = PG_HIDE_FLAGS;
|
||||
|
||||
gridMaterial = new Material(Shader.Find(GRID_SHADER));
|
||||
gridMaterial.name = MATERIAL_OBJECT_NAME;
|
||||
gridMaterial.hideFlags = PG_HIDE_FLAGS;
|
||||
|
||||
renderer.mesh = gridMesh;
|
||||
renderer.material = gridMaterial;
|
||||
}
|
||||
|
||||
public static void Destroy()
|
||||
{
|
||||
DestoryObjectsWithName(MESH_OBJECT_NAME, typeof(Mesh));
|
||||
DestoryObjectsWithName(MATERIAL_OBJECT_NAME, typeof(Material));
|
||||
DestoryObjectsWithName(PREVIEW_OBJECT_NAME, typeof(GameObject));
|
||||
}
|
||||
|
||||
static void DestoryObjectsWithName(string Name, System.Type type)
|
||||
{
|
||||
IEnumerable go = Resources.FindObjectsOfTypeAll(type).Where(x => x.name.Contains(Name));
|
||||
|
||||
foreach(Object t in go)
|
||||
{
|
||||
GameObject.DestroyImmediate(t);
|
||||
}
|
||||
}
|
||||
|
||||
private static int tan_iter, bit_iter, max = MAX_LINES, div = 1;
|
||||
|
||||
/**
|
||||
* Returns the distance this grid is drawing
|
||||
*/
|
||||
public static float DrawPlane(Camera cam, Vector3 pivot, Vector3 tangent, Vector3 bitangent, float snapValue, Color color, float alphaBump)
|
||||
{
|
||||
if(!gridMesh || !gridMaterial || !gridObject)
|
||||
Init();
|
||||
|
||||
gridMaterial.SetFloat("_AlphaCutoff", .1f);
|
||||
gridMaterial.SetFloat("_AlphaFade", .6f);
|
||||
|
||||
pivot = pg_Util.SnapValue(pivot, snapValue);
|
||||
|
||||
Vector3 p = cam.WorldToViewportPoint(pivot);
|
||||
bool inFrustum = (p.x >= 0f && p.x <= 1f) &&
|
||||
(p.y >= 0f && p.y <= 1f) &&
|
||||
p.z >= 0f;
|
||||
|
||||
float[] distances = GetDistanceToFrustumPlanes(cam, pivot, tangent, bitangent, 24f);
|
||||
|
||||
if(inFrustum)
|
||||
{
|
||||
tan_iter = (int)(Mathf.Ceil( (Mathf.Abs(distances[0]) + Mathf.Abs(distances[2]))/snapValue ));
|
||||
bit_iter = (int)(Mathf.Ceil( (Mathf.Abs(distances[1]) + Mathf.Abs(distances[3]))/snapValue ));
|
||||
|
||||
max = Mathf.Max( tan_iter, bit_iter );
|
||||
|
||||
// if the max is around 3x greater than min, we're probably skewing the camera at near-plane
|
||||
// angle, so use the min instead.
|
||||
if(max > Mathf.Min(tan_iter, bit_iter) * 2)
|
||||
max = (int) Mathf.Min(tan_iter, bit_iter) * 2;
|
||||
|
||||
div = 1;
|
||||
|
||||
float dot = Vector3.Dot( cam.transform.position-pivot, Vector3.Cross(tangent, bitangent) );
|
||||
|
||||
if(max > MAX_LINES)
|
||||
{
|
||||
if(Vector3.Distance(cam.transform.position, pivot) > 50f * snapValue && Mathf.Abs(dot) > .8f)
|
||||
{
|
||||
while(max/div > MAX_LINES)
|
||||
div += div;
|
||||
}
|
||||
else
|
||||
{
|
||||
max = MAX_LINES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// origin, tan, bitan, increment, iterations, divOffset, color, primary alpha bump
|
||||
DrawFullGrid(cam, pivot, tangent, bitangent, snapValue*div, max/div, div, color, alphaBump);
|
||||
|
||||
return ((snapValue*div)*(max/div));
|
||||
}
|
||||
|
||||
public static void DrawGridPerspective(Camera cam, Vector3 pivot, float snapValue, Color[] colors, float alphaBump)
|
||||
{
|
||||
if(!gridMesh || !gridMaterial || !gridObject)
|
||||
Init();
|
||||
|
||||
gridMaterial.SetFloat("_AlphaCutoff", 0f);
|
||||
gridMaterial.SetFloat("_AlphaFade", 0f);
|
||||
|
||||
Vector3 camDir = (pivot - cam.transform.position).normalized;
|
||||
pivot = pg_Util.SnapValue(pivot, snapValue);
|
||||
|
||||
// Used to flip the grid to match whatever direction the cam is currently
|
||||
// coming at the pivot from
|
||||
Vector3 right = camDir.x < 0f ? Vector3.right : Vector3.right * -1f;
|
||||
Vector3 up = camDir.y < 0f ? Vector3.up : Vector3.up * -1f;
|
||||
Vector3 forward = camDir.z < 0f ? Vector3.forward : Vector3.forward * -1f;
|
||||
|
||||
// Get intersecting point for each axis, if it exists
|
||||
Ray ray_x = new Ray(pivot, right);
|
||||
Ray ray_y = new Ray(pivot, up);
|
||||
Ray ray_z = new Ray(pivot, forward);
|
||||
|
||||
float x_dist = 10f, y_dist = 10f, z_dist = 10f;
|
||||
bool x_intersect = false, y_intersect = false, z_intersect = false;
|
||||
|
||||
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(cam);
|
||||
foreach(Plane p in planes)
|
||||
{
|
||||
float dist;
|
||||
float t = 0;
|
||||
|
||||
if(p.Raycast(ray_x, out dist))
|
||||
{
|
||||
t = Vector3.Distance(pivot, ray_x.GetPoint(dist));
|
||||
if(t < x_dist || !x_intersect)
|
||||
{
|
||||
x_intersect = true;
|
||||
x_dist = t;
|
||||
}
|
||||
}
|
||||
|
||||
if(p.Raycast(ray_y, out dist))
|
||||
{
|
||||
t = Vector3.Distance(pivot, ray_y.GetPoint(dist));
|
||||
if(t < y_dist || !y_intersect)
|
||||
{
|
||||
y_intersect = true;
|
||||
y_dist = t;
|
||||
}
|
||||
}
|
||||
|
||||
if(p.Raycast(ray_z, out dist))
|
||||
{
|
||||
t = Vector3.Distance(pivot, ray_z.GetPoint(dist));
|
||||
if(t < z_dist || !z_intersect)
|
||||
{
|
||||
z_intersect = true;
|
||||
z_dist = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int x_iter = (int)(Mathf.Ceil(Mathf.Max(x_dist, y_dist))/snapValue);
|
||||
int y_iter = (int)(Mathf.Ceil(Mathf.Max(x_dist, z_dist))/snapValue);
|
||||
int z_iter = (int)(Mathf.Ceil(Mathf.Max(z_dist, y_dist))/snapValue);
|
||||
|
||||
int max = Mathf.Max( Mathf.Max(x_iter, y_iter), z_iter );
|
||||
int div = 1;
|
||||
while(max/div> MAX_LINES)
|
||||
{
|
||||
div++;
|
||||
}
|
||||
|
||||
Vector3[] vertices_t = null;
|
||||
Vector3[] normals_t = null;
|
||||
Color[] colors_t = null;
|
||||
int[] indices_t = null;
|
||||
|
||||
List<Vector3> vertices_m = new List<Vector3>();
|
||||
List<Vector3> normals_m = new List<Vector3>();
|
||||
List<Color> colors_m = new List<Color>();
|
||||
List<int> indices_m = new List<int>();
|
||||
|
||||
// X plane
|
||||
DrawHalfGrid(cam, pivot, up, right, snapValue*div, x_iter/div, colors[0], alphaBump, out vertices_t, out normals_t, out colors_t, out indices_t, 0);
|
||||
vertices_m.AddRange(vertices_t);
|
||||
normals_m.AddRange(normals_t);
|
||||
colors_m.AddRange(colors_t);
|
||||
indices_m.AddRange(indices_t);
|
||||
|
||||
// Y plane
|
||||
DrawHalfGrid(cam, pivot, right, forward, snapValue*div, y_iter/div, colors[1], alphaBump, out vertices_t, out normals_t, out colors_t, out indices_t, vertices_m.Count);
|
||||
vertices_m.AddRange(vertices_t);
|
||||
normals_m.AddRange(normals_t);
|
||||
colors_m.AddRange(colors_t);
|
||||
indices_m.AddRange(indices_t);
|
||||
|
||||
// Z plane
|
||||
DrawHalfGrid(cam, pivot, forward, up, snapValue*div, z_iter/div, colors[2], alphaBump, out vertices_t, out normals_t, out colors_t, out indices_t, vertices_m.Count);
|
||||
vertices_m.AddRange(vertices_t);
|
||||
normals_m.AddRange(normals_t);
|
||||
colors_m.AddRange(colors_t);
|
||||
indices_m.AddRange(indices_t);
|
||||
|
||||
gridMesh.Clear();
|
||||
gridMesh.vertices = vertices_m.ToArray();
|
||||
gridMesh.normals = normals_m.ToArray();
|
||||
gridMesh.subMeshCount = 1;
|
||||
gridMesh.uv = new Vector2[vertices_m.Count];
|
||||
gridMesh.colors = colors_m.ToArray();
|
||||
gridMesh.SetIndices(indices_m.ToArray(), MeshTopology.Lines, 0);
|
||||
|
||||
}
|
||||
|
||||
private static void DrawHalfGrid(Camera cam, Vector3 pivot, Vector3 tan, Vector3 bitan, float increment, int iterations, Color secondary, float alphaBump,
|
||||
out Vector3[] vertices,
|
||||
out Vector3[] normals,
|
||||
out Color[] colors,
|
||||
out int[] indices, int offset)
|
||||
{
|
||||
Color primary = secondary;
|
||||
primary.a += alphaBump;
|
||||
|
||||
float len = increment * iterations;
|
||||
|
||||
int highlightOffsetTan = (int)((pg_Util.ValueFromMask(pivot, tan) % (increment * majorLineIncrement)) / increment);
|
||||
int highlightOffsetBitan = (int)((pg_Util.ValueFromMask(pivot, bitan) % (increment * majorLineIncrement)) / increment);
|
||||
|
||||
iterations++;
|
||||
|
||||
// this could only use 3 verts per line
|
||||
float fade = .75f;
|
||||
float fadeDist = len * fade;
|
||||
Vector3 nrm = Vector3.Cross(tan, bitan);
|
||||
|
||||
vertices = new Vector3[iterations*6-3];
|
||||
normals = new Vector3[iterations*6-3];
|
||||
indices = new int[iterations*8-4];
|
||||
colors = new Color[iterations*6-3];
|
||||
|
||||
vertices[0] = pivot;
|
||||
vertices[1] = (pivot + bitan*fadeDist);
|
||||
vertices[2] = (pivot + bitan*len);
|
||||
|
||||
normals[0] = nrm;
|
||||
normals[1] = nrm;
|
||||
normals[2] = nrm;
|
||||
|
||||
indices[0] = 0 + offset;
|
||||
indices[1] = 1 + offset;
|
||||
indices[2] = 1 + offset;
|
||||
indices[3] = 2 + offset;
|
||||
|
||||
colors[0] = primary;
|
||||
colors[1] = primary;
|
||||
colors[2] = primary;
|
||||
colors[2].a = 0f;
|
||||
|
||||
|
||||
int n = 4;
|
||||
int v = 3;
|
||||
|
||||
for(int i = 1; i < iterations; i++)
|
||||
{
|
||||
// MeshTopology doesn't exist prior to Unity 4
|
||||
vertices[v+0] = pivot + i * tan * increment;
|
||||
vertices[v+1] = (pivot + bitan*fadeDist) + i * tan * increment;
|
||||
vertices[v+2] = (pivot + bitan*len) + i * tan * increment;
|
||||
|
||||
vertices[v+3] = pivot + i * bitan * increment;
|
||||
vertices[v+4] = (pivot + tan*fadeDist) + i * bitan * increment;
|
||||
vertices[v+5] = (pivot + tan*len) + i * bitan * increment;
|
||||
|
||||
normals[v+0] = nrm;
|
||||
normals[v+1] = nrm;
|
||||
normals[v+2] = nrm;
|
||||
normals[v+3] = nrm;
|
||||
normals[v+4] = nrm;
|
||||
normals[v+5] = nrm;
|
||||
|
||||
indices[n+0] = v + 0 + offset;
|
||||
indices[n+1] = v + 1 + offset;
|
||||
indices[n+2] = v + 1 + offset;
|
||||
indices[n+3] = v + 2 + offset;
|
||||
indices[n+4] = v + 3 + offset;
|
||||
indices[n+5] = v + 4 + offset;
|
||||
indices[n+6] = v + 4 + offset;
|
||||
indices[n+7] = v + 5 + offset;
|
||||
|
||||
float alpha = (i/(float)iterations);
|
||||
alpha = alpha < fade ? 1f : 1f - ( (alpha-fade)/(1-fade) );
|
||||
|
||||
Color col = (i+highlightOffsetTan) % majorLineIncrement == 0 ? primary : secondary;
|
||||
col.a *= alpha;
|
||||
|
||||
colors[v+0] = col;
|
||||
colors[v+1] = col;
|
||||
colors[v+2] = col;
|
||||
colors[v+2].a = 0f;
|
||||
|
||||
col = (i+highlightOffsetBitan) % majorLineIncrement == 0 ? primary : secondary;
|
||||
col.a *= alpha;
|
||||
|
||||
colors[v+3] = col;
|
||||
colors[v+4] = col;
|
||||
colors[v+5] = col;
|
||||
colors[v+5].a = 0f;
|
||||
|
||||
n += 8;
|
||||
v += 6;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a plane grid using pivot point, the right and forward directions, and how far each direction should extend
|
||||
*/
|
||||
private static void DrawFullGrid(Camera cam, Vector3 pivot, Vector3 tan, Vector3 bitan, float increment, int iterations, int div, Color secondary, float alphaBump)
|
||||
{
|
||||
Color primary = secondary;
|
||||
primary.a += alphaBump;
|
||||
|
||||
float len = iterations * increment;
|
||||
|
||||
iterations++;
|
||||
|
||||
Vector3 start = pivot - tan*(len/2f) - bitan*(len/2f);
|
||||
start = pg_Util.SnapValue(start, bitan+tan, increment);
|
||||
|
||||
float inc = increment;
|
||||
int highlightOffsetTan = (int)((pg_Util.ValueFromMask(start, tan) % (inc*majorLineIncrement)) / inc);
|
||||
int highlightOffsetBitan = (int)((pg_Util.ValueFromMask(start, bitan) % (inc*majorLineIncrement)) / inc);
|
||||
|
||||
Vector3[] lines = new Vector3[iterations * 4];
|
||||
int[] indices = new int[iterations * 4];
|
||||
Color[] colors = new Color[iterations * 4];
|
||||
|
||||
int v = 0, t = 0;
|
||||
|
||||
for(int i = 0; i < iterations; i++)
|
||||
{
|
||||
Vector3 a = start + tan * i * increment;
|
||||
Vector3 b = start + bitan * i * increment;
|
||||
|
||||
lines[v+0] = a;
|
||||
lines[v+1] = a + bitan * len;
|
||||
|
||||
lines[v+2] = b;
|
||||
lines[v+3] = b + tan * len;
|
||||
|
||||
indices[t++] = v;
|
||||
indices[t++] = v+1;
|
||||
indices[t++] = v+2;
|
||||
indices[t++] = v+3;
|
||||
|
||||
Color col = (i + highlightOffsetTan) % majorLineIncrement == 0 ? primary : secondary;
|
||||
|
||||
// tan
|
||||
colors[v+0] = col;
|
||||
colors[v+1] = col;
|
||||
|
||||
col = (i + highlightOffsetBitan) % majorLineIncrement == 0 ? primary : secondary;
|
||||
|
||||
// bitan
|
||||
colors[v+2] = col;
|
||||
colors[v+3] = col;
|
||||
|
||||
v += 4;
|
||||
}
|
||||
|
||||
Vector3 nrm = Vector3.Cross(tan, bitan);
|
||||
Vector3[] nrms = new Vector3[lines.Length];
|
||||
for(int i = 0; i < lines.Length; i++)
|
||||
nrms[i] = nrm;
|
||||
|
||||
|
||||
gridMesh.Clear();
|
||||
gridMesh.vertices = lines;
|
||||
gridMesh.normals = nrms;
|
||||
gridMesh.subMeshCount = 1;
|
||||
gridMesh.uv = new Vector2[lines.Length];
|
||||
gridMesh.colors = colors;
|
||||
gridMesh.SetIndices(indices, MeshTopology.Lines, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the distance from pivot to frustum plane in the order of
|
||||
* float[] { tan, bitan, -tan, -bitan }
|
||||
*/
|
||||
private static float[] GetDistanceToFrustumPlanes(Camera cam, Vector3 pivot, Vector3 tan, Vector3 bitan, float minDist)
|
||||
{
|
||||
Ray[] rays = new Ray[4]
|
||||
{
|
||||
new Ray(pivot, tan),
|
||||
new Ray(pivot, bitan),
|
||||
new Ray(pivot, -tan),
|
||||
new Ray(pivot, -bitan)
|
||||
};
|
||||
|
||||
float[] intersects = new float[4] { minDist, minDist, minDist, minDist };
|
||||
bool[] intersection_found = new bool[4] { false, false, false, false };
|
||||
|
||||
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(cam);
|
||||
foreach(Plane p in planes)
|
||||
{
|
||||
float dist;
|
||||
float t = 0;
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
if(p.Raycast(rays[i], out dist))
|
||||
{
|
||||
t = Vector3.Distance(pivot, rays[i].GetPoint(dist));
|
||||
|
||||
if(t < intersects[i] || !intersection_found[i])
|
||||
{
|
||||
intersection_found[i] = true;
|
||||
intersects[i] = Mathf.Max(minDist, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return intersects;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6367e9291991f466897f892a41dd75ff
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace ProGrids
|
||||
{
|
||||
|
||||
public class pg_ParameterWindow : EditorWindow
|
||||
{
|
||||
public pg_Editor editor;
|
||||
|
||||
GUIContent gc_predictiveGrid = new GUIContent("Predictive Grid", "If enabled, the grid will automatically render at the optimal axis based on movement.");
|
||||
GUIContent gc_snapAsGroup = new GUIContent("Snap as Group", "If enabled, selected objects will keep their relative offsets when moving. If disabled, every object in the selection is snapped to grid independently.");
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Snap Settings", EditorStyles.boldLabel);
|
||||
|
||||
float snap = editor.GetSnapIncrement();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
snap = EditorGUILayout.FloatField("Snap Value", snap);
|
||||
|
||||
if(EditorGUI.EndChangeCheck())
|
||||
editor.SetSnapIncrement(snap);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
int majorLineIncrement = EditorPrefs.GetInt(pg_Constant.MajorLineIncrement, 10);
|
||||
majorLineIncrement = EditorGUILayout.IntField("Major Line Increment", majorLineIncrement);
|
||||
majorLineIncrement = majorLineIncrement < 2 ? 2 : majorLineIncrement > 128 ? 128 : majorLineIncrement;
|
||||
if(EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorPrefs.SetInt(pg_Constant.MajorLineIncrement, majorLineIncrement);
|
||||
pg_GridRenderer.majorLineIncrement = majorLineIncrement;
|
||||
pg_Editor.ForceRepaint();
|
||||
}
|
||||
|
||||
editor.ScaleSnapEnabled = EditorGUILayout.Toggle("Snap On Scale", editor.ScaleSnapEnabled);
|
||||
|
||||
SnapUnit _gridUnits = (SnapUnit)(EditorPrefs.HasKey(pg_Constant.GridUnit) ? EditorPrefs.GetInt(pg_Constant.GridUnit) : 0);
|
||||
|
||||
bool snapAsGroup = editor.snapAsGroup;
|
||||
snapAsGroup = EditorGUILayout.Toggle(gc_snapAsGroup, snapAsGroup);
|
||||
if(snapAsGroup != editor.snapAsGroup)
|
||||
editor.snapAsGroup = snapAsGroup;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
_gridUnits = (SnapUnit)EditorGUILayout.EnumPopup("Grid Units", _gridUnits);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
editor.angleValue = EditorGUILayout.Slider("Angle", editor.angleValue, 0f, 180f);
|
||||
if(EditorGUI.EndChangeCheck())
|
||||
SceneView.RepaintAll();
|
||||
|
||||
if( EditorGUI.EndChangeCheck() )
|
||||
{
|
||||
EditorPrefs.SetInt(pg_Constant.GridUnit, (int) _gridUnits);
|
||||
editor.LoadPreferences();
|
||||
}
|
||||
|
||||
bool tmp = editor.predictiveGrid;
|
||||
tmp = EditorGUILayout.Toggle(gc_predictiveGrid, tmp);
|
||||
if( tmp != editor.predictiveGrid )
|
||||
{
|
||||
editor.predictiveGrid = tmp;
|
||||
EditorPrefs.SetBool(pg_Constant.PredictiveGrid, tmp);
|
||||
}
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if( GUILayout.Button("Done"))
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 361cb9f8460027f4a88a1b9610de18c0
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,176 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace ProGrids
|
||||
{
|
||||
public class pg_Preferences
|
||||
{
|
||||
static Color _gridColorX;
|
||||
static Color _gridColorY;
|
||||
static Color _gridColorZ;
|
||||
static float _alphaBump;
|
||||
static bool _scaleSnapEnabled;
|
||||
static int _snapMethod;
|
||||
static float _BracketIncreaseValue;
|
||||
static SnapUnit _GridUnits;
|
||||
static bool _syncUnitySnap;
|
||||
|
||||
static KeyCode _IncreaseGridSize = KeyCode.Equals;
|
||||
static KeyCode _DecreaseGridSize = KeyCode.Minus;
|
||||
static KeyCode _NudgePerspectiveBackward = KeyCode.LeftBracket;
|
||||
static KeyCode _NudgePerspectiveForward = KeyCode.RightBracket;
|
||||
static KeyCode _NudgePerspectiveReset = KeyCode.Alpha0;
|
||||
static KeyCode _CyclePerspective = KeyCode.Backslash;
|
||||
|
||||
|
||||
/** Defaults **/
|
||||
public static Color GRID_COLOR_X = new Color(.9f, .46f, .46f, .15f);
|
||||
public static Color GRID_COLOR_Y = new Color(.46f, .9f, .46f, .15f);
|
||||
public static Color GRID_COLOR_Z = new Color(.46f, .46f, .9f, .15f);
|
||||
public static float ALPHA_BUMP = .25f;
|
||||
public static bool USE_AXIS_CONSTRAINTS = false;
|
||||
public static bool SHOW_GRID = true;
|
||||
|
||||
static string[] SnapMethod = new string[]
|
||||
{
|
||||
"Snap on Selected Axis",
|
||||
"Snap on All Axes"
|
||||
};
|
||||
|
||||
static int[] SnapVals = new int[] { 1, 0 };
|
||||
static bool prefsLoaded = false;
|
||||
|
||||
[PreferenceItem("ProGrids")]
|
||||
public static void PreferencesGUI()
|
||||
{
|
||||
if (!prefsLoaded)
|
||||
prefsLoaded = LoadPreferences();
|
||||
|
||||
// EditorGUILayout.HelpBox("Changes will take effect on the next ProGrids open.", MessageType.Info);
|
||||
|
||||
GUILayout.Label("Grid Colors per Axis", EditorStyles.boldLabel);
|
||||
_gridColorX = EditorGUILayout.ColorField("X Axis", _gridColorX);
|
||||
_gridColorY = EditorGUILayout.ColorField("Y Axis", _gridColorY);
|
||||
_gridColorZ = EditorGUILayout.ColorField("Z Axis", _gridColorZ);
|
||||
|
||||
_alphaBump = EditorGUILayout.Slider(new GUIContent("Tenth Line Alpha", "Every 10th line will have it's alpha value bumped by this amount."), _alphaBump, 0f, 1f);
|
||||
|
||||
// not used
|
||||
// _BracketIncreaseValue = EditorGUILayout.FloatField(new GUIContent("Grid Increment Value", "Affects the amount by which the bracket keys will increment or decrement that snap value."), _BracketIncreaseValue);
|
||||
|
||||
_GridUnits = (SnapUnit)EditorGUILayout.EnumPopup("Grid Units", _GridUnits);
|
||||
|
||||
_scaleSnapEnabled = EditorGUILayout.Toggle("Snap On Scale", _scaleSnapEnabled);
|
||||
|
||||
// GUILayout.BeginHorizontal();
|
||||
// EditorGUILayout.PrefixLabel(new GUIContent("Axis Constraints", "If toggled, objects will be automatically grid aligned on all axes when moving."));
|
||||
|
||||
_snapMethod = EditorGUILayout.IntPopup("Snap Method", _snapMethod, SnapMethod, SnapVals);
|
||||
|
||||
_syncUnitySnap = EditorGUILayout.Toggle("Sync w/ Unity Snap", _syncUnitySnap);
|
||||
|
||||
// GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Label("Shortcuts", EditorStyles.boldLabel);
|
||||
_IncreaseGridSize = (KeyCode)EditorGUILayout.EnumPopup("Increase Grid Size", _IncreaseGridSize);
|
||||
_DecreaseGridSize = (KeyCode)EditorGUILayout.EnumPopup("Decrease Grid Size", _DecreaseGridSize);
|
||||
_NudgePerspectiveBackward = (KeyCode)EditorGUILayout.EnumPopup("Nudge Perspective Backward", _NudgePerspectiveBackward);
|
||||
_NudgePerspectiveForward = (KeyCode)EditorGUILayout.EnumPopup("Nudge Perspective Forward", _NudgePerspectiveForward);
|
||||
_NudgePerspectiveReset = (KeyCode)EditorGUILayout.EnumPopup("Nudge Perspective Reset", _NudgePerspectiveReset);
|
||||
_CyclePerspective = (KeyCode)EditorGUILayout.EnumPopup("Cycle Perspective", _CyclePerspective);
|
||||
|
||||
if (GUILayout.Button("Reset"))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Delete ProGrids editor preferences?", "Are you sure you want to delete these?, this action cannot be undone.", "Yes", "No"))
|
||||
ResetPrefs();
|
||||
}
|
||||
|
||||
if (GUI.changed)
|
||||
SetPreferences();
|
||||
}
|
||||
|
||||
public static bool LoadPreferences()
|
||||
{
|
||||
_scaleSnapEnabled = EditorPrefs.HasKey("scaleSnapEnabled") ? EditorPrefs.GetBool("scaleSnapEnabled") : false;
|
||||
_gridColorX = (EditorPrefs.HasKey("gridColorX")) ? pg_Util.ColorWithString(EditorPrefs.GetString("gridColorX")) : GRID_COLOR_X;
|
||||
_gridColorY = (EditorPrefs.HasKey("gridColorY")) ? pg_Util.ColorWithString(EditorPrefs.GetString("gridColorY")) : GRID_COLOR_Y;
|
||||
_gridColorZ = (EditorPrefs.HasKey("gridColorZ")) ? pg_Util.ColorWithString(EditorPrefs.GetString("gridColorZ")) : GRID_COLOR_Z;
|
||||
_alphaBump = (EditorPrefs.HasKey("pg_alphaBump")) ? EditorPrefs.GetFloat("pg_alphaBump") : ALPHA_BUMP;
|
||||
_snapMethod = System.Convert.ToInt32(
|
||||
(EditorPrefs.HasKey(pg_Constant.UseAxisConstraints)) ? EditorPrefs.GetBool(pg_Constant.UseAxisConstraints) : USE_AXIS_CONSTRAINTS
|
||||
);
|
||||
_BracketIncreaseValue = EditorPrefs.HasKey(pg_Constant.BracketIncreaseValue) ? EditorPrefs.GetFloat(pg_Constant.BracketIncreaseValue) : .25f;
|
||||
_GridUnits = (SnapUnit)(EditorPrefs.HasKey(pg_Constant.GridUnit) ? EditorPrefs.GetInt(pg_Constant.GridUnit) : 0);
|
||||
_syncUnitySnap = EditorPrefs.GetBool(pg_Constant.SyncUnitySnap, true);
|
||||
|
||||
_IncreaseGridSize = EditorPrefs.HasKey("pg_Editor::IncreaseGridSize")
|
||||
? (KeyCode)EditorPrefs.GetInt("pg_Editor::IncreaseGridSize")
|
||||
: KeyCode.Equals;
|
||||
_DecreaseGridSize = EditorPrefs.HasKey("pg_Editor::DecreaseGridSize")
|
||||
? (KeyCode)EditorPrefs.GetInt("pg_Editor::DecreaseGridSize")
|
||||
: KeyCode.Minus;
|
||||
_NudgePerspectiveBackward = EditorPrefs.HasKey("pg_Editor::NudgePerspectiveBackward")
|
||||
? (KeyCode)EditorPrefs.GetInt("pg_Editor::NudgePerspectiveBackward")
|
||||
: KeyCode.LeftBracket;
|
||||
_NudgePerspectiveForward = EditorPrefs.HasKey("pg_Editor::NudgePerspectiveForward")
|
||||
? (KeyCode)EditorPrefs.GetInt("pg_Editor::NudgePerspectiveForward")
|
||||
: KeyCode.RightBracket;
|
||||
_NudgePerspectiveReset = EditorPrefs.HasKey("pg_Editor::NudgePerspectiveReset")
|
||||
? (KeyCode)EditorPrefs.GetInt("pg_Editor::NudgePerspectiveReset")
|
||||
: KeyCode.Alpha0;
|
||||
_CyclePerspective = EditorPrefs.HasKey("pg_Editor::CyclePerspective")
|
||||
? (KeyCode)EditorPrefs.GetInt("pg_Editor::CyclePerspective")
|
||||
: KeyCode.Backslash;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void SetPreferences()
|
||||
{
|
||||
EditorPrefs.SetBool("scaleSnapEnabled", _scaleSnapEnabled);
|
||||
EditorPrefs.SetString("gridColorX", _gridColorX.ToString("f3"));
|
||||
EditorPrefs.SetString("gridColorY", _gridColorY.ToString("f3"));
|
||||
EditorPrefs.SetString("gridColorZ", _gridColorZ.ToString("f3"));
|
||||
EditorPrefs.SetFloat("pg_alphaBump", _alphaBump);
|
||||
EditorPrefs.SetBool(pg_Constant.UseAxisConstraints, System.Convert.ToBoolean(_snapMethod));
|
||||
EditorPrefs.SetFloat(pg_Constant.BracketIncreaseValue, _BracketIncreaseValue);
|
||||
EditorPrefs.SetInt(pg_Constant.GridUnit, (int)_GridUnits);
|
||||
EditorPrefs.SetBool(pg_Constant.SyncUnitySnap, _syncUnitySnap);
|
||||
EditorPrefs.SetInt("pg_Editor::IncreaseGridSize", (int)_IncreaseGridSize);
|
||||
EditorPrefs.SetInt("pg_Editor::DecreaseGridSize", (int)_DecreaseGridSize);
|
||||
EditorPrefs.SetInt("pg_Editor::NudgePerspectiveBackward", (int)_NudgePerspectiveBackward);
|
||||
EditorPrefs.SetInt("pg_Editor::NudgePerspectiveForward", (int)_NudgePerspectiveForward);
|
||||
EditorPrefs.SetInt("pg_Editor::NudgePerspectiveReset", (int)_NudgePerspectiveReset);
|
||||
EditorPrefs.SetInt("pg_Editor::CyclePerspective", (int)_CyclePerspective);
|
||||
|
||||
if (pg_Editor.instance != null)
|
||||
{
|
||||
pg_Editor.instance.LoadPreferences();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ResetPrefs()
|
||||
{
|
||||
EditorPrefs.DeleteKey("scaleSnapEnabled");
|
||||
EditorPrefs.DeleteKey("gridColorX");
|
||||
EditorPrefs.DeleteKey("gridColorY");
|
||||
EditorPrefs.DeleteKey("gridColorZ");
|
||||
EditorPrefs.DeleteKey("pg_alphaBump");
|
||||
EditorPrefs.DeleteKey(pg_Constant.UseAxisConstraints);
|
||||
EditorPrefs.DeleteKey(pg_Constant.BracketIncreaseValue);
|
||||
EditorPrefs.DeleteKey(pg_Constant.GridUnit);
|
||||
EditorPrefs.DeleteKey("showgrid");
|
||||
EditorPrefs.DeleteKey(pg_Constant.SnapMultiplier);
|
||||
EditorPrefs.DeleteKey(pg_Constant.SyncUnitySnap);
|
||||
EditorPrefs.DeleteKey("pg_Editor::IncreaseGridSize");
|
||||
EditorPrefs.DeleteKey("pg_Editor::DecreaseGridSize");
|
||||
EditorPrefs.DeleteKey("pg_Editor::NudgePerspectiveBackward");
|
||||
EditorPrefs.DeleteKey("pg_Editor::NudgePerspectiveForward");
|
||||
EditorPrefs.DeleteKey("pg_Editor::NudgePerspectiveReset");
|
||||
EditorPrefs.DeleteKey("pg_Editor::CyclePerspective");
|
||||
|
||||
LoadPreferences();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19a8719bbc0e11f46b9cd7b9debdfc12
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace ProGrids
|
||||
{
|
||||
/**
|
||||
* A substitute for GUIContent that offers some additional functionality.
|
||||
*/
|
||||
[System.Serializable]
|
||||
public class pg_ToggleContent
|
||||
{
|
||||
public string text_on, text_off;
|
||||
public Texture2D image_on, image_off;
|
||||
public string tooltip;
|
||||
|
||||
GUIContent gc = new GUIContent();
|
||||
|
||||
public pg_ToggleContent(string t_on, string t_off, string tooltip)
|
||||
{
|
||||
this.text_on = t_on;
|
||||
this.text_off = t_off;
|
||||
this.image_on = (Texture2D)null;
|
||||
this.image_off = (Texture2D)null;
|
||||
this.tooltip = tooltip;
|
||||
|
||||
gc.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public pg_ToggleContent(string t_on, string t_off, Texture2D i_on, Texture2D i_off, string tooltip)
|
||||
{
|
||||
this.text_on = t_on;
|
||||
this.text_off = t_off;
|
||||
this.image_on = i_on;
|
||||
this.image_off = i_off;
|
||||
this.tooltip = tooltip;
|
||||
|
||||
gc.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public static bool ToggleButton(Rect r, pg_ToggleContent content, bool enabled, GUIStyle imageStyle, GUIStyle altStyle)
|
||||
{
|
||||
content.gc.image = enabled ? content.image_on : content.image_off;
|
||||
content.gc.text = content.gc.image == null ? (enabled ? content.text_on : content.text_off) : "";
|
||||
|
||||
return GUI.Button(r, content.gc, content.gc.image != null ? imageStyle : altStyle);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66b1c4a9ec825c7458f935aae34d66b1
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user