add games
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#define PRO
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace ProGrids
|
||||
{
|
||||
public static class pg_Constant
|
||||
{
|
||||
public const string ProGridsIsEnabled = "pgProGridsIsEnabled";
|
||||
public const string ProGridsIsExtended = "pgProGridsIsExtended";
|
||||
public const string ProGridsUpgradeURL = "http://u3d.as/content/six-by-seven-studio/pro-grids/3ov";
|
||||
public const string SnapValue = "pgSnapValue";
|
||||
public const string SnapMultiplier = "pgSnapMultiplier";
|
||||
public const string SnapEnabled = "pgSnapEnabled";
|
||||
public const string UseAxisConstraints = "pgUseAxisConstraints";
|
||||
public const string LastOrthoToggledRotation = "pgLastOrthoToggledRotation";
|
||||
public const string BracketIncreaseValue = "pgBracketIncreaseValue";
|
||||
public const string GridUnit = "pg_GridUnit";
|
||||
public const string LockGrid = "pg_LockGrid";
|
||||
public const string LockedGridPivot = "pg_LockedGridPivot";
|
||||
public const string PGVersion = "pg_Version";
|
||||
public const string GridAxis = "pg_GridAxis";
|
||||
public const string PerspGrid = "pg_PerspGrid";
|
||||
public const string SnapScale = "pg_SnapOnScale";
|
||||
public const string PredictiveGrid = "pg_PredictiveGrid";
|
||||
public const string SnapAsGroup = "pg_SnapAsGroup";
|
||||
public const string MajorLineIncrement = "pg_MajorLineIncrement";
|
||||
public const string SyncUnitySnap = "pg_SyncUnitySnap";
|
||||
|
||||
public const float METER = 1f;
|
||||
#if PRO
|
||||
public const float CENTIMETER = .01f;
|
||||
public const float MILLIMETER = .001f;
|
||||
public const float INCH = 0.0253999862840074f;
|
||||
public const float FOOT = 0.3048f;
|
||||
public const float YARD = 1.09361f;
|
||||
public const float PARSEC = 5f;
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b2cff15c28de0f4ba38eafc29cd64fa
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
102
assignment10final/Assets/ProCore/ProGrids/Classes/pg_Enum.cs
Normal file
102
assignment10final/Assets/ProCore/ProGrids/Classes/pg_Enum.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
#define PRO
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace ProGrids
|
||||
{
|
||||
public enum Axis {
|
||||
None = 0x0,
|
||||
X = 0x1,
|
||||
Y = 0x2,
|
||||
Z = 0x4,
|
||||
NegX = 0x8,
|
||||
NegY = 0x16,
|
||||
NegZ = 0x32
|
||||
}
|
||||
|
||||
public enum SnapUnit {
|
||||
Meter,
|
||||
#if PRO
|
||||
Centimeter,
|
||||
Millimeter,
|
||||
Inch,
|
||||
Foot,
|
||||
Yard,
|
||||
Parsec
|
||||
#endif
|
||||
}
|
||||
|
||||
public static class pg_Enum
|
||||
{
|
||||
/**
|
||||
* Multiplies a Vector3 using the inverse value of an axis (eg, Axis.Y becomes Vector3(1, 0, 1) )
|
||||
*/
|
||||
public static Vector3 InverseAxisMask(Vector3 v, Axis axis)
|
||||
{
|
||||
switch(axis)
|
||||
{
|
||||
case Axis.X:
|
||||
case Axis.NegX:
|
||||
return Vector3.Scale(v, new Vector3(0f, 1f, 1f));
|
||||
|
||||
case Axis.Y:
|
||||
case Axis.NegY:
|
||||
return Vector3.Scale(v, new Vector3(1f, 0f, 1f));
|
||||
|
||||
case Axis.Z:
|
||||
case Axis.NegZ:
|
||||
return Vector3.Scale(v, new Vector3(1f, 1f, 0f));
|
||||
|
||||
default:
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 AxisMask(Vector3 v, Axis axis)
|
||||
{
|
||||
switch(axis)
|
||||
{
|
||||
case Axis.X:
|
||||
case Axis.NegX:
|
||||
return Vector3.Scale(v, new Vector3(1f, 0f, 0f));
|
||||
|
||||
case Axis.Y:
|
||||
case Axis.NegY:
|
||||
return Vector3.Scale(v, new Vector3(0f, 1f, 0f));
|
||||
|
||||
case Axis.Z:
|
||||
case Axis.NegZ:
|
||||
return Vector3.Scale(v, new Vector3(0f, 0f, 1f));
|
||||
|
||||
default:
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public static float SnapUnitValue(SnapUnit su)
|
||||
{
|
||||
switch(su)
|
||||
{
|
||||
case SnapUnit.Meter:
|
||||
return pg_Constant.METER;
|
||||
#if PRO
|
||||
case SnapUnit.Centimeter:
|
||||
return pg_Constant.CENTIMETER;
|
||||
case SnapUnit.Millimeter:
|
||||
return pg_Constant.MILLIMETER;
|
||||
case SnapUnit.Inch:
|
||||
return pg_Constant.INCH;
|
||||
case SnapUnit.Foot:
|
||||
return pg_Constant.FOOT;
|
||||
case SnapUnit.Yard:
|
||||
return pg_Constant.YARD;
|
||||
case SnapUnit.Parsec:
|
||||
return pg_Constant.PARSEC;
|
||||
#endif
|
||||
default:
|
||||
return pg_Constant.METER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3b407d7cf143004f8e7f9de0969d275
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,71 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ProGrids
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public static class pg_IconUtility
|
||||
{
|
||||
const string ICON_FOLDER_PATH = "ProGridsToggles";
|
||||
private static string iconFolderPath = "Assets/ProCore/ProGrids/GUI/ProGridsToggles/";
|
||||
|
||||
static pg_IconUtility()
|
||||
{
|
||||
if(!Directory.Exists(iconFolderPath))
|
||||
{
|
||||
string folder = FindFolder(ICON_FOLDER_PATH);
|
||||
|
||||
if(Directory.Exists(folder))
|
||||
iconFolderPath = folder;
|
||||
}
|
||||
}
|
||||
|
||||
private static string FindFolder(string folder)
|
||||
{
|
||||
#if !UNITY_WEBPLAYER
|
||||
string single = folder.Replace("\\", "/").Substring(folder.LastIndexOf('/') + 1);
|
||||
|
||||
string[] matches = Directory.GetDirectories("Assets/", single, SearchOption.AllDirectories);
|
||||
|
||||
foreach(string str in matches)
|
||||
{
|
||||
string path = str.Replace("\\", "/");
|
||||
|
||||
if(path.Contains(folder))
|
||||
{
|
||||
if(!path.EndsWith("/"))
|
||||
path += "/";
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Debug.LogError("Could not locate ProGrids/GUI/ProGridsToggles folder. The ProGrids folder may be moved, but the contents of ProGrids must remain unmodified.");
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static Texture2D LoadIcon(string iconName)
|
||||
{
|
||||
string iconPath = string.Format("{0}{1}", iconFolderPath, iconName);
|
||||
|
||||
if(!File.Exists(iconPath))
|
||||
{
|
||||
Debug.LogError("ProGrids failed to locate menu image: " + iconName + ".\nThis can happen if the GUI folder is moved or deleted. Deleting and re-importing ProGrids will fix this error.");
|
||||
return (Texture2D) null;
|
||||
}
|
||||
|
||||
return LoadAssetAtPath<Texture2D>(iconPath);
|
||||
}
|
||||
|
||||
static T LoadAssetAtPath<T>(string path) where T : UnityEngine.Object
|
||||
{
|
||||
return (T) AssetDatabase.LoadAssetAtPath(path, typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 192dd82c3ebd3b647ae292174a2f36a6
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace ProGrids
|
||||
{
|
||||
/**
|
||||
* ProGridsNoSnapAttribute tells ProGrids to skip snapping on this object.
|
||||
* Note - On Unity versions less than 5.2 this will not take effect until after a script
|
||||
* reload.
|
||||
*/
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
|
||||
public class ProGridsNoSnapAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* ProGridsConditionalSnapAttribute tells ProGrids to check `bool IsSnapEnabled()` function on this object.
|
||||
*/
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
|
||||
public class ProGridsConditionalSnapAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a00a369d82c4f7f47ae4dc5c2be474b8
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,47 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
|
||||
/**
|
||||
* Despite the MonoBehaviour inheritance, this is an Editor-only script.
|
||||
*/
|
||||
[ExecuteInEditMode]
|
||||
public class pg_SceneMeshRender : MonoBehaviour
|
||||
{
|
||||
// HideFlags.DontSaveInEditor isn't exposed for whatever reason, so do the bit math on ints
|
||||
// and just cast to HideFlags.
|
||||
// HideFlags.HideInHierarchy | HideFlags.DontSaveInEditor | HideFlags.NotEditable
|
||||
HideFlags SceneCameraHideFlags = (HideFlags) (1 | 4 | 8);
|
||||
|
||||
public Mesh mesh;
|
||||
public Material material;
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if(mesh) DestroyImmediate(mesh);
|
||||
if(material) DestroyImmediate(material);
|
||||
}
|
||||
|
||||
void OnRenderObject()
|
||||
{
|
||||
// instead of relying on 'SceneCamera' string comparison, check if the hideflags match.
|
||||
// this could probably even just check for one bit match, since chances are that any
|
||||
// game view camera isn't going to have hideflags set.
|
||||
if( (Camera.current.gameObject.hideFlags & SceneCameraHideFlags) != SceneCameraHideFlags || Camera.current.name != "SceneCamera" )
|
||||
return;
|
||||
|
||||
if(material == null || mesh == null)
|
||||
{
|
||||
|
||||
GameObject.DestroyImmediate(this.gameObject);
|
||||
// Debug.Log("NULL MESH || MATERIAL");
|
||||
return;
|
||||
}
|
||||
|
||||
material.SetPass(0);
|
||||
Graphics.DrawMeshNow(mesh, Vector3.zero, Quaternion.identity, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb0712ebbf8b03f46a1c36447cee2893
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
369
assignment10final/Assets/ProCore/ProGrids/Classes/pg_Util.cs
Normal file
369
assignment10final/Assets/ProCore/ProGrids/Classes/pg_Util.cs
Normal file
@@ -0,0 +1,369 @@
|
||||
#if UNITY_EDITOR || !(UNITY_WP_8_1 || UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0 || UNITY_WINRT || UNITY_WINRT_8_1 || UNITY_WINRT_10_0)
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ProGrids
|
||||
{
|
||||
public static class pg_Util
|
||||
{
|
||||
public static Color ColorWithString(string value)
|
||||
{
|
||||
string valid = "01234567890.,";
|
||||
value = new string(value.Where(c => valid.Contains(c)).ToArray());
|
||||
string[] rgba = value.Split(',');
|
||||
|
||||
// BRIGHT pink
|
||||
if(rgba.Length < 4)
|
||||
return new Color(1f, 0f, 1f, 1f);
|
||||
|
||||
return new Color(
|
||||
float.Parse(rgba[0]),
|
||||
float.Parse(rgba[1]),
|
||||
float.Parse(rgba[2]),
|
||||
float.Parse(rgba[3]));
|
||||
}
|
||||
|
||||
private static Vector3 VectorToMask(Vector3 vec)
|
||||
{
|
||||
return new Vector3( Mathf.Abs(vec.x) > Mathf.Epsilon ? 1f : 0f,
|
||||
Mathf.Abs(vec.y) > Mathf.Epsilon ? 1f : 0f,
|
||||
Mathf.Abs(vec.z) > Mathf.Epsilon ? 1f : 0f );
|
||||
}
|
||||
|
||||
private static Axis MaskToAxis(Vector3 vec)
|
||||
{
|
||||
Axis axis = Axis.None;
|
||||
if( Mathf.Abs(vec.x) > 0 ) axis |= Axis.X;
|
||||
if( Mathf.Abs(vec.y) > 0 ) axis |= Axis.Y;
|
||||
if( Mathf.Abs(vec.z) > 0 ) axis |= Axis.Z;
|
||||
return axis;
|
||||
}
|
||||
|
||||
private static Axis BestAxis(Vector3 vec)
|
||||
{
|
||||
float x = Mathf.Abs(vec.x);
|
||||
float y = Mathf.Abs(vec.y);
|
||||
float z = Mathf.Abs(vec.z);
|
||||
|
||||
return (x > y && x > z) ? Axis.X : ((y > x && y > z) ? Axis.Y : Axis.Z);
|
||||
}
|
||||
|
||||
public static Axis CalcDragAxis(Vector3 movement, Camera cam)
|
||||
{
|
||||
Vector3 mask = VectorToMask(movement);
|
||||
|
||||
if(mask.x + mask.y + mask.z == 2)
|
||||
{
|
||||
return MaskToAxis(Vector3.one - mask);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( MaskToAxis(mask) )
|
||||
{
|
||||
case Axis.X:
|
||||
if( Mathf.Abs(Vector3.Dot(cam.transform.forward, Vector3.up)) < Mathf.Abs(Vector3.Dot(cam.transform.forward, Vector3.forward)))
|
||||
return Axis.Z;
|
||||
else
|
||||
return Axis.Y;
|
||||
|
||||
case Axis.Y:
|
||||
if( Mathf.Abs(Vector3.Dot(cam.transform.forward, Vector3.right)) < Mathf.Abs(Vector3.Dot(cam.transform.forward, Vector3.forward)))
|
||||
return Axis.Z;
|
||||
else
|
||||
return Axis.X;
|
||||
|
||||
case Axis.Z:
|
||||
if( Mathf.Abs(Vector3.Dot(cam.transform.forward, Vector3.right)) < Mathf.Abs(Vector3.Dot(cam.transform.forward, Vector3.up)))
|
||||
return Axis.Y;
|
||||
else
|
||||
return Axis.X;
|
||||
default:
|
||||
|
||||
return Axis.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static float ValueFromMask(Vector3 val, Vector3 mask)
|
||||
{
|
||||
if(Mathf.Abs(mask.x) > .0001f)
|
||||
return val.x;
|
||||
else if(Mathf.Abs(mask.y) > .0001f)
|
||||
return val.y;
|
||||
else
|
||||
return val.z;
|
||||
}
|
||||
|
||||
public static Vector3 SnapValue(Vector3 val, float snapValue)
|
||||
{
|
||||
float _x = val.x, _y = val.y, _z = val.z;
|
||||
return new Vector3(
|
||||
Snap(_x, snapValue),
|
||||
Snap(_y, snapValue),
|
||||
Snap(_z, snapValue)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a type with name and optional assembly name. `type` should include namespace.
|
||||
*/
|
||||
private static Type GetType(string type, string assembly = null)
|
||||
{
|
||||
Type t = Type.GetType(type);
|
||||
|
||||
if(t == null)
|
||||
{
|
||||
IEnumerable<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
if(assembly != null)
|
||||
assemblies = assemblies.Where(x => x.FullName.Contains(assembly));
|
||||
|
||||
foreach(Assembly ass in assemblies)
|
||||
{
|
||||
t = ass.GetType(type);
|
||||
|
||||
if(t != null)
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public static void SetUnityGridEnabled(bool isEnabled)
|
||||
{
|
||||
try
|
||||
{
|
||||
Type annotationUtility = GetType("UnityEditor.AnnotationUtility");
|
||||
PropertyInfo pi = annotationUtility.GetProperty("showGrid", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
pi.SetValue(null, isEnabled, BindingFlags.NonPublic | BindingFlags.Static, null, null, null);
|
||||
}
|
||||
catch
|
||||
{}
|
||||
}
|
||||
|
||||
public static bool GetUnityGridEnabled()
|
||||
{
|
||||
try
|
||||
{
|
||||
Type annotationUtility = GetType("UnityEditor.AnnotationUtility");
|
||||
PropertyInfo pi = annotationUtility.GetProperty("showGrid", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
return (bool) pi.GetValue(null, null);
|
||||
}
|
||||
catch
|
||||
{}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const float EPSILON = .0001f;
|
||||
public static Vector3 SnapValue(Vector3 val, Vector3 mask, float snapValue)
|
||||
{
|
||||
|
||||
float _x = val.x, _y = val.y, _z = val.z;
|
||||
return new Vector3(
|
||||
( Mathf.Abs(mask.x) < EPSILON ? _x : Snap(_x, snapValue) ),
|
||||
( Mathf.Abs(mask.y) < EPSILON ? _y : Snap(_y, snapValue) ),
|
||||
( Mathf.Abs(mask.z) < EPSILON ? _z : Snap(_z, snapValue) )
|
||||
);
|
||||
}
|
||||
|
||||
public static Vector3 SnapToCeil(Vector3 val, Vector3 mask, float snapValue)
|
||||
{
|
||||
float _x = val.x, _y = val.y, _z = val.z;
|
||||
return new Vector3(
|
||||
( Mathf.Abs(mask.x) < EPSILON ? _x : SnapToCeil(_x, snapValue) ),
|
||||
( Mathf.Abs(mask.y) < EPSILON ? _y : SnapToCeil(_y, snapValue) ),
|
||||
( Mathf.Abs(mask.z) < EPSILON ? _z : SnapToCeil(_z, snapValue) )
|
||||
);
|
||||
}
|
||||
|
||||
public static Vector3 SnapToFloor(Vector3 val, float snapValue)
|
||||
{
|
||||
float _x = val.x, _y = val.y, _z = val.z;
|
||||
return new Vector3(
|
||||
SnapToFloor(_x, snapValue),
|
||||
SnapToFloor(_y, snapValue),
|
||||
SnapToFloor(_z, snapValue)
|
||||
);
|
||||
}
|
||||
|
||||
public static Vector3 SnapToFloor(Vector3 val, Vector3 mask, float snapValue)
|
||||
{
|
||||
float _x = val.x, _y = val.y, _z = val.z;
|
||||
return new Vector3(
|
||||
( Mathf.Abs(mask.x) < EPSILON ? _x : SnapToFloor(_x, snapValue) ),
|
||||
( Mathf.Abs(mask.y) < EPSILON ? _y : SnapToFloor(_y, snapValue) ),
|
||||
( Mathf.Abs(mask.z) < EPSILON ? _z : SnapToFloor(_z, snapValue) )
|
||||
);
|
||||
}
|
||||
|
||||
public static float Snap(float val, float round)
|
||||
{
|
||||
return round * Mathf.Round(val / round);
|
||||
}
|
||||
|
||||
public static float SnapToFloor(float val, float snapValue)
|
||||
{
|
||||
return snapValue * Mathf.Floor(val / snapValue);
|
||||
}
|
||||
|
||||
public static float SnapToCeil(float val, float snapValue)
|
||||
{
|
||||
return snapValue * Mathf.Ceil(val / snapValue);
|
||||
}
|
||||
|
||||
public static Vector3 CeilFloor(Vector3 v)
|
||||
{
|
||||
v.x = v.x < 0 ? -1 : 1;
|
||||
v.y = v.y < 0 ? -1 : 1;
|
||||
v.z = v.z < 0 ? -1 : 1;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
abstract class SnapEnabledOverride
|
||||
{
|
||||
public abstract bool IsEnabled();
|
||||
}
|
||||
|
||||
class SnapIsEnabledOverride : SnapEnabledOverride
|
||||
{
|
||||
bool m_SnapIsEnabled;
|
||||
|
||||
public SnapIsEnabledOverride(bool snapIsEnabled)
|
||||
{
|
||||
m_SnapIsEnabled = snapIsEnabled;
|
||||
}
|
||||
|
||||
public override bool IsEnabled() { return m_SnapIsEnabled; }
|
||||
}
|
||||
|
||||
class ConditionalSnapOverride : SnapEnabledOverride
|
||||
{
|
||||
public System.Func<bool> m_IsEnabledDelegate;
|
||||
|
||||
public ConditionalSnapOverride(System.Func<bool> d)
|
||||
{
|
||||
m_IsEnabledDelegate = d;
|
||||
}
|
||||
|
||||
public override bool IsEnabled() { return m_IsEnabledDelegate(); }
|
||||
}
|
||||
|
||||
private static Dictionary<Transform, SnapEnabledOverride> m_SnapOverrideCache = new Dictionary<Transform, SnapEnabledOverride>();
|
||||
private static Dictionary<Type, bool> m_NoSnapAttributeTypeCache = new Dictionary<Type, bool>();
|
||||
private static Dictionary<Type, MethodInfo> m_ConditionalSnapAttributeCache = new Dictionary<Type, MethodInfo>();
|
||||
|
||||
public static void ClearSnapEnabledCache()
|
||||
{
|
||||
m_SnapOverrideCache.Clear();
|
||||
}
|
||||
|
||||
public static bool SnapIsEnabled(Transform t)
|
||||
{
|
||||
SnapEnabledOverride so;
|
||||
|
||||
if(m_SnapOverrideCache.TryGetValue(t, out so))
|
||||
return so.IsEnabled();
|
||||
|
||||
object[] attribs = null;
|
||||
|
||||
foreach(Component c in t.GetComponents<MonoBehaviour>())
|
||||
{
|
||||
if(c == null)
|
||||
continue;
|
||||
|
||||
Type type = c.GetType();
|
||||
|
||||
bool hasNoSnapAttrib;
|
||||
|
||||
if(m_NoSnapAttributeTypeCache.TryGetValue(type, out hasNoSnapAttrib))
|
||||
{
|
||||
if(hasNoSnapAttrib)
|
||||
{
|
||||
m_SnapOverrideCache.Add(t, new SnapIsEnabledOverride(!hasNoSnapAttrib));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
attribs = type.GetCustomAttributes(true);
|
||||
hasNoSnapAttrib = attribs.Any(x => x != null && x.ToString().Contains("ProGridsNoSnap"));
|
||||
m_NoSnapAttributeTypeCache.Add(type, hasNoSnapAttrib);
|
||||
|
||||
if(hasNoSnapAttrib)
|
||||
{
|
||||
m_SnapOverrideCache.Add(t, new SnapIsEnabledOverride(!hasNoSnapAttrib));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
MethodInfo mi;
|
||||
|
||||
if(m_ConditionalSnapAttributeCache.TryGetValue(type, out mi))
|
||||
{
|
||||
if(mi != null)
|
||||
{
|
||||
m_SnapOverrideCache.Add(t, new ConditionalSnapOverride(() => { return (bool) mi.Invoke(c, null); }));
|
||||
return (bool) mi.Invoke(c, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( attribs.Any(x => x != null && x.ToString().Contains("ProGridsConditionalSnap")) )
|
||||
{
|
||||
mi = type.GetMethod("IsSnapEnabled", BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
|
||||
m_ConditionalSnapAttributeCache.Add(type, mi);
|
||||
|
||||
if(mi != null)
|
||||
{
|
||||
m_SnapOverrideCache.Add(t, new ConditionalSnapOverride(() => { return (bool) mi.Invoke(c, null); }));
|
||||
return (bool) mi.Invoke(c, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ConditionalSnapAttributeCache.Add(type, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_SnapOverrideCache.Add(t, new SnapIsEnabledOverride(true));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PGExtensions
|
||||
{
|
||||
public static bool Contains(this Transform[] t_arr, Transform t)
|
||||
{
|
||||
for(int i = 0; i < t_arr.Length; i++)
|
||||
if(t_arr[i] == t)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static float Sum(this Vector3 v)
|
||||
{
|
||||
return v[0] + v[1] + v[2];
|
||||
}
|
||||
|
||||
public static bool InFrustum(this Camera cam, Vector3 point)
|
||||
{
|
||||
Vector3 p = cam.WorldToViewportPoint(point);
|
||||
return (p.x >= 0f && p.x <= 1f) &&
|
||||
(p.y >= 0f && p.y <= 1f) &&
|
||||
p.z >= 0f;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e12ec5ca21bb5842aa4a54b18874a11
|
||||
timeCreated: 18446744011573954816
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user