Example #1
0
 public static UnityEngine.Object[] GetFiltered(System.Type type, UnityEditor.SelectionMode mode)
 {
     ArrayList list = new ArrayList();
     if ((type == typeof(Component)) || type.IsSubclassOf(typeof(Component)))
     {
         foreach (Transform transform in GetTransforms(mode))
         {
             Component component = transform.GetComponent(type);
             if (component != null)
             {
                 list.Add(component);
             }
         }
     }
     else if ((type == typeof(GameObject)) || type.IsSubclassOf(typeof(GameObject)))
     {
         foreach (Transform transform2 in GetTransforms(mode))
         {
             list.Add(transform2.gameObject);
         }
     }
     else
     {
         foreach (UnityEngine.Object obj2 in GetObjectsMode(mode))
         {
             if ((obj2 != null) && ((obj2.GetType() == type) || obj2.GetType().IsSubclassOf(type)))
             {
                 list.Add(obj2);
             }
         }
     }
     return (UnityEngine.Object[]) list.ToArray(typeof(UnityEngine.Object));
 }
Example #2
0
 /// <summary>
 /// Add an ability from the ability store to the ability HUD as they are purchased
 /// </summary>
 /// <param name="AbilityType"></param>
 public void AddAbility(System.Type AbilityType)
 {
     //If the ability type is valid
     if (AbilityType.IsSubclassOf(typeof(Ability)))
     {
         bool AbilityExists = (Abilities.Where(a => a.GetType() == AbilityType).Count() > 0);
         //If the ability is already in the list
         if (AbilityExists)
         {
             Ability ability = Abilities.Where(a => a.GetType() == AbilityType).Select(a => a).Single();
             ability.Quantity++;
         }
         //If it is not
         else {
             Ability newa = System.Activator.CreateInstance(AbilityType) as Ability;
             newa.Quantity = 1;
             Abilities.Add(newa);
         }
         UpdateButtons();
     }
     else
     {
         Debug.Log("Error: Invalid Ability type");
     }
 }
Example #3
0
        public static OpCode Create(System.Type t)
        {
            if(t.IsSubclassOf(typeof(OpCode)))
            {
                return Activator.CreateInstance(t) as OpCode;
            }

            throw new ParseException("Type derived from HVM.OpCode", t.ToString());
        }
Example #4
0
	/// <summary> 
	/// Returns True if the value has the supplied type; False otherwise.
	/// <param name="type">The field type to check.</param>
	/// <returns>True if the value has the supplied type; False otherwise.</returns>
	/// <summary> 
	public bool HasType (System.Type type) {
		switch (m_FieldType) {
			case FieldType.Int:
				return type == typeof(int);
			case FieldType.String:
				return type == typeof(string); 
			case FieldType.Float:
				return type == typeof(float);
			case FieldType.Enum:
				return type.IsEnum;
			case FieldType.Bool:
				return type == typeof(bool);
			case FieldType.Vector2:
				return type == typeof(Vector2);
			case FieldType.Vector3:
				return type == typeof(Vector3);
			case FieldType.Vector4:
				return type == typeof(Vector4);
			case FieldType.Quaternion:
				return type == typeof(Quaternion);
			case FieldType.Rect:
				return type == typeof(Rect);
			case FieldType.Color:
				return type == typeof(Color);
			case FieldType.LayerMask:
				return type == typeof(LayerMask);
			case FieldType.AnimationCurve:
				return type == typeof(AnimationCurve);
			case FieldType.Array:
				return type.IsArray;
			case FieldType.Constant:
				return type.IsSubclassOf(typeof(Variable));
			case FieldType.None:
				return type.IsSubclassOf(typeof(Variable));
			case FieldType.UnityObject:
				return type.IsSubclassOf(typeof(UnityEngine.Object)) || type == typeof(UnityEngine.Object);
			case FieldType.State:
				return type == typeof(InternalStateBehaviour);
			case FieldType.Generic:
				return !type.IsValueType && !typeof(Variable).IsAssignableFrom(type) && !typeof(UnityEngine.Object).IsAssignableFrom(type);
		}
		return false;
	}
Example #5
0
	/// <summary>
	/// Get the URL pointing to the documentation for the specified component.
	/// </summary>

	static public string GetHelpURL (System.Type type)
	{
		if (type == typeof(UITexture))		return "http://www.tasharen.com/forum/index.php?topic=6703";
		if (type == typeof(UISprite))		return "http://www.tasharen.com/forum/index.php?topic=6704";
		if (type == typeof(UIPanel))		return "http://www.tasharen.com/forum/index.php?topic=6705";
		if (type == typeof(UILabel))		return "http://www.tasharen.com/forum/index.php?topic=6706";
		if (type == typeof(UIButton))		return "http://www.tasharen.com/forum/index.php?topic=6708";
		if (type == typeof(UIToggle))		return "http://www.tasharen.com/forum/index.php?topic=6709";
		if (type == typeof(UIRoot))			return "http://www.tasharen.com/forum/index.php?topic=6710";
		if (type == typeof(UICamera))		return "http://www.tasharen.com/forum/index.php?topic=6711";
		if (type == typeof(UIAnchor))		return "http://www.tasharen.com/forum/index.php?topic=6712";
		if (type == typeof(UIStretch))		return "http://www.tasharen.com/forum/index.php?topic=6713";
		if (type == typeof(UISlider))		return "http://www.tasharen.com/forum/index.php?topic=6715";
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
		if (type == typeof(UI2DSprite))		return "http://www.tasharen.com/forum/index.php?topic=6729";
#endif
		if (type == typeof(UIScrollBar))	return "http://www.tasharen.com/forum/index.php?topic=6733";
		if (type == typeof(UIProgressBar))	return "http://www.tasharen.com/forum/index.php?topic=6738";
		if (type == typeof(UIPopupList))	return "http://www.tasharen.com/forum/index.php?topic=6751";
		if (type == typeof(UIInput))		return "http://www.tasharen.com/forum/index.php?topic=6752";
		if (type == typeof(UIKeyBinding))	return "http://www.tasharen.com/forum/index.php?topic=6753";
		if (type == typeof(UIGrid))			return "http://www.tasharen.com/forum/index.php?topic=6756";
		if (type == typeof(UITable))		return "http://www.tasharen.com/forum/index.php?topic=6758";
		
		if (type == typeof(ActiveAnimation) || type == typeof(UIPlayAnimation))
			return "http://www.tasharen.com/forum/index.php?topic=6762";

		if (type == typeof(UIScrollView) || type == typeof(UIDragScrollView))
			return "http://www.tasharen.com/forum/index.php?topic=6763";

		if (type == typeof(UIWidget) || type.IsSubclassOf(typeof(UIWidget)))
			return "http://www.tasharen.com/forum/index.php?topic=6702";

		if (type == typeof(UIPlayTween) || type.IsSubclassOf(typeof(UITweener)))
			return "http://www.tasharen.com/forum/index.php?topic=6760";

		if (type == typeof(UILocalize) || type == typeof(Localization))
			return "http://www.tasharen.com/forum/index.php?topic=8092.0";

		return null;
	}
Example #6
0
 public SubDrawerAttribute( System.Type type, params object[] objects )
 {
     if ( !type.IsSubclassOf( typeof( PropertyAttribute ) ) ) return;
     System.Type[] paramTypes = objects == null ? Type.EmptyTypes : new Type[ objects.Length];
     for ( int i = 0; i < objects.Length; i++ ) {
         paramTypes[ i ] = objects[ i ].GetType();
     }
     ConstructorInfo ci = type.GetConstructor( paramTypes );
     if( ci == null ){
         Debug.Log( "GetConstructor Error" );
     }
     else{
         SecondAttribute = ci.Invoke( objects ) as PropertyAttribute;
     }
 }
