本文整理汇总了C#中UnityEngine.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# UnityEngine.GetType方法的具体用法?C# UnityEngine.GetType怎么用?C# UnityEngine.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine
的用法示例。
在下文中一共展示了UnityEngine.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnGUI
public static void OnGUI(UnityEngine.Object targetObject){
EditorGUI.BeginChangeCheck ();
SerializedObject serializedObject = new SerializedObject (targetObject);
serializedObject.Update ();
FieldInfo[] fields;
if(!fieldsLookup.TryGetValue (targetObject.GetType (),out fields)){
fields=targetObject.GetPublicFields().OrderBy(field => field.MetadataToken).ToArray();
fieldsLookup.Add(targetObject.GetType(),fields);
}
if(PreferencesEditor.GetBool(Preference.ShowActionTooltips) && !string.IsNullOrEmpty(targetObject.GetTooltip())){
GUILayout.BeginVertical((GUIStyle)"hostview");
GUILayout.Label(targetObject.GetTooltip(),FsmEditorStyles.wrappedLabelLeft);
GUILayout.EndVertical();
}
for (int i=0; i< fields.Length; i++) {
FieldInfo field=fields[i];
if(field.HasAttribute(typeof(HideInInspector))){
continue;
}
PropertyDrawer drawer=GUIDrawer.GetDrawer(field);
GUIContent content = field.GetInspectorGUIContent ();
SerializedProperty property=serializedObject.FindProperty(field.Name);
if(PreferencesEditor.GetBool(Preference.ShowVariableTooltips) && !string.IsNullOrEmpty(field.GetTooltip())){
GUILayout.BeginVertical("box");
GUILayout.Label(field.GetTooltip(),FsmEditorStyles.wrappedLabelLeft);
GUILayout.EndVertical();
}
if(drawer != null){
drawer.fieldInfo=field;
drawer.OnGUI(property,content);
}else{
int indentLevel=EditorGUI.indentLevel;
EditorGUI.indentLevel= typeof(IList).IsAssignableFrom(field.FieldType)?indentLevel+1:indentLevel;
EditorGUILayout.PropertyField (property, content,true);
EditorGUI.indentLevel=indentLevel;
}
}
if (EditorGUI.EndChangeCheck()) {
serializedObject.ApplyModifiedProperties();
ErrorChecker.CheckForErrors();
}
}
示例2: ScreenShotComponent
public static void ScreenShotComponent(Rect contentRect, UnityEngine.Object target)
{
ScreenShots.s_TakeComponentScreenshot = false;
contentRect.yMax += 2f;
contentRect.xMin += 1f;
ScreenShots.SaveScreenShotWithBorder(contentRect, ScreenShots.kWindowBorderColor, target.GetType().Name + "Inspector");
}
示例3: InitializeControlFreakTouchController
protected virtual void InitializeControlFreakTouchController(UnityEngine.Object touchController)
{
if (touchController != null){
Type inputType = touchController.GetType();
if (inputType != null){
this.deadZone = UFE.config.inputOptions.controlFreakDeadZone;
this.useControlFreak = true;
// Retrieve the required methods using the Reflection API to avoid
// compilation errors if Control-Freak's TouchController hasn't been
// imported into the project. We will cache the method information
// to call these methods later
MethodInfo getAxisInfo = inputType.GetMethod(
"GetAxis",
BindingFlags.Instance | BindingFlags.Public,
null,
new Type[]{typeof(string)},
null
);
if (getAxisInfo != null){
this.getAxis = delegate(string axis){
return (float) getAxisInfo.Invoke(touchController, new object[]{axis});
};
}
MethodInfo getAxisRawInfo = inputType.GetMethod(
"GetAxisRaw",
BindingFlags.Instance | BindingFlags.Public,
null,
new Type[]{typeof(string)},
null
);
if (getAxisRawInfo != null){
this.getAxisRaw = delegate(string axis){
return (float) getAxisRawInfo.Invoke(touchController, new object[]{axis});
};
}
MethodInfo getButtonInfo = inputType.GetMethod(
"GetButton",
BindingFlags.Instance | BindingFlags.Public,
null,
new Type[]{typeof(string)},
null
);
if (getButtonInfo != null){
this.getButton = delegate(string button){
return (bool) getButtonInfo.Invoke(touchController, new object[]{button});
};
}
}
}
}
示例4: CheckForErrors
public static void CheckForErrors(UnityEngine.Object targetObject){
if (targetObject == null) {
return;
}
if (targetObject.GetType ()==typeof(StateMachine)) {
checkingStateMachine = targetObject as StateMachine;
}else if(targetObject.GetType()==typeof(State)){
checkingState=targetObject as State;
} else if (targetObject.GetType ().IsSubclassOf (typeof(ExecutableNode))) {
checkingExecutableNode=targetObject as ExecutableNode;
}
FieldInfo[] fields = targetObject.GetType().GetAllFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
for (int i=0; i<fields.Length; i++) {
FieldInfo field=fields[i];
if(field.HasAttribute(typeof(ReferenceAttribute)) || !field.IsSerialized()){
continue;
}
object value=field.GetValue(targetObject);
if(field.FieldType.IsSubclassOf(typeof(FsmVariable))){
if(!field.HasAttribute(typeof(NotRequiredAttribute)) &&(value == null || CheckForVariableError(value as FsmVariable,field))){
FsmError error=new FsmError(FsmError.ErrorType.RequiredField,checkingStateMachine,checkingState,checkingExecutableNode,value as FsmVariable,field);
if(!ContainsError(error)){
errorList.Add(error);
}
}
}else if(field.FieldType.IsSubclassOf(typeof(UnityEngine.Object))){
CheckForErrors(value as UnityEngine.Object);
}else if(field.FieldType.IsArray){
var array = value as Array;
Type elementType = field.FieldType.GetElementType ();
if(elementType.IsSubclassOf(typeof(UnityEngine.Object))){
foreach(UnityEngine.Object element in array){
CheckForErrors(element);
}
}
}
}
checkForErrors = false;
}
示例5: LogSingleInstance
public static void LogSingleInstance(UnityEngine.Object instanceToLog, params object[] toLog)
{
int instanceId;
if (instanceDict.TryGetValue(instanceToLog.GetType(), out instanceId))
{
if (instanceId == instanceToLog.GetInstanceID())
Log(toLog);
}
else
{
instanceDict[instanceToLog.GetType()] = instanceToLog.GetInstanceID();
Log(toLog);
}
}
示例6: GetTypeName
internal static string GetTypeName(UnityEngine.Object obj)
{
if (obj == (UnityEngine.Object) null)
return "Object";
string lower = AssetDatabase.GetAssetPath(obj).ToLower();
if (lower.EndsWith(".unity"))
return "Scene";
if (lower.EndsWith(".guiskin"))
return "GUI Skin";
if (Directory.Exists(AssetDatabase.GetAssetPath(obj)))
return "Folder";
if (obj.GetType() == typeof (UnityEngine.Object))
return Path.GetExtension(lower) + " File";
return ObjectNames.GetClassName(obj);
}
示例7: GetTypeName
internal static string GetTypeName(UnityEngine.Object obj)
{
string text = AssetDatabase.GetAssetPath(obj).ToLower();
if (text.EndsWith(".unity"))
{
return "Scene";
}
if (text.EndsWith(".guiskin"))
{
return "GUI Skin";
}
if (Directory.Exists(AssetDatabase.GetAssetPath(obj)))
{
return "Folder";
}
if (obj.GetType() == typeof(UnityEngine.Object))
{
return Path.GetExtension(text) + " File";
}
return ObjectNames.GetClassName(obj);
}
示例8: ValidateEditor
/// <summary>
/// this class will call the validate method of the inspector
/// </summary>
/// <param name="theGameObject"></param>
public static KGFMessageList ValidateEditor(UnityEngine.Object theObject)
{
KGFMessageList aMessageList = new KGFMessageList();
string anObjectName = theObject.GetType().ToString();
string aTypeName = anObjectName+"Editor";
Type aType = Type.GetType(aTypeName);
if(aType != null)
{
MethodInfo aMethodInfo = aType.GetMethod("Validate"+aTypeName,System.Reflection.BindingFlags.Static | BindingFlags.Public);
if(aMethodInfo != null && aMethodInfo.GetParameters().Length == 1)
{
object[] aParameters = new object[1];
aParameters[0] = theObject;
aMessageList = (KGFMessageList)aMethodInfo.Invoke(null,aParameters);
}
else
{
if (!itsAlreadySentWarnings.Contains(aTypeName))
{
itsAlreadySentWarnings.Add(aTypeName);
aMessageList.AddWarning("static method Validate"+aTypeName+"() not implemented in: "+aTypeName);
Debug.LogWarning("static method Validate() not implemented in: "+aTypeName);
}
}
}
else
{
if (!itsAlreadySentWarnings.Contains(aTypeName))
{
itsAlreadySentWarnings.Add(aTypeName);
aMessageList.AddWarning("type: "+aTypeName+" not implemented.");
Debug.LogWarning("type: "+aTypeName+" not implemented.");
}
}
return aMessageList;
}
示例9: GeneratePopUpForType
private static void GeneratePopUpForType(GenericMenu menu, UnityEngine.Object target, bool useFullTargetName, SerializedProperty listener, System.Type[] delegateArgumentsTypes)
{
List<UnityEventDrawer.ValidMethodMap> methods = new List<UnityEventDrawer.ValidMethodMap>();
string targetName = !useFullTargetName ? target.GetType().Name : target.GetType().FullName;
bool flag = false;
if (delegateArgumentsTypes.Length != 0)
{
UnityEventDrawer.GetMethodsForTargetAndMode(target, delegateArgumentsTypes, methods, PersistentListenerMode.EventDefined);
if (methods.Count > 0)
{
menu.AddDisabledItem(new GUIContent(targetName + "/Dynamic " + string.Join(", ", ((IEnumerable<System.Type>) delegateArgumentsTypes).Select<System.Type, string>((Func<System.Type, string>) (e => UnityEventDrawer.GetTypeName(e))).ToArray<string>())));
UnityEventDrawer.AddMethodsToMenu(menu, listener, methods, targetName);
flag = true;
}
}
methods.Clear();
UnityEventDrawer.GetMethodsForTargetAndMode(target, new System.Type[1]{ typeof (float) }, methods, PersistentListenerMode.Float);
UnityEventDrawer.GetMethodsForTargetAndMode(target, new System.Type[1]{ typeof (int) }, methods, PersistentListenerMode.Int);
UnityEventDrawer.GetMethodsForTargetAndMode(target, new System.Type[1]{ typeof (string) }, methods, PersistentListenerMode.String);
UnityEventDrawer.GetMethodsForTargetAndMode(target, new System.Type[1]{ typeof (bool) }, methods, PersistentListenerMode.Bool);
UnityEventDrawer.GetMethodsForTargetAndMode(target, new System.Type[1]{ typeof (UnityEngine.Object) }, methods, PersistentListenerMode.Object);
UnityEventDrawer.GetMethodsForTargetAndMode(target, new System.Type[0], methods, PersistentListenerMode.Void);
if (methods.Count <= 0)
return;
if (flag)
menu.AddItem(new GUIContent(targetName + "/ "), false, (GenericMenu.MenuFunction) null);
if (delegateArgumentsTypes.Length != 0)
menu.AddDisabledItem(new GUIContent(targetName + "/Static Parameters"));
UnityEventDrawer.AddMethodsToMenu(menu, listener, methods, targetName);
}
示例10: CalculateMethodMap
private static IEnumerable<UnityEventDrawer.ValidMethodMap> CalculateMethodMap(UnityEngine.Object target, System.Type[] t, bool allowSubclasses)
{
List<UnityEventDrawer.ValidMethodMap> validMethodMapList = new List<UnityEventDrawer.ValidMethodMap>();
if (target == (UnityEngine.Object) null || t == null)
return (IEnumerable<UnityEventDrawer.ValidMethodMap>) validMethodMapList;
System.Type type = target.GetType();
List<MethodInfo> list = ((IEnumerable<MethodInfo>) type.GetMethods()).Where<MethodInfo>((Func<MethodInfo, bool>) (x => !x.IsSpecialName)).ToList<MethodInfo>();
IEnumerable<PropertyInfo> source = ((IEnumerable<PropertyInfo>) type.GetProperties()).AsEnumerable<PropertyInfo>().Where<PropertyInfo>((Func<PropertyInfo, bool>) (x =>
{
if (x.GetCustomAttributes(typeof (ObsoleteAttribute), true).Length == 0)
return x.GetSetMethod() != null;
return false;
}));
list.AddRange(source.Select<PropertyInfo, MethodInfo>((Func<PropertyInfo, MethodInfo>) (x => x.GetSetMethod())));
using (List<MethodInfo>.Enumerator enumerator = list.GetEnumerator())
{
while (enumerator.MoveNext())
{
MethodInfo current = enumerator.Current;
System.Reflection.ParameterInfo[] parameters = current.GetParameters();
if (parameters.Length == t.Length && current.GetCustomAttributes(typeof (ObsoleteAttribute), true).Length <= 0 && current.ReturnType == typeof (void))
{
bool flag = true;
for (int index = 0; index < t.Length; ++index)
{
if (!parameters[index].ParameterType.IsAssignableFrom(t[index]))
flag = false;
if (allowSubclasses && t[index].IsAssignableFrom(parameters[index].ParameterType))
flag = true;
}
if (flag)
validMethodMapList.Add(new UnityEventDrawer.ValidMethodMap()
{
target = target,
methodInfo = current
});
}
}
}
return (IEnumerable<UnityEventDrawer.ValidMethodMap>) validMethodMapList;
}
示例11: FindCustomEditorType
internal static System.Type FindCustomEditorType(UnityEngine.Object o, bool multiEdit)
{
return CustomEditorAttributes.FindCustomEditorTypeByType(o.GetType(), multiEdit);
}
示例12: HelpIconButton
internal static bool HelpIconButton(Rect position, UnityEngine.Object obj)
{
bool flag1 = Unsupported.IsDeveloperBuild();
bool defaultToMonoBehaviour = !flag1 || obj.GetType().Assembly.ToString().StartsWith("Assembly-");
bool flag2 = Help.HasHelpForObject(obj, defaultToMonoBehaviour);
if (!flag2 && !flag1)
return false;
Color color = GUI.color;
GUIContent content = new GUIContent(EditorGUI.GUIContents.helpIcon);
string helpNameForObject = Help.GetNiceHelpNameForObject(obj, defaultToMonoBehaviour);
if (flag1 && !flag2)
{
GUI.color = Color.yellow;
string str = (!(obj is MonoBehaviour) ? "sealed partial class-" : "script-") + helpNameForObject;
content.tooltip = string.Format("Could not find Reference page for {0} ({1}).\nDocs for this object is missing or all docs are missing.\nThis warning only shows up in development builds.", (object) helpNameForObject, (object) str);
}
else
content.tooltip = string.Format("Open Reference for {0}.", (object) helpNameForObject);
GUIStyle inspectorTitlebarText = EditorStyles.inspectorTitlebarText;
if (GUI.Button(position, content, inspectorTitlebarText))
Help.ShowHelpForObject(obj);
GUI.color = color;
return true;
}
示例13: GetMethod
internal protected static bool GetMethod(UnityEngine.MonoBehaviour monob, string methodType, out MethodInfo mi)
{
mi = null;
if (monob == null || string.IsNullOrEmpty(methodType))
{
return false;
}
List<MethodInfo> methods = SupportClass.GetMethods(monob.GetType(), null);
for (int index = 0; index < methods.Count; index++)
{
MethodInfo methodInfo = methods[index];
if (methodInfo.Name.Equals(methodType))
{
mi = methodInfo;
return true;
}
}
return false;
}
示例14: GetAssetId
public SaveGameManager.AssetReference GetAssetId(UnityEngine.Object referencedObject)
{
if (referencedObject == null)
{
return new SaveGameManager.AssetReference
{
index = -1
};
}
Index<string, List<UnityEngine.Object>> index = null;
Type type = referencedObject.GetType();
if (!this.assetReferences.TryGetValue(type, out index))
{
index = (this.assetReferences[type] = new Index<string, List<UnityEngine.Object>>());
IEnumerable<UnityEngine.Object> enumerable = Resources.FindObjectsOfTypeAll(type).Except(UnityEngine.Object.FindObjectsOfType(type));
foreach (UnityEngine.Object current in enumerable)
{
index[current.name].Add(current);
}
}
List<UnityEngine.Object> list = null;
if (!index.TryGetValue(referencedObject.name, out list))
{
return new SaveGameManager.AssetReference
{
index = -1
};
}
return new SaveGameManager.AssetReference
{
index = list.IndexOf(referencedObject),
name = referencedObject.name,
type = type.FullName
};
}
示例15: SerializeUnityObject
/** Write a UnityEngine.Object */
public void SerializeUnityObject ( UnityEngine.Object ob ) {
if ( ob == null ) {
writer.Write (int.MaxValue);
return;
}
int inst = ob.GetInstanceID();
string name = ob.name;
string type = ob.GetType().AssemblyQualifiedName;
string guid = "";
//Write scene path if the object is a Component or GameObject
Component component = ob as Component;
GameObject go = ob as GameObject;
if (component != null || go != null) {
if (component != null && go == null) {
go = component.gameObject;
}
UnityReferenceHelper helper = go.GetComponent<UnityReferenceHelper>();
if (helper == null) {
Debug.Log ("Adding UnityReferenceHelper to Unity Reference '"+ob.name+"'");
helper = go.AddComponent<UnityReferenceHelper>();
}
//Make sure it has a unique GUID
helper.Reset ();
guid = helper.GetGUID ();
}
writer.Write(inst);
writer.Write(name);
writer.Write(type);
writer.Write(guid);
}