本文整理汇总了C#中UnityEngine.Component.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Component.GetType方法的具体用法?C# Component.GetType怎么用?C# Component.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Component
的用法示例。
在下文中一共展示了Component.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComponentField
public static Component ComponentField(Rect position, GUIContent label, Component value, System.Type inheritsFromType, bool allowSceneObjects, System.Type targetComponentType)
{
if (inheritsFromType == null) inheritsFromType = typeof(Component);
else if (!typeof(Component).IsAssignableFrom(inheritsFromType) && !typeof(IComponent).IsAssignableFrom(inheritsFromType)) throw new TypeArgumentMismatchException(inheritsFromType, typeof(IComponent), "Type must inherit from IComponent or Component.", "inheritsFromType");
if (targetComponentType == null) throw new System.ArgumentNullException("targetComponentType");
if (!typeof(Component).IsAssignableFrom(targetComponentType)) throw new TypeArgumentMismatchException(targetComponentType, typeof(Component), "targetComponentType");
if (value != null && !targetComponentType.IsAssignableFrom(value.GetType())) throw new TypeArgumentMismatchException(value.GetType(), inheritsFromType, "value must inherit from " + inheritsFromType.Name, "value");
if (TypeUtil.IsType(inheritsFromType, typeof(Component)))
{
return EditorGUI.ObjectField(position, label, value, inheritsFromType, true) as Component;
}
else
{
value = EditorGUI.ObjectField(position, label, value, typeof(Component), true) as Component;
var go = GameObjectUtil.GetGameObjectFromSource(value);
if (go != null)
{
foreach (var c in go.GetComponents(inheritsFromType))
{
if (TypeUtil.IsType(c.GetType(), targetComponentType))
{
return c as Component;
}
}
}
}
return null;
}
示例2: CloneComponent
public static Component CloneComponent(Component source, GameObject destination)
{
Component tmpComponent = destination.gameObject.AddComponent(source.GetType());
foreach (FieldInfo f in source.GetType().GetFields())
{
f.SetValue(tmpComponent, f.GetValue(source));
}
return tmpComponent;
}
示例3: UpdateComponentFlags
public void UpdateComponentFlags( Component c )
{
#if !UNITY_EDITOR && UNITY_METRO
FieldInfo[] fields=c.GetType().GetRuntimeFields().ToArray();
#else
FieldInfo[] fields = c.GetType().GetFields();
#endif
foreach ( FieldInfo pi in fields )
{
if ( !componentFields.Exists( s => s.fieldName == pi.Name ) && VolumeEffectField.IsValidType( pi.FieldType.FullName ) )
componentFields.Add( new VolumeEffectFieldFlags( pi ) );
}
}
示例4: OnEnter
public override void OnEnter ()
{
base.OnEnter ();
mComponent = gameObject.Value.GetComponent (component);
fieldInfo = mComponent.GetType ().GetField (property);
if (fieldInfo == null) {
propertyInfo= mComponent.GetType().GetProperty(property);
}
DoSetProperty ();
if (!everyFrame) {
Finish ();
}
}
示例5: VolumeEffectComponentFlags
public VolumeEffectComponentFlags( Component c )
: this( c.GetType() + "" )
{
#if !UNITY_EDITOR && UNITY_METRO
FieldInfo[] fields=c.GetType().GetRuntimeFields().ToArray();
#else
FieldInfo[] fields = c.GetType().GetFields();
#endif
foreach ( FieldInfo pi in fields )
{
if ( VolumeEffectField.IsValidType( pi.FieldType.FullName ) )
componentFields.Add( new VolumeEffectFieldFlags( pi ) );
}
}
示例6: GetCoherentMethodsInComponent
private static List<CoherentMethodBindingInfo> GetCoherentMethodsInComponent(Component component)
{
List<CoherentMethodBindingInfo> coherentMethods = new List<CoherentMethodBindingInfo>();
Type type = component.GetType();
List<CoherentMethodBindingInfo> cachedCoherentMethods;
if (s_CoherentMethodsCache.TryGetValue(type, out cachedCoherentMethods))
{
return cachedCoherentMethods;
}
// Iterate methods of each type
BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
foreach (MethodInfo methodInfo in type.GetMethods(bindingFlags))
{
// Iterate custom attributes
var attributes = methodInfo.GetCustomAttributes(typeof(CoherentMethodAttribute), true);
foreach (object customAttribute in attributes)
{
CoherentMethodAttribute coherentMethodAttribute = (customAttribute as CoherentMethodAttribute);
Delegate func = CoherentMethodHelper.ToDelegate(methodInfo, component);
coherentMethods.Add(new CoherentMethodBindingInfo(){
ScriptEventName = coherentMethodAttribute.ScriptEventName,
BoundFunction = func,
IsEvent = coherentMethodAttribute.IsEvent
});
}
}
s_CoherentMethodsCache.Add(type, coherentMethods);
return coherentMethods;
}
示例7: InvokeMethod
private IEnumerator InvokeMethod(Component component){
yield return new WaitForSeconds(delay.Value);
MethodInfo methodInfo=component.GetType().GetMethod(methodName);
if (methodInfo != null) {
methodInfo.Invoke (component, new object[]{});
}
}
示例8: AddMethodToTable
void AddMethodToTable(Component c, MethodInfo mi, string key, Dictionary<string, List<MethodReference>> table)
{
if(key == null)
key = string.Format ("{0}.{1}", c.GetType ().Name, mi.Name);
if (!table.ContainsKey (key))
table [key] = new List<MethodReference> ();
Debug.Log ("Registering Network Method: " + key);
table [key].Add (new MethodReference () { c = c, mi = mi });
}
示例9: DrawComponent
/// <summary>
/// Draw the component's public fields in a way that the user can edit
/// </summary>
/// <param name="component">The component whose fields we're drawing</param>
private static void DrawComponent(Component component)
{
Type componentType = component.GetType();
FieldInfo[] typeFields = componentType.GetFields(BindingFlags.Public | BindingFlags.Instance);
foreach(FieldInfo fieldInfo in typeFields)
{
DrawField(fieldInfo, component);
}
}
示例10: AddClipCurveData
public void AddClipCurveData(Component component, string name, bool isProperty, Type type)
{
MemberClipCurveData data = new MemberClipCurveData();
data.Type = component.GetType().Name;
data.PropertyName = name;
data.IsProperty = isProperty;
data.PropertyType = UnityPropertyTypeInfo.GetMappedType(type);
initializeClipCurves(data, component);
curveData.Add(data);
}
示例11: ProcessDepthOfField
private static void ProcessDepthOfField(Component gameComponent, Component sceneComponent)
{
Type dofType = sceneComponent.GetType();
FieldInfo fPlaneField = dofType.GetField("focusPlane", Utilities.DEFAULT_BINDING_FLAG);
if (fPlaneField == null) return;
float currentValue = (float)fPlaneField.GetValue(sceneComponent);
float factor = Mathf.Pow(Mathf.Pow(currentValue, 4) / (sceneComponent.GetComponent<Camera>().farClipPlane / gameComponent.GetComponent<Camera>().farClipPlane), 1.0f / 4);
fPlaneField.SetValue(sceneComponent, factor);
}
示例12: ListAcceptableFields
public static FieldInfo[] ListAcceptableFields(Component c)
{
if (c == null)
{
return new FieldInfo[0];
}
FieldInfo[] source = c.GetType().GetFields();
return (from f in source
where VolumeEffectField.IsValidType(f.FieldType.FullName)
select f).ToArray<FieldInfo>();
}
示例13: CopyComponent
public static void CopyComponent(GameObject target, Component original)
{
System.Type type = original.GetType();
Component copy = target.AddComponent(type);
BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Default | BindingFlags.DeclaredOnly;
PropertyInfo[] pinfos = type.GetProperties(flags);
foreach (var pinfo in pinfos)
{
if (pinfo.CanWrite)
{
pinfo.SetValue(copy, pinfo.GetValue(original, null), null);
}
}
}
示例14: GetEditor
/**
* Find the best matching pb_ComponentEditor for a type.
*/
public static pb_ComponentEditor GetEditor(Component component)
{
GameObject go = new GameObject();
Type editorType = null;
if( !builtInComponentEditors.TryGetValue(component.GetType(), out editorType) )
{
foreach(KeyValuePair<Type, Type> kvp in builtInComponentEditors)
{
if(kvp.Key.IsAssignableFrom(component.GetType()))
{
editorType = kvp.Value;
break;
}
}
}
go.name = component.name;
pb_ComponentEditor editor = (pb_ComponentEditor) go.AddComponent( editorType ?? typeof(pb_ComponentEditor) );
editor.SetComponent(component);
return editor;
}
示例15: VolumeEffectComponent
public VolumeEffectComponent(Component c, VolumeEffectComponentFlags compFlags)
: this(compFlags.componentName)
{
foreach (VolumeEffectFieldFlags current in compFlags.componentFields)
{
if (current.blendFlag)
{
FieldInfo field = c.GetType().GetField(current.fieldName);
VolumeEffectField volumeEffectField = (!VolumeEffectField.IsValidType(field.FieldType.FullName)) ? null : new VolumeEffectField(field, c);
if (volumeEffectField != null)
{
this.fields.Add(volumeEffectField);
}
}
}
}