コード例 #1
0
        void ProcessWaitingScripts(bool initialLoad)
        {
            bool hasDefaultGameRules = false;

            foreach (var pluginPair in PluginTypes)
            {
                ICryMonoPlugin plugin = pluginPair.Key;

                foreach (Type type in pluginPair.Value)
                {
                    var script = FindScript(ScriptType.Any, x => x.Type == type);
                    if (script == null)
                    {
                        if (!CryScript.TryCreate(type, out script))
                        {
                            continue;
                        }
                    }

                    script.RegistrationParams = plugin.GetRegistrationParams(script.ScriptType, type);

                    if (!script.Registered)
                    {
                        if (script == null || script.RegistrationParams == null)
                        {
                            continue;
                        }

                        // Contain types that can only be registered at startup here.
                        if (initialLoad)
                        {
                            if (script.RegistrationParams is ActorRegistrationParams)
                            {
                                var registrationParams = (ActorRegistrationParams)script.RegistrationParams;

                                NativeActorMethods.RegisterActorClass(script.ScriptName, script.Type.Implements(typeof(NativeActor)), registrationParams.isAI);
                            }
                            else if (script.RegistrationParams is EntityRegistrationParams)
                            {
                                var registrationParams = (EntityRegistrationParams)script.RegistrationParams;

                                if (registrationParams.name == null)
                                {
                                    registrationParams.name = script.ScriptName;
                                }
                                if (registrationParams.category == null)
                                {
                                    registrationParams.category = "Default";
                                }

                                NativeEntityMethods.RegisterEntityClass(registrationParams);

                                script.RegistrationParams = registrationParams;
                            }
                        }

                        if (script.RegistrationParams is GameRulesRegistrationParams)
                        {
                            var registrationParams = (GameRulesRegistrationParams)script.RegistrationParams;

                            if (registrationParams.name == null)
                            {
                                registrationParams.name = script.ScriptName;
                            }

                            NativeGameRulesMethods.RegisterGameMode(registrationParams.name);

                            if (registrationParams.defaultGamemode || !hasDefaultGameRules)
                            {
                                NativeGameRulesMethods.SetDefaultGameMode(registrationParams.name);

                                hasDefaultGameRules = true;
                            }

                            script.RegistrationParams = registrationParams;
                        }
                        else if (script.RegistrationParams is FlowNodeRegistrationParams)
                        {
                            var registrationParams = (FlowNodeRegistrationParams)script.RegistrationParams;

                            if (registrationParams.name == null)
                            {
                                registrationParams.name = script.ScriptName;
                            }
                            if (registrationParams.category == null)
                            {
                                registrationParams.category = script.Type.Namespace;
                            }
                            if (registrationParams.filter == 0)
                            {
                                registrationParams.filter = FlowNodeFilter.Approved;
                            }

                            script.RegistrationParams = registrationParams;

                            script.ScriptName = registrationParams.category + ":" + registrationParams.name;
                        }
                        else if (script.RegistrationParams is EntityFlowNodeRegistrationParams)
                        {
                            var registrationParams = (EntityFlowNodeRegistrationParams)script.RegistrationParams;

                            script.ScriptName = "entity" + ":" + registrationParams.entityName;
                        }

                        script.Registered = true;
                        Scripts.Add(script);
                    }
                }
            }
        }
コード例 #2
0
ファイル: ScriptManager.cs プロジェクト: BenChung/CryMono
        void LoadPlugins(bool initialLoad)
        {
            var pluginsDirectory = PathUtils.PluginsFolder;

            if (!Directory.Exists(pluginsDirectory))
            {
                return;
            }

            bool hasDefaultGameRules = false;

            foreach (var directory in Directory.GetDirectories(pluginsDirectory))
            {
                var compilerDll = Path.Combine(directory, "Compiler.dll");
                if (File.Exists(compilerDll))
                {
                    var assembly = LoadAssembly(compilerDll);

                    var compilerType = assembly.GetTypes().First(x => x.Implements <ScriptCompiler>());
                    Debug.LogAlways("        Initializing {0}...", compilerType.Name);

                    var compiler = Activator.CreateInstance(compilerType) as ScriptCompiler;

                    var assemblyPaths = Directory.GetFiles(directory, "*.dll", SearchOption.AllDirectories);
                    var assemblies    = new List <Assembly>();

                    foreach (var assemblyPath in assemblyPaths)
                    {
                        if (assemblyPath != compilerDll)
                        {
                            assemblies.Add(LoadAssembly(assemblyPath));
                        }
                    }

                    var scripts = compiler.Process(assemblies);

                    foreach (var unprocessedScript in scripts)
                    {
                        var script = unprocessedScript;

                        if (initialLoad)
                        {
                            if (script.RegistrationParams == null)
                            {
                                continue;
                            }
                            else if (script.RegistrationParams is ActorRegistrationParams)
                            {
                                var registrationParams = (ActorRegistrationParams)script.RegistrationParams;

                                NativeActorMethods.RegisterActorClass(script.ScriptName, script.Type.Implements(typeof(NativeActor)));
                            }
                            else if (script.RegistrationParams is EntityRegistrationParams)
                            {
                                var registrationParams = (EntityRegistrationParams)script.RegistrationParams;

                                if (registrationParams.name == null)
                                {
                                    registrationParams.name = script.ScriptName;
                                }
                                if (registrationParams.category == null)
                                {
                                    registrationParams.category = "Default";
                                }

                                NativeEntityMethods.RegisterEntityClass(registrationParams);

                                script.RegistrationParams = registrationParams;
                            }
                            else if (script.RegistrationParams is GameRulesRegistrationParams)
                            {
                                var registrationParams = (GameRulesRegistrationParams)script.RegistrationParams;

                                if (registrationParams.name == null)
                                {
                                    registrationParams.name = script.ScriptName;
                                }

                                NativeGameRulesMethods.RegisterGameMode(registrationParams.name);

                                if (registrationParams.defaultGamemode || !hasDefaultGameRules)
                                {
                                    NativeGameRulesMethods.SetDefaultGameMode(registrationParams.name);

                                    hasDefaultGameRules = true;
                                }

                                script.RegistrationParams = registrationParams;
                            }
                            else if (script.RegistrationParams is FlowNodeRegistrationParams)
                            {
                                var registrationParams = (FlowNodeRegistrationParams)script.RegistrationParams;

                                if (registrationParams.name == null)
                                {
                                    registrationParams.name = script.ScriptName;
                                }
                                if (registrationParams.category == null)
                                {
                                    registrationParams.category = script.Type.Namespace;
                                }
                                if (registrationParams.filter == 0)
                                {
                                    registrationParams.filter = FlowNodeFilter.Approved;
                                }

                                script.RegistrationParams = registrationParams;

                                script.ScriptName = registrationParams.category + ":" + registrationParams.name;
                            }
                            else if (script.RegistrationParams is EntityFlowNodeRegistrationParams)
                            {
                                var registrationParams = (EntityFlowNodeRegistrationParams)script.RegistrationParams;

                                script.ScriptName = "entity" + ":" + registrationParams.entityName;
                            }
                        }

                        Scripts.Add(script);
                    }
                }
            }
        }