Example #7
0
    // called after the object has been created, and it is being dropped
    public void Drop(Pawn dropper, System.Type itemType)
    {
        if(!itemType.IsSubclassOf(typeof(Item))) {
            Debug.Log("WARNING! "+dropper.name+" tried to drop a "+itemType.ToString()+". Must extend Item!");
            return;
        }

        bHasLanded = false;
        startDropSpeed = Random.Range(0.0f, maxVelocity);
        velocity = Random.insideUnitCircle * startDropSpeed;
        velocity.y = Mathf.Abs(velocity.y);
        groundHeight = (dropper.transform.position - dropper.GetBaseOffset()).y;

        item = (Item)System.Activator.CreateInstance(itemType);
        droppedBy = dropper;
    }
        public override System.Threading.Tasks.Task WriteToStreamAsync(System.Type type, object value, System.IO.Stream writeStream, System.Net.Http.HttpContent content, System.Net.TransportContext transportContext)
        {
            var obj = new ExpandoObject() as IDictionary<string, Object>;
            if (type.IsSubclassOf(typeof(BaseMetaResponseModel)) && type.IsGenericType)
            {
                Type innerType = type.GetGenericArguments()[0];
                var genericValue = (value as BaseMetaResponseModel);
                value = genericValue.Content;
                type = innerType;
                obj["meta"] = genericValue.Meta;

            }
            var root = GetRootFieldName(type, value);
            obj[root] = value;
            return base.WriteToStreamAsync(type, obj as object, writeStream, content, transportContext);
        }
Example #9
0
        private static System.Data.Common.DbProviderFactory GetFactory(System.Type type)
        {
            if (type != null && type.IsSubclassOf(typeof(System.Data.Common.DbProviderFactory)))
            {
                // Provider factories are singletons with Instance field having
                // the sole instance
                System.Reflection.FieldInfo field = type.GetField("Instance"
                    , System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static
                );

                if (field != null)
                {
                    return (System.Data.Common.DbProviderFactory)field.GetValue(null);
                    //return field.GetValue(null) as DbProviderFactory;
                } // End if (field != null)

            } // End if (type != null && type.IsSubclassOf(typeof(System.Data.Common.DbProviderFactory)))

            throw new System.Configuration.ConfigurationErrorsException("DataProvider is missing!");
            //throw new System.Configuration.ConfigurationException("DataProvider is missing!");
        }
Example #10
0
    	/// <summary> 
        /// Adds a new node to the action state, automatically handles undo, dirty flag and save node.
        /// <param name="actionState">The action state to add a new node.</param>
        /// <param name="nodeType">The type of the new node.</param>
        /// <returns>The new node.</returns>
        /// </summary>
        public static ActionNode AddNode (InternalActionState actionState, System.Type nodeType) {
            // Validate parameters
            if (actionState != null && nodeType != null && nodeType.IsSubclassOf(typeof(ActionNode)) && !nodeType.IsAbstract) {
                // Register Undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterUndo(actionState,"Add New Node");
                #else
                Undo.RecordObject(actionState,"Add New Node");
                #endif

                // Create new node
                var newNode = actionState.AddNode(nodeType);

                if (newNode != null) {                    
                    // Saves node and sets dirty flag
                    StateUtility.SetDirty(actionState);
                    return newNode;
                }
            }

            return null;
        }
        public Delegate GetMethod(string name, System.Type delegShape)
        {
            if (_wrappedObject == null) throw new InvalidOperationException("Can only access static members.");
            if (!delegShape.IsSubclassOf(typeof(Delegate))) throw new ArgumentException("Type must inherit from Delegate.", "delegShape");

            var binding = PUBLIC_MEMBERS;
            if (_includeNonPublic) binding |= BindingFlags.NonPublic;

            var invokeMeth = delegShape.GetMethod("Invoke");
            var paramTypes = (from p in invokeMeth.GetParameters() select p.ParameterType).ToArray();
            MethodInfo meth = null;
            try
            {
                meth = _wrappedType.GetMethod(name, binding, null, paramTypes, null);
            }
            catch
            {
                try
                {
                    meth = _wrappedType.GetMethod(name, binding);
                }
                catch
                {

                }
            }

            if (meth != null)
            {
                try
                {
                    return Delegate.CreateDelegate(delegShape, _wrappedObject, meth);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("A method matching the name and shape requested could not be found.", ex);
                }
            }
            else
            {
                throw new InvalidOperationException("A method matching the name and shape requested could not be found.");
            }
        }
        internal static Skybound.VisualTips.IVisualTipExtender GetExtender(System.Type controlOrComponentType)
        {
            Skybound.VisualTips.IVisualTipExtender ivisualTipExtender2;

            Skybound.VisualTips.IVisualTipExtender ivisualTipExtender1 = Skybound.VisualTips.VisualTipProvider.Extenders[controlOrComponentType] as Skybound.VisualTips.IVisualTipExtender;
            if (ivisualTipExtender1 == null)
            {
                System.Collections.IDictionaryEnumerator idictionaryEnumerator = Skybound.VisualTips.VisualTipProvider.Extenders.GetEnumerator();
                try
                {
                    while (idictionaryEnumerator.MoveNext())
                    {
                        System.Collections.DictionaryEntry dictionaryEntry = (System.Collections.DictionaryEntry)idictionaryEnumerator.Current;
                        if (controlOrComponentType.IsSubclassOf(dictionaryEntry.Key as System.Type))
                        {
                            ivisualTipExtender2 = dictionaryEntry.Value as Skybound.VisualTips.IVisualTipExtender;
                            return ivisualTipExtender2;
                        }
                    }
                }
                finally
                {
                    System.IDisposable idisposable = idictionaryEnumerator as System.IDisposable;
                    if (idisposable != null)
                        idisposable.Dispose();
                }
            }
            return ivisualTipExtender1;
        }
        public void TestNonDesignerFormEndSuccessor(System.Type type, System.Type baseForm)
        {
            Assert.IsTrue(type.IsSubclassOf(baseForm), string.Format("{0} does not inherit from {1}!", type.Name, baseForm.Name));

            var attributes = type.GetCustomAttributes(typeof(System.ComponentModel.DesignerCategoryAttribute), false);

            Assert.GreaterOrEqual(attributes.Length, 1, string.Format("No DesignerCategoryAttribute for {0}!", type.Name));

            foreach (var a in attributes)
            {
                Assert.AreEqual(((System.ComponentModel.DesignerCategoryAttribute)a).Category, "Form", type.Name + " does not marked as DesignerCategoryAttribute - Form");
            }
        }
 internal static bool IsProtectedVisibleTo(MethodInfo method, System.Type derivedType, XamlSchemaContext schemaContext)
 {
     if (derivedType == null)
     {
         return false;
     }
     if (!derivedType.Equals(method.DeclaringType) && !derivedType.IsSubclassOf(method.DeclaringType))
     {
         return false;
     }
     if (method.IsFamily || method.IsFamilyOrAssembly)
     {
         return true;
     }
     if (!method.IsFamilyAndAssembly)
     {
         return false;
     }
     return (TypeReflector.IsInternal(method.DeclaringType) || schemaContext.AreInternalsVisibleTo(method.DeclaringType.Assembly, derivedType.Assembly));
 }
            // We pass in a type of the form to create rather than encode it as a generic parameter
            // so that we can have an array of the HelperWindowMenuItem.
            public HelperWindowMenuItem(MainForm mainForm, string name, System.Type tForm)
            {
                Debug.Assert(tForm.IsSubclassOf(typeof(gui.DebuggerToolWindow)));
                this.m_mainForm = mainForm;
                this.m_typeHelperForm = tForm;

                EventHandler handler = new EventHandler(this.OnClick);
                MenuItem item = new MenuItem(name, handler);
                this.m_mainForm.AddToViewMenu(item);
            }
        //While there is a similar method in EditorUtils, due to layouting and especialy no prefix name, this has to be redone a bit differently
        static object EditorField(object o, System.Type t, bool isPersistent, GUILayoutOption[] layoutOptions)
        {
            //Check scene object type for UnityObjects. Consider Interfaces as scene object type. Assumpt that user uses interfaces with UnityObjects
            var isSceneObjectType = (typeof(Component).IsAssignableFrom(t) || t == typeof(GameObject) || t.IsInterface);
            if (typeof(UnityEngine.Object).IsAssignableFrom(t) || t.IsInterface){
                return UnityEditor.EditorGUILayout.ObjectField((UnityEngine.Object)o, t, isSceneObjectType, layoutOptions);
            }

            //Check Type second
            if (t == typeof(System.Type)){
                return EditorUtils.Popup<System.Type>(null, (System.Type)o, UserTypePrefs.GetPreferedTypesList(typeof(object), false), true, layoutOptions );
            }

            t = o != null? o.GetType() : t;
            if (t.IsAbstract){
                GUILayout.Label( string.Format("({0})", t.FriendlyName()), layoutOptions );
                return o;
            }

            if (o == null && !t.IsAbstract && !t.IsInterface && (t.GetConstructor(System.Type.EmptyTypes) != null || t.IsArray ) ){
                if (GUILayout.Button("(null) Create", layoutOptions)){
                    if (t.IsArray)
                        return System.Array.CreateInstance(t.GetElementType(), 0);
                    return System.Activator.CreateInstance(t);
                }
                return o;
            }

            if (t == typeof(bool))
                return UnityEditor.EditorGUILayout.Toggle((bool)o, layoutOptions);
            if (t == typeof(Color))
                return UnityEditor.EditorGUILayout.ColorField((Color)o, layoutOptions);
            if (t == typeof(AnimationCurve))
                return UnityEditor.EditorGUILayout.CurveField((AnimationCurve)o, layoutOptions);
            if (t.IsSubclassOf(typeof(System.Enum) ))
                return UnityEditor.EditorGUILayout.EnumPopup((System.Enum)o, layoutOptions);
            if (t == typeof(float)){
                GUI.backgroundColor = UserTypePrefs.GetTypeColor(t);
                return UnityEditor.EditorGUILayout.FloatField((float)o, layoutOptions);
            }
            if (t == typeof(int)){
                GUI.backgroundColor = UserTypePrefs.GetTypeColor(t);
                return UnityEditor.EditorGUILayout.IntField((int)o, layoutOptions);
            }
            if (t == typeof(string)){
                GUI.backgroundColor = UserTypePrefs.GetTypeColor(t);
                return UnityEditor.EditorGUILayout.TextField((string)o, layoutOptions);
            }

            if (t == typeof(Vector2))
                return UnityEditor.EditorGUILayout.Vector2Field("", (Vector2)o, layoutOptions);
            if (t == typeof(Vector3))
                return UnityEditor.EditorGUILayout.Vector3Field("", (Vector3)o, layoutOptions);
            if (t == typeof(Vector4))
                return UnityEditor.EditorGUILayout.Vector4Field("", (Vector4)o, layoutOptions);

            if (t == typeof(Quaternion)){
                var q = (Quaternion)o;
                var v = new Vector4(q.x, q.y, q.z, q.w);
                v = UnityEditor.EditorGUILayout.Vector4Field("", v, layoutOptions);
                return new Quaternion(v.x, v.y, v.z, v.w);
            }

            //If some other type, show it in the generic object editor window
            if (GUILayout.Button( string.Format("{0} {1}", t.FriendlyName(), (o is IList)? ((IList)o).Count.ToString() : "" ), layoutOptions))
                GenericInspectorWindow.Show(o, t);

            return o;
        }
Example #17
0
 private static MatchResult MatchArgument(System.Type parameter, object arg)
 {
     if (parameter.IsInstanceOfType(arg))
         return MatchResult.Exact;
     if (arg is Basic && parameter.IsInstanceOfType(((Basic)arg).Inner()))
         return MatchResult.BasicConversion;
     if (arg == null && !parameter.IsValueType)
         return MatchResult.Exact;
     if (arg is Proc && parameter.IsSubclassOf(typeof(System.Delegate)))
         return MatchResult.ProcConversion;
     if (arg is Array && (parameter.IsSubclassOf(typeof(System.Array))))
         return MatchResult.ArrayConversion;
     if (parameter.IsValueType) {
         if (parameter == typeof(System.Int64)) {
             return MatchResult.Int64Conversion;
         }
         if (parameter == typeof(System.UInt64)) {
             return MatchResult.UInt64Conversion;
         }
     }
     return MatchResult.NoMatch;
 }
Example #18
0
        private RubyMethod FindCLRMethod(string methodId, System.Type clrtype)
        {
            BindingFlags flags = BindingFlags.Instance | BindingFlags.Public;
            if (this._type == Type.IClass)
            {
                // static methods
                if (methodId == "new")
                {
                    if (clrtype.IsSubclassOf(typeof(System.Delegate)))
                    {
                        return new RubyMethod(new DelegateConstructor(clrtype), 0, Access.Public, this);
                    }
                    else
                    {
                        ConstructorInfo[] ci = clrtype.GetConstructors();

                        if (ci == null || ci.Length == 0)
                            return null;

                        MethodBase[] mi = new MethodBase[ci.Length];
                        System.Array.Copy(ci, mi, ci.Length);
                        return new RubyMethod(new MultiMethod(mi), -1, Access.Public, this);
                    }
                }
                else if (methodId == "allocator")
                {
                    return new RubyMethod(Methods.rb_class_allocate_instance.singleton, 0, Access.Private, this);
                }
                else if (methodId == "[]")
                {
                    // instantiate a generic type
                    // ruby: type = ns::List[System::Int32]
                    if (clrtype.IsGenericType)
                    {
                        // clrtype is Type`n+Inner but we are looking for Type`n+Inner`n
                        // we need to strip generic arguments from the name, but supply
                        // them to the GenericTypeGetter
                        return new RubyMethod(
                            new GenericTypeGetter(
                                clrtype.Assembly,
                                clrtype.GetGenericTypeDefinition().FullName,
                                clrtype.GetGenericArguments()),
                            -1, Access.Public, this);
                    }
                    else
                    {
                        return new RubyMethod(
                            new GenericTypeGetter(clrtype.Assembly, clrtype.FullName, null),
                            -1, Access.Public, this);
                    }
                }

                flags = BindingFlags.Static | BindingFlags.Public;
            }

            bool is_setter = false;
            // methods ending with "=" are expected to be either
            // field or property setters
            if (methodId.EndsWith("="))
            {
                is_setter = true;
                methodId = methodId.Substring(0, methodId.Length - 1);
            }

            // default member access, an Indexer in C#
            if (methodId == "[]")
            {
                object[] attributes = clrtype.GetCustomAttributes(
                    typeof(System.Reflection.DefaultMemberAttribute), true);

                if (attributes.Length > 0)
                {
                    methodId = ((DefaultMemberAttribute)attributes[0]).MemberName;
                }
            }

            MemberInfo[] members = clrtype.GetMember(methodId, flags);

            if (members.Length == 0)
            {
                // we didn't find a member with the exact name
                // but we still need to check for nested types with
                // additional type parameters
                string genericNestedId = methodId + "`";
                foreach (System.Type nested in clrtype.GetNestedTypes(flags))
                {
                    if (nested.Name.StartsWith(genericNestedId))
                    {
                        return new RubyMethod(
                            new ValueMethod(
                                new GenericContainer(
                                    clrtype.Assembly, clrtype.Name + "+" + methodId,
                                    clrtype.GetGenericArguments())),
                            0, Access.Public, this);
                    }
                }

                return null;
            }

            if (members[0] is MethodBase)
            {
                if (is_setter)
                    return null;

                MethodBase[] methods = new MethodBase[members.Length];
                System.Array.Copy(members, methods, members.Length);
                return new RubyMethod(new MultiMethod(methods), -1, Access.Public, this);
            }

            if (members[0] is PropertyInfo)
            {
                // not all the property overloads may have the getter/setter
                // we're looking for, so we maintain a count and resize
                // the methods array later if necessary
                int count = 0;
                MethodBase[] methods = new MethodBase[members.Length];
                
                foreach (PropertyInfo pi in members)
                {
                    MethodInfo method = is_setter ? pi.GetSetMethod() : pi.GetGetMethod();
                    if (method != null)
                        methods[count++] = method;
                }
                
                if (count == 0)
                    return null;

                if (count < members.Length)
                    System.Array.Resize(ref methods, count);

                return new RubyMethod(new MultiMethod(methods), -1, Access.Public, this);
            }

            FieldInfo field = members[0] as FieldInfo;
            if (field != null)
            {
                if (is_setter)
                    return new RubyMethod(new FieldSetter(field), 1, Access.Public, this);
                else
                    return new RubyMethod(new FieldGetter(field), 0, Access.Public, this);
            }

            //EventInfo eventinfo = members[0] as EventInfo;
            //if (eventinfo != null)
            //{
            //    return ...;
            //}

            // nested types
            System.Type type = members[0] as System.Type;
            if (type != null)
            {
                // see section 10.7.1 of ECMA
                if (type.IsGenericTypeDefinition)
                    type = type.MakeGenericType(clrtype.GetGenericArguments());

                return new RubyMethod(
                    new NestedTypeGetter(Load(type, null, false)),
                    0, Access.Public, this);
            }

            return null;
        }
