Created
April 12, 2015 13:47
-
-
Save winxalex/e1963254ccf537849e53 to your computer and use it in GitHub Desktop.
Unity3d Curve Editor Revealed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// /////////////// CURVE EDITOR //////////////// | |
#region CurveMenuManagerW | |
public class CurveMenuManagerW | |
{ | |
private static Type __RealType; | |
private static ConstructorInfo method_ctor; | |
static MethodInfo MethodInfo_AddTangentMenuItems; | |
private object __instance; | |
public object wrapped { | |
get{ return __instance;} | |
} | |
public static void InitType () | |
{ | |
if (method_ctor == null) { | |
method_ctor = GetWrappedType ().GetConstructor (new Type[] { | |
CurveEditorW.GetWrappedType () | |
}); | |
MethodInfo_AddTangentMenuItems = __RealType.GetMethod ("AddTangentMenuItems", new Type[] { | |
typeof(GenericMenu), | |
typeof(List<>).MakeGenericType (KeyIdentifierW.GetWrappedType ()) | |
}); | |
} | |
} | |
public static Type GetWrappedType () | |
{ | |
if (__RealType == null) { | |
Assembly assembly = Assembly.GetAssembly (typeof(Editor)); | |
__RealType = assembly.GetType ("UnityEditor.CurveMenuManager"); | |
} | |
return __RealType; | |
} | |
public CurveMenuManagerW (CurveEditorW editor) | |
{ | |
InitType (); | |
__instance = method_ctor.Invoke (new object[]{editor.wrapped}); | |
} | |
public void AddTangentMenuItems (GenericMenu menu, object keyList) | |
{ | |
MethodInfo_AddTangentMenuItems.Invoke (__instance, new object[] { | |
menu, | |
keyList | |
}); | |
} | |
} | |
#endregion | |
#region KeyIdentifierW | |
public class KeyIdentifierW | |
{ | |
private static Type __RealType; | |
private static ConstructorInfo method_ctor; | |
static MethodInfo MethodInfo_SetWrap; | |
private object __instance; | |
public object wrapped { | |
get{ return __instance;} | |
} | |
public static void InitType () | |
{ | |
if (method_ctor == null) { | |
Assembly assembly = Assembly.GetAssembly (typeof(Editor)); | |
method_ctor = GetWrappedType ().GetConstructor (new Type[] { | |
assembly.GetType ("UnityEditor.CurveRenderer"),typeof(int),typeof(int) | |
}); | |
} | |
} | |
public static Type GetWrappedType () | |
{ | |
if (__RealType == null) { | |
Assembly assembly = Assembly.GetAssembly (typeof(Editor)); | |
__RealType = assembly.GetType ("UnityEditor.KeyIdentifier"); | |
} | |
return __RealType; | |
} | |
public KeyIdentifierW (object renderer, int curveId, int keyIndex) | |
{ | |
InitType (); | |
__instance = method_ctor.Invoke (new object[] { | |
renderer, | |
curveId, | |
keyIndex | |
}); | |
} | |
} | |
#endregion | |
#region CurveSelectionW | |
public class CurveSelectionW | |
{ | |
private static Type __RealType; | |
private object __instance; | |
static FieldInfo FieldInfo_m_Host; | |
static PropertyInfo PropertyInfo_key; | |
static PropertyInfo PropertyInfo_curveID ; | |
static PropertyInfo PropertyInfo_curveWrapper; | |
CurveWrapperW _curveWrapperW; | |
public object wrapped { | |
get{ return __instance;} | |
set{ __instance = value;} | |
} | |
public static void InitType () | |
{ | |
if (__RealType == null) { | |
Assembly assembly = Assembly.GetAssembly (typeof(Editor)); | |
__RealType = assembly.GetType ("UnityEditor.CurveSelection"); | |
FieldInfo_m_Host = __RealType.GetField ("m_Host", BindingFlags.Instance | BindingFlags.NonPublic); | |
PropertyInfo_key = __RealType.GetProperty ("key"); | |
PropertyInfo_curveID = __RealType.GetProperty ("curveID"); | |
PropertyInfo_curveWrapper = __RealType.GetProperty ("curveWrapper", BindingFlags.Instance | BindingFlags.NonPublic); | |
} | |
} | |
public CurveWrapperW curveWrapper { | |
get { | |
if (_curveWrapperW == null) | |
_curveWrapperW = new CurveWrapperW (); | |
_curveWrapperW.wrapped = PropertyInfo_curveWrapper.GetValue (__instance, null); | |
return _curveWrapperW; | |
} | |
} | |
public CurveEditorW host { | |
set{ FieldInfo_m_Host.SetValue (__instance, value.wrapped);} | |
} | |
public int key { | |
get { | |
return (int)PropertyInfo_key.GetValue (__instance, null); | |
} | |
set { | |
PropertyInfo_key.SetValue (__instance, value, null); | |
} | |
} | |
public int curveID { | |
get { | |
return (int)PropertyInfo_curveID.GetValue (__instance, null); | |
} | |
set { | |
PropertyInfo_curveID.SetValue (__instance, value, null); | |
} | |
} | |
public CurveSelectionW () | |
{ | |
InitType (); | |
__instance = FormatterServices.GetUninitializedObject (__RealType); | |
} | |
public CurveSelectionW (int curveID, CurveEditorW host, int keyIndex):this() | |
{ | |
this.host = host; | |
this.key = keyIndex; | |
this.curveID = curveID; | |
//__instance = method_ctor.Invoke (new object[]{curveID,host.wrapped,keyIndex}); | |
} | |
} | |
#endregion | |
#region NormalCurveRenderer | |
public class NormalCurveRendererW | |
{ | |
private static Type __RealType; | |
private static ConstructorInfo method_ctor; | |
static MethodInfo MethodInfo_SetWrap; | |
private object __instance; | |
public object wrapped { | |
get{ return __instance;} | |
} | |
public static Type GetWrappedType () | |
{ | |
if (__RealType == null) { | |
Assembly assembly = Assembly.GetAssembly (typeof(Editor)); | |
__RealType = assembly.GetType ("UnityEditor.NormalCurveRenderer"); | |
} | |
return __RealType; | |
} | |
public static void InitType () | |
{ | |
if (method_ctor == null) { | |
method_ctor = GetWrappedType ().GetConstructor (new Type[] { | |
typeof(AnimationCurve) | |
}); | |
MethodInfo_SetWrap = __RealType.GetMethod ("SetWrap", new Type[] { | |
typeof(WrapMode), | |
typeof(WrapMode) | |
}); | |
} | |
} | |
public NormalCurveRendererW (AnimationCurve curve) | |
{ | |
InitType (); | |
__instance = method_ctor.Invoke (new object[]{curve}); | |
} | |
public void SetWrap (WrapMode preWrap, WrapMode postWrap) | |
{ | |
MethodInfo_SetWrap.Invoke (__instance, new object[]{preWrap,postWrap}); | |
} | |
} | |
#endregion | |
#region CurveWrapper | |
[Serializable] | |
public class CurveWrapperW | |
{ | |
private static Type __RealType; | |
private static ConstructorInfo method_ctor; | |
static FieldInfo FieldInfo_id; | |
static FieldInfo FieldInfo_groupId; | |
static FieldInfo FieldInfo_hidden; | |
static FieldInfo FieldInfo_readOnly; | |
static FieldInfo FieldInfo_color; | |
static PropertyInfo PropertyInfo_renderer; | |
static PropertyInfo PropertyInfo_curve; | |
private object __instance; | |
public object wrapped { | |
get { | |
return __instance; | |
} | |
set { | |
__instance = value; | |
} | |
} | |
public AnimationCurve curve { | |
get{ return (AnimationCurve)PropertyInfo_curve.GetValue (__instance, null);} | |
set { | |
NormalCurveRendererW renderer; | |
this.hidden = false; | |
this.readOnly = false; | |
renderer = new NormalCurveRendererW (value); | |
renderer.SetWrap (value.preWrapMode, value.postWrapMode); | |
this.renderer = renderer.wrapped; | |
} | |
} | |
public bool hidden { | |
get{ return (bool)FieldInfo_hidden.GetValue (__instance);} | |
set{ FieldInfo_hidden.SetValue (__instance, value);} | |
} | |
public bool readOnly { | |
get{ return (bool)FieldInfo_readOnly.GetValue (__instance);} | |
set{ FieldInfo_readOnly.SetValue (__instance, value);} | |
} | |
public Color color { | |
get{ return (Color)FieldInfo_color.GetValue (__instance);} | |
set{ FieldInfo_color.SetValue (__instance, value);} | |
} | |
public int groupId { | |
get{ return (int)FieldInfo_groupId.GetValue (__instance);} | |
set{ FieldInfo_groupId.SetValue (__instance, value); } | |
} | |
public object renderer { | |
get{ return PropertyInfo_renderer.GetValue (__instance, null);} | |
set{ PropertyInfo_renderer.SetValue (__instance, value, null);} | |
} | |
public int id { | |
get{ return (int)FieldInfo_id.GetValue (__instance);} | |
set{ FieldInfo_id.SetValue (__instance, value); } | |
} | |
private static void InitType () | |
{ | |
if (method_ctor == null) { | |
method_ctor = GetWrappedType ().GetConstructor (new Type[] {}); | |
PropertyInfo_renderer = __RealType.GetProperty ("renderer"); | |
PropertyInfo_curve = __RealType.GetProperty ("curve"); | |
FieldInfo_groupId = __RealType.GetField ("groupId"); | |
FieldInfo_color = __RealType.GetField ("color"); | |
FieldInfo_hidden = __RealType.GetField ("hidden"); | |
FieldInfo_readOnly = __RealType.GetField ("readOnly"); | |
FieldInfo_id = __RealType.GetField ("id"); | |
} | |
} | |
public static Type GetWrappedType () | |
{ | |
if (__RealType == null) { | |
Assembly assembly = Assembly.GetAssembly (typeof(Editor)); | |
__RealType = assembly.GetType ("UnityEditor.CurveWrapper"); | |
} | |
return __RealType; | |
} | |
public CurveWrapperW () | |
{ | |
InitType (); | |
__instance = method_ctor.Invoke (new object[]{}); | |
this.groupId = -1; | |
this.color = new Color (UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); | |
} | |
} | |
#endregion | |
#region CurveEditorW | |
public class CurveEditorW | |
{ | |
private static Type __RealType; | |
private object instance; | |
private static MethodInfo MethodInfo_OnGUI; | |
static MethodInfo MethodInfo_FrameSelected; | |
static MethodInfo MethodInfo_GetCurveAtPosition; | |
static MethodInfo MethodInfo_CreateKeyFromClick; | |
static MethodInfo MethodInfo_getCurveWrapperById; | |
static MethodInfo MethodInfo_GetGUIPoint; | |
static MethodInfo MethodInfo_DeleteKeys; | |
private static PropertyInfo PropertyInfo_rect; | |
private static PropertyInfo PropertyInfo_scaleWithWindow; | |
private static PropertyInfo PropertyInfo_drawRect; | |
static PropertyInfo PropertyInfo_margin; | |
static PropertyInfo PropertyInfo_topmargin; | |
static PropertyInfo PropertyInfo_leftmargin; | |
static PropertyInfo PropertyInfo_rightmargin; | |
static PropertyInfo PropertyInfo_bottommargin; | |
static PropertyInfo PropertyInfo_vSlider; | |
static PropertyInfo PropertyInfo_hSlider; | |
static PropertyInfo PropertyInfo_hRangeMax; | |
static PropertyInfo PropertyInfo_hRangeMin; | |
static PropertyInfo PropertyInfo_vRangeMax; | |
static PropertyInfo PropertyInfo_vRangeMin; | |
static PropertyInfo PropertyInfo_vRangeLocked; | |
static PropertyInfo PropertyInfo_hRangeLocked; | |
static PropertyInfo PropertyInfo_mousePositionInDrawing; | |
static PropertyInfo PropertyInfo_animationCurves; | |
static FieldInfo FieldInfo_m_Selection; | |
static FieldInfo FieldInfo_m_Translation; | |
static FieldInfo FieldInfo_m_Scale; | |
static FieldInfo FieldInfo_m_DrawOrder; | |
static ConstructorInfo method_ctor; | |
AnimationCurve m_Curve; | |
Color m_Color; | |
static Styles ms_Styles; | |
private object __instance; | |
CurveMenuManagerW m_MenuManager; | |
CurveWrapperW[] _curveWrappersW; | |
private int _indexSelected = -1; | |
public delegate void SelectHandler (int index); | |
//Defining event based on the above delegate | |
public event SelectHandler onSelect; | |
public object wrapped { | |
get { | |
return __instance; | |
} | |
} | |
public Rect rect { | |
get{ return (Rect)PropertyInfo_rect.GetValue (__instance, null);} | |
set{ PropertyInfo_rect.SetValue (__instance, value, null);} | |
} | |
public bool scaleWithWindow { | |
get{ return (bool)PropertyInfo_scaleWithWindow.GetValue (__instance, null);} | |
set{ PropertyInfo_scaleWithWindow.SetValue (__instance, value, null);} | |
} | |
public float margin { | |
set{ PropertyInfo_margin.SetValue (__instance, value, null);} | |
} | |
public float topmargin { | |
set{ PropertyInfo_topmargin.SetValue (__instance, value, null);} | |
} | |
public float leftmargin { | |
set{ PropertyInfo_leftmargin.SetValue (__instance, value, null);} | |
} | |
public float rightmargin { | |
set{ PropertyInfo_rightmargin.SetValue (__instance, value, null);} | |
} | |
public float bottommargin { | |
set{ PropertyInfo_bottommargin.SetValue (__instance, value, null);} | |
} | |
public Vector2 mousePositionInDrawing { | |
get{ return (Vector2)PropertyInfo_mousePositionInDrawing.GetValue (__instance, null);} | |
} | |
public Vector2 Scale { | |
get{ return (Vector2)FieldInfo_m_Scale.GetValue (__instance);} | |
} | |
public Vector2 Translation { | |
get{ return (Vector2)FieldInfo_m_Translation.GetValue (__instance);} | |
} | |
List<int> DrawOrder { | |
get{ return (List<int>)FieldInfo_m_DrawOrder.GetValue (__instance);} | |
} | |
IList m_Selection { | |
get{ return FieldInfo_m_Selection.GetValue (__instance) as IList;} | |
} | |
public bool hRangeLocked { | |
get{ return (bool)PropertyInfo_hRangeLocked.GetValue (__instance, null);} | |
set{ PropertyInfo_hRangeLocked.SetValue (__instance, value, null);} | |
} | |
public bool vRangeLocked { | |
get{ return (bool)PropertyInfo_vRangeLocked.GetValue (__instance, null);} | |
set{ PropertyInfo_vRangeLocked.SetValue (__instance, value, null);} | |
} | |
public bool hSlider { | |
get{ return (bool)PropertyInfo_hSlider.GetValue (__instance, null);} | |
set{ PropertyInfo_hSlider.SetValue (__instance, value, null);} | |
} | |
public bool vSlider { | |
get{ return (bool)PropertyInfo_hSlider.GetValue (__instance, null);} | |
set{ PropertyInfo_vSlider.SetValue (__instance, value, null);} | |
} | |
public float hRangeMin { | |
get{ return (float)PropertyInfo_hRangeMin.GetValue (__instance, null);} | |
set{ PropertyInfo_hRangeMin.SetValue (__instance, value, null);} | |
} | |
public float hRangeMax { | |
get{ return (float)PropertyInfo_hRangeMax.GetValue (__instance, null);} | |
set{ PropertyInfo_hRangeMax.SetValue (__instance, value, null);} | |
} | |
public float vRangeMin { | |
get{ return (float)PropertyInfo_vRangeMin.GetValue (__instance, null);} | |
set{ PropertyInfo_vRangeMin.SetValue (__instance, value, null);} | |
} | |
public float vRangeMax { | |
get{ return (float)PropertyInfo_vRangeMax.GetValue (__instance, null);} | |
set{ PropertyInfo_vRangeMax.SetValue (__instance, value, null);} | |
} | |
public CurveWrapperW[] animationCurves { | |
set { | |
value.Select ((item) => item.curve); | |
_curveWrappersW = value; | |
PropertyInfo_animationCurves.SetValue (__instance, CurveWrappersWToCurveWrappers (value), null); | |
} | |
get { | |
return _curveWrappersW; | |
} | |
} | |
void DeleteKeys (object userData) | |
{ | |
MethodInfo_DeleteKeys.Invoke (__instance, new object[]{userData}); | |
} | |
public Rect drawRect { | |
get{ return (Rect)PropertyInfo_drawRect.GetValue (__instance, null);} | |
} | |
public static void InitType () | |
{ | |
if (method_ctor == null) { | |
method_ctor = GetWrappedType ().GetConstructor (new Type[] { | |
typeof(Rect),CurveWrapperW.GetWrappedType ().MakeArrayType (),typeof(bool) | |
}); | |
PropertyInfo_rect = __RealType.GetProperty ("rect"); | |
PropertyInfo_scaleWithWindow = __RealType.GetProperty ("scaleWithWindow"); | |
PropertyInfo_margin = __RealType.GetProperty ("margin"); | |
PropertyInfo_topmargin = __RealType.GetProperty ("topmargin"); | |
PropertyInfo_leftmargin = __RealType.GetProperty ("leftmargin"); | |
PropertyInfo_rightmargin = __RealType.GetProperty ("rightmargin"); | |
PropertyInfo_bottommargin = __RealType.GetProperty ("rightmargin"); | |
PropertyInfo_vSlider = __RealType.GetProperty ("vSlider"); | |
PropertyInfo_hSlider = __RealType.GetProperty ("hSlider"); | |
PropertyInfo_hRangeMax = __RealType.GetProperty ("hRangeMax"); | |
PropertyInfo_hRangeMin = __RealType.GetProperty ("hRangeMin"); | |
PropertyInfo_vRangeMax = __RealType.GetProperty ("vRangeMax"); | |
PropertyInfo_vRangeMin = __RealType.GetProperty ("vRangeMin"); | |
PropertyInfo_vRangeLocked = __RealType.GetProperty ("vRangeLocked"); | |
PropertyInfo_hRangeLocked = __RealType.GetProperty ("hRangeLocked"); | |
PropertyInfo_drawRect = __RealType.BaseType.GetProperty ("drawRect"); | |
PropertyInfo_mousePositionInDrawing = __RealType.BaseType.GetProperty ("mousePositionInDrawing"); | |
PropertyInfo_animationCurves = __RealType.GetProperty ("animationCurves"); | |
MethodInfo_OnGUI = __RealType.GetMethod ("OnGUI"); | |
MethodInfo_GetGUIPoint = __RealType.GetMethod ("GetGUIPoint", BindingFlags.NonPublic | BindingFlags.Instance); | |
MethodInfo_getCurveWrapperById = __RealType.GetMethod ("getCurveWrapperById"); | |
MethodInfo_FrameSelected = __RealType.GetMethod ("FrameSelected"); | |
MethodInfo_GetCurveAtPosition = __RealType.GetMethod ("GetCurveAtPosition", BindingFlags.NonPublic | BindingFlags.Instance); | |
MethodInfo_CreateKeyFromClick = __RealType.GetMethod ("CreateKeyFromClick", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[]{typeof(object)}, null); | |
MethodInfo_DeleteKeys = __RealType.GetMethod ("DeleteKeys", BindingFlags.NonPublic | BindingFlags.Instance); | |
FieldInfo_m_Translation = __RealType.BaseType.GetField ("m_Translation", BindingFlags.Instance | BindingFlags.NonPublic); | |
FieldInfo_m_Scale = __RealType.BaseType.GetField ("m_Scale", BindingFlags.Instance | BindingFlags.NonPublic); | |
FieldInfo_m_DrawOrder = __RealType.GetField ("m_DrawOrder", BindingFlags.Instance | BindingFlags.NonPublic); | |
FieldInfo_m_Selection = __RealType.GetField ("m_Selection", BindingFlags.Instance | BindingFlags.NonPublic); | |
} | |
} | |
public static Type GetWrappedType () | |
{ | |
if (__RealType == null) { | |
Assembly assembly = Assembly.GetAssembly (typeof(Editor)); | |
__RealType = assembly.GetType ("UnityEditor.CurveEditor"); | |
} | |
return __RealType; | |
} | |
public CurveEditorW (Rect rect, CurveWrapperW[] curveWrappers, bool minimalGUI) | |
{ | |
InitType (); | |
if (CurveEditorW.ms_Styles == null) { | |
CurveEditorW.ms_Styles = new CurveEditorW.Styles (); | |
} | |
__instance = method_ctor.Invoke (new object[] { | |
rect, | |
CurveWrappersWToCurveWrappers (curveWrappers), | |
minimalGUI | |
}); | |
} | |
public CurveEditorW (Rect rect, AnimationCurve curve, bool minimalGUI):this(rect,new AnimationCurve[]{curve},minimalGUI) | |
{ | |
} | |
public CurveEditorW (Rect rect, AnimationCurve[] curves, bool minimalGUI) | |
{ | |
InitType (); | |
if (CurveEditorW.ms_Styles == null) { | |
CurveEditorW.ms_Styles = new CurveEditorW.Styles (); | |
} | |
__instance = method_ctor.Invoke (new object[] { | |
rect, | |
AnimationCurvesToCurveWrappers (curves), | |
minimalGUI | |
}); | |
} | |
public void RemoveCurveAt (int index) | |
{ | |
if (index > -1 && index < _curveWrappersW.Length) { | |
List<CurveWrapperW> list = _curveWrappersW.ToList (); | |
list.RemoveAt (index); | |
_curveWrappersW = list.ToArray (); | |
PropertyInfo_animationCurves.SetValue (__instance, CurveWrappersWToCurveWrappers (_curveWrappersW), null); | |
} | |
_indexSelected = -1; | |
} | |
public void AddCurve (CurveWrapperW curveWrapperW) | |
{ | |
int len = _curveWrappersW.Length; | |
curveWrapperW.id = ("Curve" + len).GetHashCode (); | |
Array.Resize (ref _curveWrappersW, len + 1); | |
_curveWrappersW [len] = curveWrapperW; | |
PropertyInfo_animationCurves.SetValue (__instance, CurveWrappersWToCurveWrappers (_curveWrappersW), null); | |
} | |
Array CurveWrappersWToCurveWrappers (CurveWrapperW[] curveWrappers) | |
{ | |
Array curveWrapperArray = Array.CreateInstance (CurveWrapperW.GetWrappedType (), curveWrappers.Length); | |
CurveWrapperW curveWrapperW; | |
for (int i=0; i<curveWrapperArray.Length; i++) { | |
curveWrapperW = curveWrappers [i]; | |
curveWrapperW.id = ("Curve" + i).GetHashCode (); | |
curveWrapperArray.SetValue (curveWrapperW.wrapped, i); | |
} | |
_curveWrappersW = curveWrappers; | |
return curveWrapperArray; | |
} | |
Array AnimationCurvesToCurveWrappers (AnimationCurve[] curves) | |
{ | |
CurveWrapperW curveWrapperW; | |
Array curveWrapperArray = Array.CreateInstance (CurveWrapperW.GetWrappedType (), curves.Length); | |
_curveWrappersW = new CurveWrapperW[curves.Length]; | |
AnimationCurve curve; | |
for (int i=0; i<curves.Length; i++) { | |
curve = curves [i]; | |
_curveWrappersW [i] = curveWrapperW = new CurveWrapperW (); | |
curveWrapperW.id = ("Curve" + i).GetHashCode (); | |
curveWrapperW.curve = curve; | |
curveWrapperArray.SetValue (curveWrapperW.wrapped, i); | |
} | |
return curveWrapperArray; | |
} | |
int GetCurveAtPosition (Vector2 mousePosition, out Vector2 closestPointOnCurve) | |
{ | |
Vector2 vectorTemp = new Vector2 (); | |
object[] arguments = new object[] { | |
mousePosition, | |
vectorTemp | |
}; | |
int result = (int)MethodInfo_GetCurveAtPosition.Invoke (__instance, arguments); | |
closestPointOnCurve = (Vector2)arguments [1]; | |
return result; | |
} | |
public void FrameSelected (bool horizontally, bool vertically) | |
{ | |
MethodInfo_FrameSelected.Invoke (__instance, new object[] { | |
horizontally, | |
vertically | |
}); | |
} | |
CurveWrapperW getCurveWrapperById (int i) | |
{ | |
CurveWrapperW crv = new CurveWrapperW (); | |
crv.wrapped = MethodInfo_getCurveWrapperById.Invoke (__instance, new object[]{i}); | |
return crv; | |
} | |
Vector2 GetGUIPoint (Vector3 point) | |
{ | |
return (Vector2)MethodInfo_GetGUIPoint.Invoke (__instance, new object[]{point}); | |
} | |
CurveSelectionW FindNearest (Vector2 mousePosition) | |
{ | |
//return MethodInfo_FindNearest.Invoke (__instance, null); | |
mousePosition.x = mousePosition.x - this.drawRect.x; | |
mousePosition.y = mousePosition.y - this.drawRect.y; | |
int num = -1; | |
int keyIndex = -1; | |
float num2 = 64f; | |
for (int i = this.DrawOrder.Count - 1; i >= 0; i--) { | |
CurveWrapperW curveWrapperById = this.getCurveWrapperById (this.DrawOrder [i]); | |
if (!curveWrapperById.readOnly && !curveWrapperById.hidden) { | |
for (int j = 0; j < curveWrapperById.curve.keys.Length; j++) { | |
Keyframe keyframe = curveWrapperById.curve.keys [j]; | |
float sqrMagnitude = (this.GetGUIPoint (new Vector2 (keyframe.time, keyframe.value)) - mousePosition).sqrMagnitude; | |
if (sqrMagnitude <= 16f) { | |
return new CurveSelectionW (curveWrapperById.id, this, j); | |
} | |
if (sqrMagnitude < num2) { | |
num = curveWrapperById.id; | |
keyIndex = j; | |
num2 = sqrMagnitude; | |
} | |
} | |
if (i == this.DrawOrder.Count - 1 && num >= 0) { | |
num2 = 16f; | |
} | |
} | |
} | |
if (num >= 0) { | |
return new CurveSelectionW (num, this, keyIndex); | |
} | |
return null; | |
} | |
Vector2 ViewToDrawingTransformPoint (Vector2 lhs) | |
{ | |
return new Vector2 ((lhs.x - this.drawRect.x - this.Translation.x) / this.Scale.x, (lhs.y - this.drawRect.y - this.Translation.y) / this.Scale.y); | |
} | |
void CreateKeyFromClick (object userData) | |
{ | |
MethodInfo_CreateKeyFromClick.Invoke (__instance, new object[]{userData}); | |
} | |
public void DoEditor () | |
{ | |
GUI.Label (this.drawRect, GUIContent.none, CurveEditorW.ms_Styles.curveEditorBackground); | |
// int controlID =GUIUtility.GetControlID ("SelectKeys".GetHashCode (), FocusType.Passive); | |
//int controlID = GUIUtility.GetControlID (897560, FocusType.Passive); | |
Event current = Event.current; | |
//EventType typeForControl = current.GetTypeForControl (controlID); | |
//EventType.ContextClick never fired??? | |
if (current.type == EventType.MouseDown && this.drawRect.Contains (current.mousePosition)) { | |
if (current.button == 1) { | |
//check if clicked happen over key points | |
CurveSelectionW curveSelection = this.FindNearest (current.mousePosition); | |
if (curveSelection != null) { | |
IList list = (IList)Activator.CreateInstance (typeof(List<>).MakeGenericType (KeyIdentifierW.GetWrappedType ())); | |
bool flag2 = false; | |
KeyIdentifierW keyIdW; | |
CurveSelectionW current2 = new CurveSelectionW (); | |
foreach (var obj in this.m_Selection) { | |
current2.wrapped = obj; | |
keyIdW = new KeyIdentifierW (current2.curveWrapper.renderer, current2.curveID, current2.key); | |
list.Add (keyIdW.wrapped); | |
if (current2.curveID == curveSelection.curveID && current2.key == curveSelection.key) { | |
flag2 = true; | |
} | |
} | |
if (!flag2) { | |
list.Clear (); | |
keyIdW = new KeyIdentifierW (curveSelection.curveWrapper.renderer, curveSelection.curveID, curveSelection.key); | |
list.Add (keyIdW.wrapped); | |
this.m_Selection.Clear (); | |
this.m_Selection.Add (curveSelection.wrapped); | |
} | |
this.m_MenuManager = new CurveMenuManagerW (this); | |
GenericMenu genericMenu = new GenericMenu (); | |
string text; | |
if (list.Count > 1) { | |
text = "Delete Keys"; | |
} else { | |
text = "Delete Key"; | |
} | |
genericMenu.AddItem (new GUIContent (text), false, new GenericMenu.MenuFunction2 (this.DeleteKeys), list); | |
genericMenu.AddSeparator (string.Empty); | |
this.m_MenuManager.AddTangentMenuItems (genericMenu, list); | |
genericMenu.ShowAsContext (); | |
Event.current.Use (); | |
} else {//check if click happened on curve | |
Vector2 vector; | |
int curveAtPosition = this.GetCurveAtPosition (this.ViewToDrawingTransformPoint (Event.current.mousePosition), out vector);//this.GetCurveAtPosition (offset, out vector); | |
if (curveAtPosition >= 0) { | |
GenericMenu genericMenu = new GenericMenu (); | |
genericMenu.AddItem (new GUIContent ("Add Key"), false, new GenericMenu.MenuFunction2 (this.CreateKeyFromClick), this.ViewToDrawingTransformPoint (Event.current.mousePosition)); | |
genericMenu.ShowAsContext (); | |
Event.current.Use (); | |
} | |
} | |
} else { | |
Vector2 vector; | |
int curveAtPosition = this.GetCurveAtPosition (this.ViewToDrawingTransformPoint (Event.current.mousePosition), out vector);//this.GetCurveAtPosition (offset, out vector); | |
if (curveAtPosition > -1) { | |
Color clr = this.animationCurves [curveAtPosition].color; | |
this.animationCurves [curveAtPosition].color = new Color (clr.r, clr.g, clr.b, 0.5f); | |
if (_indexSelected > -1) { | |
clr = this.animationCurves [_indexSelected].color; | |
this.animationCurves [_indexSelected].color = new Color (clr.r, clr.g, clr.b, 1f); | |
} | |
_indexSelected = curveAtPosition; | |
} else { | |
if (_indexSelected > -1) { | |
Color clr = this.animationCurves [_indexSelected].color; | |
this.animationCurves [_indexSelected].color = new Color (clr.r, clr.g, clr.b, 1f); | |
} | |
_indexSelected = -1; | |
} | |
onSelect (_indexSelected); | |
} | |
} | |
MethodInfo_OnGUI .Invoke (__instance, null); | |
} | |
// | |
// Nested Types | |
// | |
internal class Styles | |
{ | |
public GUIStyle curveEditorBackground = "PopupCurveEditorBackground"; | |
} | |
} | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment