コード例 #1
0
ファイル: Game.cs プロジェクト: xmshaka/slash-framework
        /// <summary>
        ///   Initialization of the game. Can be used for game-specific initialization steps.
        /// </summary>
        private void InitGame()
        {
            if (this.AddSystemsViaReflection)
            {
#if !WINDOWS_STORE && !WINDOWS_PHONE
                // Make sure all referenced assemblies are loaded.
                AssemblyUtils.CheckReferencedAssembliesAreLoaded();
#endif

                // Add game systems using reflection.
                var systemTypes = ReflectionUtils.FindTypesWithBase <ISystem>();

                // Check if enabled and order by index.
                var gameSystemTypes = from systemType in systemTypes
                                      let systemTypeAttribute = systemType.GetAttribute <GameSystemAttribute>()
                                                                where systemTypeAttribute != null && systemTypeAttribute.Enabled
                                                                orderby systemTypeAttribute.Order
                                                                select systemType;

                // Attach systems.
                foreach (var gameSystemType in gameSystemTypes)
                {
                    var system = (ISystem)Activator.CreateInstance(gameSystemType);
                    this.AddSystem(system);
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///   Finds all types accessible to the user in the inspector via reflection.
        /// </summary>
        /// <param name="baseType">Base type of types to search for. Null if all inspector types should be found.</param>
        /// <returns>Inspector type table containing all available inspector types.</returns>
        public static InspectorTypeTable FindInspectorTypes(Type baseType)
        {
            InspectorTypeTable inspectorTypeTable = new InspectorTypeTable();

#if !WINDOWS_STORE && !WINDOWS_PHONE
            // Make sure all referenced assemblies are loaded.
            AssemblyUtils.CheckReferencedAssembliesAreLoaded();
#endif

            foreach (var assembly in AssemblyUtils.GetLoadedAssemblies())
            {
                try
                {
                    var inspectorTypes =
                        assembly.GetTypes()
                        .Where(
                            type =>
                            baseType == null ||
                            baseType.IsAssignableFrom(type) &&
                            type.IsAttributeDefined <InspectorTypeAttribute>());

                    foreach (var inspectorType in inspectorTypes)
                    {
                        InspectorType inspectorTypeData = InspectorType.GetInspectorType(inspectorType);

                        inspectorTypeTable.inspectorTypes.Add(inspectorType, inspectorTypeData);
                    }
                }
                catch (ReflectionTypeLoadException)
                {
                    // Some assemblies can't be reflected, like UnityEditor.
                }
            }

            return(inspectorTypeTable);
        }