Example #19
0
        /// <summary>
        /// Adds a state to the supplied game object.
        /// Automatically handles undo. 
        /// <param name="gameObject">The game object to add a new state.</param>
        /// <param name="type">The new state type.</param>
        /// <returns>The new created state.<returns>
        /// </summary> 
        public static InternalStateBehaviour AddState (GameObject gameObject, System.Type type) {
            // Validate parameters
            if (gameObject != null && type.IsSubclassOf(typeof(InternalStateBehaviour))) {
                 // Register Undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterSceneUndo("Add Component");
                // Create a new parent
                var newState = gameObject.AddComponent(type) as InternalStateBehaviour;
                #else
                // Create a new parent
                var newState = gameObject.AddComponent(type) as InternalStateBehaviour;
                if (newState != null)
                    Undo.RegisterCreatedObjectUndo(newState, "Add Component");
                #endif

                // Set game object dirty flag
                EditorUtility.SetDirty(gameObject);

                return newState;
            }
            return null;
        }
        public string GetIcon(System.Type type)
        {
            ModifierEnum mod;

            if (type.IsNestedPrivate)
                mod = ModifierEnum.Private;
            else if (type.IsNotPublic || type.IsNestedAssembly)
                mod = ModifierEnum.Internal;
            else if (type.IsNestedFamily)
                mod = ModifierEnum.Protected;
            else
                mod = ModifierEnum.Public;

            if (type.IsValueType)
                return GetWithModifiers (mod, Stock.Struct, Stock.ProtectedStruct, Stock.InternalStruct, Stock.PrivateStruct);

            if (type.IsEnum)
                return GetWithModifiers (mod, Stock.Enum, Stock.ProtectedEnum, Stock.InternalEnum, Stock.PrivateEnum);

            if (type.IsInterface)
                return GetWithModifiers (mod, Stock.Interface, Stock.ProtectedInterface, Stock.InternalInterface, Stock.PrivateInterface);

            if (type.IsSubclassOf (typeof (System.Delegate)))
                return GetWithModifiers (mod, Stock.Delegate, Stock.ProtectedDelegate, Stock.InternalDelegate, Stock.PrivateDelegate);

            return GetWithModifiers (mod, Stock.Class, Stock.ProtectedClass, Stock.InternalClass, Stock.PrivateClass);
        }
 public object deserialize(System.Type lPropertyType, object lTableValue)
 {
     object lValue = null;
     if (
                lPropertyType.IsSubclassOf(typeof(System.Array))
                && lTableValue is ArrayList)
     {
         var lTableArrayList = (ArrayList)lTableValue;
         var lElementType = lPropertyType.GetElementType();
         lValue = System.Array.CreateInstance(lElementType, lTableArrayList.Count);
         var lArray = (System.Array)lValue;
         int i = 0;
         foreach (var lTableValueElement in lTableArrayList)
         {
             var lElement = System.Activator.CreateInstance(lElementType);
             _serializeObject.serializeFromTable(lElement, (Hashtable)lTableValueElement);
             lArray.SetValue(lElement, i);
             ++i;
         }
     }
     else if (lTableValue.GetType() == typeof(Hashtable))
     {
         lValue = System.Activator.CreateInstance(lPropertyType);
         _serializeObject.serializeFromTable(lValue, (Hashtable)lTableValue);
     }
     return lValue;
 }
