Created
July 8, 2017 00:58
-
-
Save Polkm/a22d716182f78ae6b48694d6cbb8ece4 to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using UnityEditor; | |
using System.Reflection; | |
using Type = System.Type; | |
public class InlineCurveEditor | |
{ | |
private object curveEditor; | |
private Type curveType; | |
private Type curveDataType; | |
private Type cureWrapperGetCallbackType; | |
private Type cureWrapperSetCallbackType; | |
public InlineCurveEditor() | |
{ | |
curveType = FindType("ParticleSystemCurveEditor"); | |
curveDataType = FindType("ParticleSystemCurveEditor+CurveData"); | |
cureWrapperGetCallbackType = FindType("CurveWrapper+GetAxisScalarsCallback"); | |
cureWrapperSetCallbackType = FindType("CurveWrapper+SetAxisScalarsCallback"); | |
var construct = curveType.GetConstructor(new Type[0]); | |
curveEditor = construct.Invoke(new object[0]); | |
var initMeth = curveType.GetMethod("Init"); | |
initMeth.Invoke(curveEditor, new object[0]); | |
} | |
private static Type SearchType(Type parentType, string name) | |
{ | |
if (parentType.FullName.Contains(name)) | |
{ | |
return parentType; | |
} | |
foreach (var type in parentType.GetNestedTypes()) | |
{ | |
var res = SearchType(type, name); | |
if (res != null) | |
{ | |
return res; | |
} | |
} | |
return null; | |
} | |
public static Type FindType(string name) | |
{ | |
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies()) | |
{ | |
foreach (var type in assembly.GetTypes()) | |
{ | |
var res = SearchType(type, name); | |
if (res != null) | |
{ | |
return res; | |
} | |
} | |
} | |
return null; | |
} | |
public void AddCurve(SerializedProperty prop) | |
{ | |
var types = new Type[] { | |
typeof(string), | |
typeof(GUIContent), | |
typeof(SerializedProperty), | |
typeof(SerializedProperty), | |
typeof(Color), | |
typeof(bool), | |
cureWrapperGetCallbackType, | |
cureWrapperSetCallbackType, | |
typeof(bool) | |
}; | |
var cdConstruct = curveDataType.GetConstructor(types); | |
var cd = cdConstruct.Invoke(new object[] { | |
prop.name, | |
new GUIContent(prop.name), | |
null, | |
prop, | |
Color.red, | |
false, | |
null, | |
null, | |
true | |
}); | |
var addCurveMeth = curveType.GetMethod("AddCurve"); | |
addCurveMeth.Invoke(curveEditor, new object[] { cd }); | |
} | |
public void OnGUI() | |
{ | |
var height = 200; | |
var rect = GUILayoutUtility.GetRect(13f, height, new GUILayoutOption[] | |
{ | |
GUILayout.MinHeight(height) | |
}); | |
var onGUIMeth = curveType.GetMethod("OnGUI"); | |
onGUIMeth.Invoke(curveEditor, new object[] { rect }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment