当前位置: 首页>>代码示例>>C#>>正文


C# Component.GetType方法代码示例

本文整理汇总了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;
        }
开发者ID:XianWorld,项目名称:spacepuppy-unity-framework,代码行数:30,代码来源:SPEditorGUI.cs

示例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;
 }
开发者ID:MechroCat22,项目名称:VR-Object-Hunt,代码行数:9,代码来源:Utilities.cs

示例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 ) );			
		}
	}
开发者ID:cuongngo90,项目名称:Unity-SpriteShader,代码行数:13,代码来源:VolumeEffectsFlags.cs

示例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 ();
			}
		}
开发者ID:AlexGam,项目名称:TowerIsland,代码行数:13,代码来源:SetProperty.cs

示例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 ) );
		}

	}
开发者ID:cuongngo90,项目名称:Unity-SpriteShader,代码行数:15,代码来源:VolumeEffectsFlags.cs

示例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;
		}
开发者ID:Charkova,项目名称:MetaEden.a14,代码行数:34,代码来源:CoherentMethodAttribute.cs

示例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[]{});
			} 
		}
开发者ID:AlexGam,项目名称:TowerIsland,代码行数:7,代码来源:Invoke.cs

示例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 });
 }
开发者ID:simonwittber,项目名称:netwrok-client,代码行数:9,代码来源:MessageDispatcher.cs

示例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);
            }
        }
开发者ID:jmschrack,项目名称:LudumDare33,代码行数:14,代码来源:PresetMatrixWindow.cs

示例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);
 }
开发者ID:ArthurRasmusson,项目名称:UofTHacks2016,代码行数:10,代码来源:CinemaClipCurve.cs

示例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);
		}
开发者ID:JuanJosePol,项目名称:ggjmallorca2016,代码行数:10,代码来源:EffectsPostProcessor.cs

示例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>();
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:11,代码来源:VolumeEffectComponent.cs

示例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);
         }
     }
 }
开发者ID:zeropointx,项目名称:KartClone,代码行数:14,代码来源:Utility.cs

示例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;
		}
开发者ID:procore3d,项目名称:giles,代码行数:27,代码来源:pb_ComponentEditorResolver.cs

示例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);
             }
         }
     }
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:16,代码来源:VolumeEffectComponent.cs


注:本文中的UnityEngine.Component.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。