Example #22
0
File: Bin.cs Project: jwzl/ossbuild
public Gst.Element GetByInterface (System.Type type) {
  if (!type.IsSubclassOf (typeof (Gst.GLib.GInterfaceAdapter)))
    return null;

  Gst.GLib.GType t = (Gst.GLib.GType) type;

  return GetByInterface (t);
}
	/// <summary>
	/// determines if type 'potentialDescendant' is derived from or
	/// equal to 'potentialBase'
	/// </summary>
	public static bool IsSameOrSubclass(System.Type potentialBase, System.Type potentialDescendant)
	{
		return potentialDescendant.IsSubclassOf(potentialBase)
			   || potentialDescendant == potentialBase;
	}
Example #24
0
File: Bin.cs Project: jwzl/ossbuild
public IEnumerable GetAllByInterface (System.Type type) {
  if (!type.IsSubclassOf (typeof (Gst.GLib.GInterfaceAdapter)))
    return null;

  Gst.GLib.GType t = (Gst.GLib.GType) type;

  return GetAllByInterface (t);
}
Example #25
0
		public static Array ListToArray (ListBase list, System.Type type)
		{
			Array result = Array.CreateInstance (type, list.Count);
			if (list.Count > 0)
				list.CopyTo (result, 0);

			if (type.IsSubclassOf (typeof (Gst.GLib.Opaque)))
				list.elements_owned = false;

			return result;
		}
 /// <summary> 
 /// Returns the script for the supplied node type.
 /// <param name= "type">The type of the node to search for the script.</param>
 /// <returns>A MonoScript of the supplied node type.</returns>
 /// </summary>
 public static MonoScript GetNodeScript (System.Type type) {
     if (type != null && type.IsSubclassOf(typeof(ActionNode))) {
         foreach (MonoScript script in BehaviourTreeUtility.GetNodeScripts()) {
             if (script.GetClass() == type)
                 return script;
         }
     }
     return null;
 }
	public static int GetIcon(System.Type type)
	{
		int BASE = ClassIndex;
		
		if (type.IsValueType) {
			BASE = StructIndex;
		}
		if (type.IsEnum) {
			BASE = EnumIndex;
		}
		if (type.IsInterface) {
			BASE = InterfaceIndex;
		}
		if (type.IsSubclassOf(typeof(System.Delegate))) {
			BASE = DelegateIndex;
		}
		
		if (type.IsNestedPrivate) {
			return BASE + 3;
		}
		
		if (type.IsNotPublic || type.IsNestedAssembly) {
			return BASE + 1;
		}
		
		if (type.IsNestedFamily) {
			return BASE + 2;
		}
		return BASE;
	}
Example #28
0
        public Array ToArray(System.Type type)
        {
            Array result = Array.CreateInstance (type, Count);
            if (Count > 0)
                CopyTo (result, 0);

            if (type.IsSubclassOf (typeof (GObject.Opaque)))
                elements_owned = false;

            return result;
        }
Example #29
0
 private void AddAccountReportType(string name, System.Type formClass)
 {
     bool flag = User.IsMemberOf(RightsEnum.АРМБухгалтерЛССправкиПросмотрВсехДоступныхСправок);
     bool flag2 = User.IsMemberOf(RightsEnum.АРМБухгалтерЛССправкиПросмотрДоступныхПоставщикамУслуг);
     if (flag || flag2)
     {
         AccountReportType byName = AccountReportType.GetByName(name);
         if (((byName != AccountReportType.Null) && ((flag && byName.IsEnabled) || ((flag2 && byName.IsEnabledProvider) && byName.IsEnabled))) && formClass.IsSubclassOf(typeof(AccountReportForm)))
         {
             this.m_AccountReportTypeClasses.Add(byName, formClass);
         }
     }
 }
 private static bool IsTypeCompatible(System.Type type)
 {
     return ((type != null) && (type.IsSubclassOf(typeof(MonoBehaviour)) || type.IsSubclassOf(typeof(ScriptableObject))));
 }